RicoSuter / NJsonSchema

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

JsonSchemaExtensionDataAttr will not work on validate even if the key is standard JSON schema property #1275

Open jarvan-jiang opened 3 years ago

jarvan-jiang commented 3 years ago
[JsonSchemaExtensionData("minimum", 0)]
[JsonSchemaExtensionData("exclusiveMinimum", true)]
public decimal? Hours { get; set; }

Add attributes like this, then use FromType will get a perfect JSON schema: "Hours": { "type": "number", "format": "decimal", "minimum": 0, "exclusiveMinimum": true } But when calling jsonSchema.Validate(data), there will be no error for invalid value for this field. Seems there isn't a step to check if JsonSchemaExtensionDataAttribute can be applied to real schema? Is that by design?

RicoSuter commented 3 years ago

Validate runs on the schema not on the attributes. So probably the validator does not validate this yet. Can you create a PR with a test and fix?