Я объявил Enum
в схеме JSON
, как показано ниже. Я без проблем сгенерировал артефакты, используя схему.
В настоящее время я работаю над частью проверки с использованием com.github.fge.jsonschema.* api
.
Но во время проверки API не проверяет, когда я отправляю запрос JSON
без элемента sourceType
. Нужна помощь в устранении ошибки проверки.
Примечание: версия схемы - V4
Объявление Enum
Основная схема
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "xxxxxxxxxxxxxxxxxxxxxxx",
"description": "xxxxxxxxxxxxxxxxxxxxx",
"type": "object",
"properties": {
"requestHeader": {
"$ref": "resource:/json/RequestHeader.json#/definitions/requestHeader"
},
"sourceType": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/sourceType"
},
"billingSystem": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/billingSystem"
},
"siteId": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/siteId"
},
"ocnValue": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/ocnValue"
},
"raoValue": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/raoValue"
},
"tn": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/tn"
},
"actionCode": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/actionCode"
},
"serviceClass": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/serviceClass"
},
"bnsCode": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/bnsCode"
},
"privacyIndicator": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/privacyIndicator"
},
"customerName": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/customerName"
},
"workOrderNumber": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/workOrderNumber"
},
"accountNumber": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/accountNumber"
},
"portInFlag": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/portInFlag"
},
"sendDate": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/sendDate"
},
"transferFromAccountNumber": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/transferFromAccountNumber"
},
"transferToAccountNumber": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/transferToAccountNumber"
},
"comments": {
"$ref": "resource:/json/LcBase.json#/definitions/lcBase/properties/comments"
}
}
}
Подсхема
{
"definitions": {
"lcBase": {
"type": "object",
"properties": {
"transactionId": {
"type": "integer",
"minLength": 0,
"maxLength": 15
},
"sourceType": {
"type": "string",
"enum": [
"abc",
"xyz"
]
},......
JsonNode schemaNode = JsonLoader.fromResource(getResource(reqType)); // Root Node .Class
JsonNode data = JsonLoader.fromString(jsonString);
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonSchema schema = factory.getJsonSchema(schemaNode);
report = schema.validate(data);
if (report != null) {
Iterator<ProcessingMessage> iter = report.iterator();
while (iter.hasNext()) {
ProcessingMessage pm = iter.next();
stringBuilder.append(pm.getMessage()).append(",\n");
}
result = report.isSuccess();
}
ОК. Есть ли способ проверить Enum / Array с помощью валидатора схемы json, поскольку я хотел автоматизировать проверку на стороне сервера вместо ручного.
Можете ли вы поделиться с нами своей схемой? Предположительно, это указывает на то, что "sourceType" является обязательным. Каков результат, когда вы вставляете схему и образцы данных в приложение json-schema-validator.herokuapp.com, предоставленное вашим валидатором?
Пожалуйста, отредактируйте свой вопрос. Не добавляйте комментарии. Код практически не читается. Поместите эту информацию в свой вопрос и удалите комментарии. Сложите все в одно место. Сделайте так, чтобы людям было проще вам помогать.
json не знает перечислений. Ваше "перечисление" - это просто массив