swagger-api / swagger-api/swagger-codegen
[C#] Generated ValidationResult message for max lenght is wrong
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I have successfully generated an API client using the generator, for C#. However the generated error messages are wrong with their length message. It says "...length must be less than 1.", but should read "...length must be equal or less than 1", because 1 is the max lenght.
The resultant code is:
8<------------------------------------------------------------------------------
// MutationTypeCd (string) maxLength
if (this.MutationTypeCd != null && this.MutationTypeCd.Length > 1)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for MutationTypeCd, length must be less than 1.", new[] { "MutationTypeCd" });
}
8<------------------------------------------------------------------------------
in method "IValidatableObject.Validate"
in class "xyz.BurWebAnnouncementDto"
in file xyz\model\xyzdto.cs
Swagger-codegen version
2.3.1, as stated on https://generator.swagger.io/# today.
Swagger declaration file content or url
This is the relevant part of the property in question in the API spec:
"MutationTypeCd": {
"maxLength": 1,
"type": "string"
},
Command line used for generation
I used the online generator, with no options, and the spec directly included (not via url)
Steps to reproduce
- Use a spec with a string property of maxLenght 1 (or any other specific lenght)
- Generate the client for C#, then look into the according Dto.cs
- The validation messages are wrong for max lenght.
Related issues/PRs
Probably related: https://github.com/swagger-api/swagger-codegen/issues/6582
Suggest a fix/enhancement
Replace the error message
"Invalid value for XYZ, length must be less than X." with "Invalid value for MutationTypeCd, length must must be equal or less than X."
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
Search the C# generator templates for the reported validation message and reproduce the case with a string property whose maxLength is 1. Done means the generated C# validation message describes the inclusive maximum correctly, while the length check remains consistent with the specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100