반응형
json 스키마에서 배열의 최소 크기를 정의하는 방법
json 파일의 스키마를 만들고 싶습니다.여러 가지 제품을 위한 것입니다.
json 스키마는 다음과 같습니다.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
"title": "Product",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "number"
},
"name": {
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"dimensions": {
"type": "object",
"properties": {
"length": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
},
"required": ["length", "width", "height"]
},
"warehouseLocation": {
"description": "Coordinates of the warehouse with the product",
"$ref": "http://json-schema.org/geo"
}
},
"required": ["id", "name", "price"]
}
}
어레이에는 적어도1개의 항목이 포함되어 있어야 합니다.어레이의 최소값을 정의하려면 어떻게 해야 합니까?
최소 디피니션을 추가해야 합니까?
배열 내의 최소 항목 수를 설정하려면"minItems"
.
참조:
https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#section-5.3.3
그리고.
http://jsonary.com/documentation/json-schema/?section=section/Array%20 검증
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
...
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"maxItems": 4,
"uniqueItems": true
}
},
"required": ["id", "name", "price"]
}
초안 v4가 원하는 것을 허용하는 것 같습니다.http://json-schema.org/example1.html 에서 :
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
...
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
},
"required": ["id", "name", "price"]
}
"tags" 속성은 최소 항목 수(1)를 포함하는 배열로 정의됩니다.
아니겠죠, 적어도 초안 작성은 해야 할 것 같아요.minimum
는 배열이 아닌 숫자 값에만 적용됩니다.
5.1. 숫자 인스턴스 검증 키워드(숫자 및 정수)
...
5.1.3 최소 및 배타적 최소
따라서 어레이의 최소 항목/최대 항목에 대해 잘 알고 있어야 합니다.
언급URL : https://stackoverflow.com/questions/16583485/how-to-define-the-min-size-of-array-in-the-json-schema
반응형
'programing' 카테고리의 다른 글
POST에서 json을 웹 API 서비스로 보내는 중 오류가 발생했습니다. (0) | 2023.03.27 |
---|---|
일반적으로 하나의 컴포넌트에 하나 또는 여러 개의 useEffect 훅을 사용하는 것이 좋습니까? (0) | 2023.03.27 |
스프링 부트바인드 @Value to Enum 대소문자를 구분하지 않음 (0) | 2023.03.22 |
Wordpress 구텐베르크 미디어 업로드 비디오 갤러리 (0) | 2023.03.22 |
React에서 사용자 세션을 관리하는 가장 좋은 방법은 무엇입니까? (0) | 2023.03.22 |