Porównaj ceny domen i usług IT, sprzedawców z całego świata

Jak określić minimalny rozmiar tablicy w schemacie JSON


Chcę utworzyć plik json, który jest schematem dla tablicy produktów.
Schemat json jest podobny do poniższego:
{
"$schema": "[url=http://json-schema.org/draft-04/schema#"]http://json-schema.org/draft-04/schema#"[/url],
"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": "[url=http://json-schema.org/geo"]http://json-schema.org/geo"[/url]
}
},
"required": ["id", "name", "price"]
}
}

Tablica musi zawierać co najmniej jeden element. Jak mogę określić minimum tablicy?
Czy muszę dodać minimalną definicję?
Zaproszony:
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Aby ustawić minimalny numer pozycji w tablicy, użyj
„minItems”
.
Widzieć:
http://tools.ietf.org/html/dra ... 5.3.3
http://tools.ietf.org/html/dra ... 5.3.3
i
http://jsonary.com/documentati ... ation
http://jsonary.com/documentati ... ation
{
"$schema": "[url=http://json-schema.org/draft-04/schema#"]http://json-schema.org/draft-04/schema#"[/url],
"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"]
}
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Przypuszczam, że nie, przynajmniej patrząc na wersję roboczą,
minimum
dotyczy tylko wartości liczbowych, a nie tablic.

5.1. Słowa kluczowe walidacyjne dla instancji numerycznych (liczba i liczba całkowita)

...
5.1.3. minimum i wyłącznośćMinimum
http://tools.ietf.org/html/dra ... atego powinieneś być dobry z min/maxItems dla tablic.
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Wygląda na to, że projekt v4 pozwala na to, czego szukasz. Od

http://json-schema.org/example1.html
http://json-schema.org/example1.html
:
{
"$schema": "[url=http://json-schema.org/draft-04/schema#"]http://json-schema.org/draft-04/schema#"[/url],
"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"]
}

Zwróć uwagę, że właściwość „tags” jest zdefiniowana jako tablica z minimalną liczbą elementów (1).

Aby odpowiedzieć na pytania, Zaloguj się lub Zarejestruj się