OpenAPITools / OpenAPITools/openapi-generator
[BUG] Description
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example) No
Description
I have an openapi schema that is autogenerated by @nestjs/swagger library. Unfortunately, and due to strange workplace conditions, I have to generate a C# client. The problem I am running into is every model, regardless of what the annotations specify, will insert non-null validation onto string fields. This happens regardless of:
- Whether I mark the api property
nullableor not. - Whether I mark the api property
requiredor not. - Whether I specify the runtime argument
--additional-properties=validatable=falseor not - Whether I specify the runtime argument
--additional-properties=nullableReferenceTypes=trueor not
openapi-generator version
6.6.0
OpenAPI declaration file content or url
{
"openapi": "3.0.0",
"components": { "schemas": {
"CreateFieldDto": {
"type": "object",
"properties": {
"key": { "type": "string" },
"value": { "type": "string", "nullable": true }
},
"required": [ "key", "value" ]
} } }
// ...
}
Generation Details
/// Generated file: ./src/Org.OpenAPITools/Model/CreateFieldDto.cs
// ...
public CreateFieldDto(string key = default(string), string value = default(string))
{
// to ensure "key" is required (not null)
if (key == null)
{
throw new ArgumentNullException("key is a required property for CreateFieldDto and cannot be null");
}
this.Key = key;
// to ensure "value" is required (not null)
if (value == null)
{
throw new ArgumentNullException("value is a required property for CreateFieldDto and cannot be null");
}
this.Value = value;
}
// ...
Steps to reproduce
openapi-generator generate \
-i <wherever you bake the file with the model>
-o <wherever you want> \
-g csharp-netcore \
--artifact-version 1.0.0 \
--additional-properties=validatable=false,nullableReferenceTypes=true
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided OpenAPI schema and the openapi-generator generate command using the csharp-netcore generator, then inspect the generated ./src/Org.OpenAPITools/Model/CreateFieldDto.cs. Reproduce the constructor output with version 6.6.0 and the listed additional properties. Done means the generated validation distinguishes the shown required and nullable string properties as described by the schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100