2

Using njsonschema, I want to generate a schema that will ensure that all values written to a dictionary will be validated against a regex pattern.

Consider the following class:

class File
{
    [RegularExpression("^\\d+\\.\\d+\\.\\d+\\.\\d+$")]
    public Dictionary<string, string> Versions { get; set; }
}

The schema part that I wish that njsonschema would generate is:

"Versions": {
    "type": "object",
    "additionalProperties": {
        "type": "string",
        "pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$"
    }
}

Instaed, njsonschema generates something like this:

"Versions": {
  "type": "object",
  "pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$",
  "additionalProperties": {
    "type": "string"
  }
}

Is there any way to acheive this?

Thanks in advance!

Eitan H.S.
  • 430
  • 3
  • 15

1 Answers1

0

This problem has been fixed in this commit:

https://github.com/RSuter/NJsonSchema/commit/fa1b36b68bb5ad7ec005b2a77002a5668d1aa2b4

A version of NJsonSchema (v9.4.4+) with this fix has been released...

Rico Suter
  • 11,548
  • 6
  • 67
  • 93