OpenAPITools / OpenAPITools/openapi-generator
[BUG] EmitDefaultValue=false for int
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I'm using C# microservices and use OpenAPI to generate the Nugets. My DTO has some properties that are int with a range and a default:
[Range(-1, int.MaxValue)]
[DefaultValue(-1)]
public int SomeNumber { get; set; } = -1;
And these are my related packages:
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.1.4" />
For some unknown reason, this property is created in the generated Nuget with EmitDefaultValue=false, making it impossible to give this property a value of 0. I tried manually adding EmitDefaultValue to true, and updating the package versions to 6.5.0 (latest).
I saw several related bugs and PR to this repository that were resolved, but found no explanation on how to solve it:
3274
10772
9071
4346
Please let me know what fixes were done for these other issues and what changes I need to make.
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 by comparing the generated C# NuGet DTO property with the provided DefaultValue and Range annotations, then read the related issues 3274, 10772, 9071, and 4346. Confirm which generator options or template behavior produces EmitDefaultValue=false and document a reproducible fix or the required configuration change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100