Reputation: 91
I have the following json schema definition in my .raml file
- request: |
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"required": true,
"properties": {
"personProperty": {
"type": "array",
"items": {
"$ref": "property"
}
}
}
}
- property: |
{ "$schema": "http://json-schema.org/draft-03/schema",
"type": "object",
"description": "A single person property",
"properties": {
"fieldId": { "type": "integer", "required": true},
"systemId": { "type": "integer", "required": false},
"value": { "type": "string" , "required": true },
"created": { "type": "string" , "required": false }
}
}
I need mule ESB to reject the input when one of the required fields inside the array is missing.
For example this should be rejected with 400- BAD REQUEST:
{
"personProperty": [
{
"fieldId": "1",
"systemId": 1,
"created": "2015-02-23 21:19:00.907"
}
]
}
If the schema is not inside an array, the validation works properly. But when inside the array, it is not validating any single item having the required attribute.
Do I need a special configuration?
Thanks.
Upvotes: 1
Views: 1707
Reputation: 33413
You have not answered my question so I can only assume that you had wrongly included the inner object definition. Seeing your own answer and the reference to struggling, I'd like to propose an answer too.
Here is a standalone and reference free representation of your schema:
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"properties": {
"personProperty": {
"type": "array",
"items": {
"type": "object",
"properties": {
"fieldId": {
"type": "integer",
"required": true
},
"systemId": {
"type": "integer",
"required": false
},
"value": {
"type": "string",
"required": true
},
"created": {
"type": "string",
"required": false
}
}
}
}
}
}
Upvotes: 0
Reputation: 91
after struggling for a while I was able to make it work using this:
- request: |
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"definitions": {
"person-property": {
"type": "object",
"properties": {
"fieldId": {
"type": "integer",
"required": true
},
"systemId": {
"type": "integer",
"required": false
},
"value": {
"type": "string",
"required": true
},
"created": {
"type": "string",
"required": false
}
}
}
},
"properties": {
"personProperty": {
"type": "array",
"items": {
"$ref": "#/definitions/person-property"
}
}
}
}
I used an inner definition and then called it using "$ref": "#/definitions/person-property"
Upvotes: 0