RicoSuter/NJsonSchema

Propagate item-level validation on string arrays from JSON schema to C# object model

Open

#1.292 geöffnet am 8. Dez. 2020

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (550 Forks)github user discovery
help wantedproject: NJsonSchema.CodeGeneration.CSharptype: enhancement

Repository-Metriken

Stars
 (1.578 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

I have a string array field which validates not only the length of the array, but the length of the strings in the array as well:

"Tags": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 3
      }
    },

However, when converted to a C# OM, the per-item validation gets lost:

[Newtonsoft.Json.JsonProperty("Tags", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[System.ComponentModel.DataAnnotations.MinLength(1)]
[System.ComponentModel.DataAnnotations.MaxLength(16)]
public System.Collections.Generic.ICollection<string> Tags { get; set; }

I don't have a bright idea on how this validation criteria could live in the .NET world, it's possible that there's no way to currently phrase that using the DataAnnotations, but I'm hoping to be surprised!

Contributor Guide