RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.61k stars 1.22k forks source link

nswag not handling the maxLength and pattern properties in the OpenAPI specification for array items #4879

Open Dharam625 opened 2 months ago

Dharam625 commented 2 months ago

I have the following open api specification written in yaml:

type: object
additionalProperties: false
properties:
  oddNumbers:
    type: array
    items:
      type: string
      pattern: '^[0-9]+$'
      maxLength: 19
    example: ["1", "3", "5", "7", "9"]

Here is the generated c# code using NWag:


    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public partial class OddNumbers
    {
        [System.Text.Json.Serialization.JsonPropertyName("oddNumbers")]
        public System.Collections.Generic.List<string> OddNumbers1 { get; set; }
    }

As you can see, pattern and maxLength applied at each array item in open api specification is not carried through in generated code.

is this feature not supported currently in Nswag or there is some configuration setting i am missing ?

Any help is much appreciated :)