1

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

4

1 回答 1

2

可以使用简单的|运算符来完成

result[PropertyNames.Metrics] = new JsonSchema 
{ 
    Type = JsonSchemaType.Array, 
    Required = true, 
    Items = new List<JsonSchema> 
    { 
        new JsonSchema() 
        { 
            Type = JsonSchemaType.Integer | JsonSchemaType.Null
        } 
    }
};
于 2014-08-07T20:04:19.530 回答