You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public Example(string requiredNullable = default(string), string requiredNotNullable = default(string))
{
// to ensure "requiredNullable" is required (not null)
if (requiredNullable == null)
{
throw new ArgumentNullException("requiredNullable is a required property for Example and cannot be null");
}
this.RequiredNullable = requiredNullable;
// to ensure "requiredNotNullable" is required (not null)
if (requiredNotNullable == null)
{
throw new ArgumentNullException("requiredNotNullable is a required property for Example and cannot be null");
}
this.RequiredNotNullable = requiredNotNullable;
}
This block (from above) will demand it to be not nullable:
if (requiredNullable == null)
{
throw new ArgumentNullException("requiredNullable is a required property for Example and cannot be null");
}
Steps to reproduce
This is the command used to generate the Example.cs class:
CampionFabio
changed the title
[BUG] [csharp] C# Models from schema with a property attribute "nullable": true generate properties not nulable
[BUG] [CSHARP] Models from schema with a property attribute "nullable": true are generating properties not nullable
Apr 15, 2025
Thank you Alec,
I really appreciate your team taking this on.
We had a few major upgrades in our app along the last months and they caused this to start happening (because one of the changes was to no longer monkey-patch the generated code)
This generator tool is great and saves us a fair bit of maintenance effort.
Bug Report Checklist
Description
When properties are configured to be both required and nullable, the generated C# model does not allow a null value for that property.
openapi-generator version
Used
"@openapitools/openapi-generator-cli": "^2.18.4"
with
OpenAPI declaration file content or url
Generation Details
The problem is that the property "requiredNullable" does not allow the null value, even though it is configured in the json as:
Constructor generated:
This block (from above) will demand it to be not nullable:
Steps to reproduce
This is the command used to generate the Example.cs class:
Related issues/PRs
No
Suggest a fix
if the property is flagged with
"nullable": true
in the ref json , the generated C# model should not enforce the parameter to not be nullable.The text was updated successfully, but these errors were encountered: