OpenAPITools / OpenAPITools/openapi-generator
[BUG][CSharp] Bug generating code with Enum having maxLength property
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hi
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
We have an open api spec version 2.0 and we are trying to generate code in csharp .
We have an issue in generated SDKif the property whose type is string is an enum and has maxLength specified . Please refer line 121 in attached contract .
petstore.txt
Below is the code in csharp and the one in bold throws error.
// Status (string) maxLength
if(this.Status != null && this.Status.Length > 20)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Status , length must be less than 20.", new [] { "Status " });
}
openapi-generator version
3.3.4
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix
csharp code should be like The code should be like this.Status.ToString().Length.
In the snapshot below we can make 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 attached petstore.txt OpenAPI 2.0 specification and reproduce generation for C#. Inspect the generated validation for the enum string property with maxLength 20, then verify the output compiles and handles the length check without treating the enum as a direct string.
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
- Mostly clear
- Newbie friendliness
- 42/100