Reputation: 45
How can I set Multiple type in a JsonSchema. The description field in the below example I want it to be JsonSchemaType.String or JsonSchemaType.null.
{PropertyNames.Id, new JsonSchema { Type = JsonSchemaType.Integer, Required = true }},
{PropertyNames.Description, new JsonSchema { Type = JsonSchemaType.String, Required = true }}
Also, I have an array which consists of Integers and float.
result[PropertyNames.Metrics] = new JsonSchema { Type = JsonSchemaType.Array, Required = true, Items = new List<JsonSchema> { new JsonSchema() { Type = JsonSchemaType.Integer } } };
The validation fails as it expects integer but receives float. Can I do something like Type = JsonSchemaType.Integer "or" JsonSchemaType.Float
Upvotes: 1
Views: 1279
Reputation: 45
It can be done using a simple |
operator
result[PropertyNames.Metrics] = new JsonSchema
{
Type = JsonSchemaType.Array,
Required = true,
Items = new List<JsonSchema>
{
new JsonSchema()
{
Type = JsonSchemaType.Integer | JsonSchemaType.Null
}
}
};
Upvotes: 2