Skip to content

[BUG][C#] Model properties are generated as non-nullable after 4.1.0 release #3725

@douggish

Description

@douggish

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

In version 4.0.3, when using an OpenAPI 2.0 input, model properties were generated as nullable. For example, see that the date-time property in the FormatTest class was generated as a DateTime? type in 4.0.3:
https://github.com/OpenAPITools/openapi-generator/blob/v4.0.3/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/FormatTest.cs#L172

But in 4.1.0, the same property is generated as a non-nullable DateTime type:
https://github.com/OpenAPITools/openapi-generator/blob/v4.1.0/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/FormatTest.cs#L172

This is a problem because if a service returns null for these properties in a response, the JSON deserialization fails.

Is there a way to generate nullable properties using an OpenAPI 2.0 input?

openapi-generator version

4.1.0

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/v4.1.0/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml#L1301

Command line used for generation

See https://github.com/OpenAPITools/openapi-generator/blob/v4.1.0/bin/csharp-petstore-netcore-project.sh#L30

Steps to reproduce

Look at the generated samples in Github for version 4.0.3 and 4.1.0 and compare the types of the properties in the generated models.

Related issues/PRs

I believe this may have been introduced by these pull requests:
#3530
#3537

Suggest a fix

I think the changes made in the above pull requests should only affect OpenAPI 3.0 generation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions