Код: Выделить всё
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/create.stockincdecevent.schema.json",
"title": "Create-Stock-Inc-Dec-event",
"description": "Schema for the event to request a stock inc dec operation",
"type": "object",
"properties": {
"userMetaData": {
"type": "object",
"description": "Meta attributes used by the user of the system",
"properties": {
"userId": {
"type": "string",
"description": "The user ID of the connected client"
}
},
"required": [
"userId"
]
},
"data": {
"type": "object",
"description": "The data that has to be processed.",
"properties": {
"itemID": {
"type": "string",
"description": "The item for which the stock has to be deducted."
},
"stockCount": {
"type": "number",
"description": "stock count to deduct."
}
},
"required": [
"itemID",
"stockCount"
]
}
},
"required": [
"userMetaData",
"data"
]
}
Код: Выделить всё
{
"userMetaData": {
"userId": "user-1"
},
"data": {
"itemID": "Item-1",
"stockCount": 1
}
}
Код: Выделить всё
OutputUnit schemaValidateResponse = Validator
.create(schema, new JsonSchemaOptions().setBaseUri("https://example.com").setDraft(Draft.DRAFT202012))
.validate(dataToValidate)
Код: Выделить всё
{
"userMetaData": {
"userId": "user-1"
},
"data": {
"itemID": "Item-1"
}
}
Заранее спасибо.
Подробнее здесь: https://stackoverflow.com/questions/784 ... validation
Мобильная версия