Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
palenshus opened this issue Dec 8, 2020 · 2 comments

Comments

@palenshus
Copy link

palenshus commented Dec 8, 2020

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!

@RicoSuter
Copy link
Owner

RicoSuter commented Feb 26, 2021

but I'm hoping to be surprised!

:-) I dont have the answer, sorry.

We'd need to investigate...

@esskar
Copy link

esskar commented Feb 18, 2022

Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants