JSONスキーマでプロパティを定義している状況について混乱しています。
productスキーマを定義しようとしている項目があるとします。私のデータベースでは、productsテーブルにはid、brand_id、name、item_numberおよびがありdescriptionます。以外descriptionはすべて必須フィールドです。はidデータベースによってbrand_id自動生成され、ユーザーの作成に基づいて API によって自動的に作成時に設定されます。
これはPOST /api/products、次のデータのみを使用できることを意味します。
{
"product": {
"name": "Product Name",
"item_number": "item001"
}
}
しかし、製品スキーマをどのように定義すればよいでしょうか? プロパティidとを含める必要がありbrand_idますか? もしそうなら、それらは自動的に設定されますが、必須としてラベル付けする必要がありますか?
これは私が思いついたものです:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://jsonschema.net/products",
"type": "object",
"properties": {
"item_number": {
"id": "http://jsonschema.net/products/item_number",
"type": "string"
},
"name": {
"id": "http://jsonschema.net/products/name",
"type": "string"
},
"description": {
"id": "http://jsonschema.net/products/description",
"type": "string",
"default": "null"
}
},
"required": [
"item_number",
"name"
]
}