OpenAPITools / OpenAPITools/openapi-generator

[BUG] Nullable Types Changed [C-Sharp]

Open
#13,311 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I'm not sure if this a bug per-se but I've noticed that since v5.4.0 (at least), date types have stopped being rendered as DateTime? (ie, nullable) and are now rendered simply as DateTime.

I can't find a reference to this change - can anyone illuminate me?

This change resulted in several (minor) code breaks for us.

Here a fragment from the OpenAPI definition, which hasn't changed:

"CustomFieldAdd": {
  "description": "While records provide many fields to track information, organizations often require additional details.",
  "required": [
    "category"
  ],
  "type": "object",
  "properties": {
    "category": {
      "description": "The custom field category. Available values are the entries in the <b>Custom Field Categories</b> tablet.",
      "type": "string"
    },
    "comment": {
      "description": "The comment on the custom field.",
      "maxLength": 50,
      "minLength": 0,
      "type": "string"
    },
    "date": {
      "format": "date-time",
      "description": "The date on the custom field. Uses <a href=\"https://tools.ietf.org/html/rfc3339\">ISO-8601 format:</a><i>1969-11-21T10:29:43</i>.",
      "type": "string",
      "x-supports-datetime-offset": false
    },
    "parent_id": {
      "description": "The parent object's immutable system record ID.",
      "type": "string"
    },
    "value": {
      "description": "The value of the custom field.",
      "type": "object"
    }
  },

Here's the c-sharp code (signature only) rendered by v4.0.3 (which we've used until trying to upgrade to a later version):

public CustomFieldAdd(string category = default(string), string comment = default(string), **DateTime?** date = default(DateTime?), string parentId = default(string), Object value = default(Object))

And here's the code rendered by v5.4.0 and later:

public CustomFieldAdd(string category = default(string), string comment = default(string), **DateTime** date = default(DateTime), string parentId = default(string), Object value = default(Object))

(As an aside, default(type) can be shortened to simply default; the type is inferred. Also, date is preferred over DateTime.)

UPDATE

After some more digging, I see that other types are affected as well, such as int and bool. Eg:

v4.0.3:

public ApiList(string id = default(string), string name = default(string), string description = default(string), **int?** recordCount = default(**int?**), DateTime? dateModified = default(DateTime?), string lastModifiedByUserName = default(string), string lastModifiedByUserId = default(string), **bool?** isPublic = default(**bool?**))

v5.4.0:

public ApiList(string id = default(string), string name = default(string), string description = default(string), **int** recordCount = default(**int**), DateTime dateModified = default(DateTime), string lastModifiedByUserName = default(string), string lastModifiedByUserId = default(string), **bool** isPublic = default(**bool**))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing C# output from generator v4.0.3 and v5.4.0 using the OpenAPI fragment in the report, focusing on nullable date, integer, and boolean parameters. Done means identifying the change that removed nullable types and either restoring the prior output or documenting why the generated signatures should differ.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.