So I am using a Json Meta Schema https://json-schema.org/draft/2019-09/meta/core to further validate JSONSchema using https://github.com/java-json-tools/json-schema-validator
I have a requirement where I have to restrict a schema from having nested objects , like the below schema should be invalid
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "test",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"productId": {
"description": "Outer",
"type": "object",
"properties": {
"lineId": {
"description": "Outer",
"type": "object"
}
}
}
}
}
Since productId
is an object and it has another object lineId
, productId
can have only string or number fields but never an object , How to extend the MetaSchema to enforce this. Any help is appreciated
Your question has some version inconsistency, but I'll assume draft-04 since the validator you are using only supports up to draft-04. If you need to do this for other drafts, this procedure will be similar through draft-07. Draft 2019-09 would be more complicated.
type
and any keywords related to objects such as properties
.id
to something unique like https://my-project.com/nested-meta-schema
.{ "$ref": "#" }
) with references to the schema you just made ( { "$ref": "https://my-project.com/nested-meta-schema" }
)id
of the second schema to something unique like https://my-project.com/flat-meta-schema
.$schema
to the id you gave the second meta-schema.Note that not all implementations support custom meta-schemas, so your mileage may vary.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.