swagger-api / swagger-api/swagger-codegen
[C#] Generated code for enums with a StringLength attribute does not compile
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If the swagger.json contains an enum which has minLength and maxLength properties specified then swagger-codegen generates invalid C# - it will not compile because it creates validation rules trying to validate the length of the enum value - and of course an enum value does not have a length.
More details here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1037 as perhaps swashbuckle should not generate the min/max length for this situation, but I think swagger-codegen should ignore min/max length for an enum as it does not really make sense even though it is syntactically valid swagger - and of course more importantly, results in code that does not compile
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 reproducing the issue with a swagger.json enum containing minLength and maxLength, then trace the generated C# validation output. The work is done when the generated C# compiles and no length validation is emitted for enum values; use the linked Swashbuckle discussion for context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100