I'm creating a JSON schema for use in Postman that has a few schema definitions in them. The JSON I validate against the schema needs to match with one of the schema definitions.
SAMPLE SCHEMA
{
"oneOf": [
{
"$ref": "#/definitions/schema1"
},
{
"$ref": "#/definitions/schema2"
},
{
"$ref": "#/definitions/schema3"
}
],
"definitions": {
"schema1": {
"type": "object",
"properties": {
"propertyA": {
"type": "string"
}
},
"required": [
"propertyA"
]
},
"schema2": {
"type": "object",
"properties": {
"propertyB": {
"type": "string"
}
},
"required": [
"propertyB"
]
},
"schema3": {
"type": "object",
"properties": {
"propertyC": {
"type": "string"
}
},
"required": [
"propertyC"
]
}
}
}
SAMPLE JSON DATA
This JSON gets validated against the schema and correctly marked as invalid (because a string is needed):
{
"propertyA": 123
}
THE PROBLEM
This example returns 4 errors according to https://www.jsonschemavalidator.net/:
- Message: JSON is valid against no schemas from 'oneOf'. Schema path: #/oneOf
- Message: Invalid type. Expected String but got Integer. Schema path: #/definitions/schema1/properties/propertyA/type
- Message: Required properties are missing from object: propertyC.
Schema path: #/definitions/schema3/required - Message: Required properties are missing from object: propertyB.
Schema path: #/definitions/schema2/required
I'm only interested in the error message saying that it expected a String. How do I avoid those other error messages while keeping the schema definitions in 1 single file?