문제 설명
JSON 스키마 기반 문서 (Documentation based on JSON Schema)
제 JSON 스키마를 사용하여 문서를 생성하고 싶습니다.
아래 예에서는 JSON의 출력 메시지에서 사용할 수 있는 모든 ErrorNumber/ErrorMessage 조합을 나열하고 싶습니다.
하지만 개체 수준에서 방법을 찾을 수 없습니다. "예&" 또는 "열거형"; 실패했습니다.
해결 방법이 있습니까?
{
"type": "object",
"required": [
"ErrorNumber",
"ErrorMessage"
],
"properties": {
"ErrorNumber": {
"$id": "#root/ErrorNumber",
"type": "integer"
},
"ErrorMessage": {
"$id": "#root/ErrorMessage",
"type": "string"
}
}
}
참조 솔루션
방법 1:
Did you mean to write
"$ref"
where you use"$id"
in the example?Where exactly did you have problems with
enum
? The following works fine for me with a draft‑2020‑12 Validator (and after removing your "$id"!):- Different approaches, in case you still can change that:
</ol>
{
// ... your JSON here ...
"enum": [
{"ErrorNumber": 200, "ErrorMessage": "OK"},
{"ErrorNumber": 404, "ErrorMessage": "Not found."}
// ...
]
}
If your error numbers start at 0 and are contiguous, then an Array of messages might serve your purpose.
Alternatively an object with numerical keys might:
{
"200": "OK",
"404": "Not found."
}