RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.38k stars 532 forks source link

minlength is impacted by required attribute in json schema #768

Open kiranpradeep opened 6 years ago

kiranpradeep commented 6 years ago

I used below schema to generate C# code using CSharpGenerator. But there is no validation for the length if the field marked as required. The validation ( [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue, MinimumLength = 1)]) is correctly generated if the field is not marked as required.

{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "files": { "type": "string", "minlength": 1 } }, "required": [ "files" ] }

Is this intentional? I am using version: 9.10.67 on nuget.

RicoSuter commented 6 years ago

This is probably missing at the moment...

hugovlc commented 3 years ago

Any workaround for this?