スキーマ検証を使用します
メモ
アカウントには、データ ハブアドオンサービスへのアクセス権が必要です。
スキーマ検証を使用するには、追加のデータをスペース定義に入れる必要があります。 ID schema-validator を持つプロセッサを追加 し 、 JSON スキーマを有効な URL に、または Complete スキーマ as JSON 文字列を param スキーマに入力します。
{
"title": "My Space with JSON Schema Validation",
"description": "Description as markdown",
"processors": [
{
"id": "schema-validator",
"params": {
"schema": "<URL to schema or schema as JSON schema>"
}
}
]
}
メモ
URL を使用する場合は、 URL がパブリックアクセス可能であることを確認してください。
リクエスト
Swagger で試してください
POST /spaces
{
"title": "My Space with JSON Schema Validation",
"description": "Make sure that all features contain a field 'geometry' and a property 'name'.",
"processors": [
{
"id": "schema-validator",
"params": {
"schema": "{\"definitions\":{},\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"$id\":\"http://example.com/root.json\",\"type\":\"object\",\"title\":\"TheRootSchema\",\"required\":[\"geometry\",\"type\",\"properties\"],\"properties\":{\"geometry\":{\"$id\":\"#/properties/geometry\",\"type\":\"object\",\"title\":\"TheGeometrySchema\",\"required\":[\"type\",\"coordinates\"],\"properties\":{\"type\":{\"$id\":\"#/properties/geometry/properties/type\",\"type\":\"string\",\"title\":\"TheTypeSchema\",\"default\":\"\",\"examples\":[\"Point\"],\"pattern\":\"^(.*)$\"},\"coordinates\":{\"$id\":\"#/properties/geometry/properties/coordinates\",\"type\":\"array\",\"title\":\"TheCoordinatesSchema\",\"items\":{\"$id\":\"#/properties/geometry/properties/coordinates/items\",\"type\":\"number\",\"title\":\"TheItemsSchema\",\"default\":0.0,\"examples\":[14.3222,-2.32506]}}}},\"type\":{\"$id\":\"#/properties/type\",\"type\":\"string\",\"title\":\"TheTypeSchema\",\"default\":\"\",\"examples\":[\"Feature\"],\"pattern\":\"^(.*)$\"},\"properties\":{\"$id\":\"#/properties/properties\",\"type\":\"object\",\"title\":\"ThePropertiesSchema\",\"required\":[\"name\",\"@ns:com:here:xyz\"],\"properties\":{\"name\":{\"$id\":\"#/properties/properties/properties/name\",\"type\":\"string\",\"title\":\"TheNameSchema\",\"default\":\"\",\"examples\":[\"Toyota\"],\"pattern\":\"^(.*)$\"},\"@ns:com:here:xyz\":{\"$id\":\"#/properties/properties/properties/@ns:com:here:xyz\",\"type\":\"object\",\"title\":\"The@ns:com:here:xyzSchema\",\"required\":[\"tags\"],\"properties\":{\"tags\":{\"$id\":\"#/properties/properties/properties/@ns:com:here:xyz/properties/tags\",\"type\":\"array\",\"title\":\"TheTagsSchema\",\"items\":{\"$id\":\"#/properties/properties/properties/@ns:com:here:xyz/properties/tags/items\",\"type\":\"string\",\"title\":\"TheItemsSchema\",\"default\":\"\",\"examples\":[\"yellow\"],\"pattern\":\"^(.*)$\"}}}}}}}}"
}
}
]
}
警告
スキーマの $id プロパティには、空白文字を含めることはできません。
応答
{
"id": "x-demospace",
"owner":"{appId}",
"title": "My Space with JSON Schema Validation",
"description": "Make sure that all features contain a field 'geometry' and a property 'name'.",
"processors": [
{
"id": "schema-validator",
"params": {
"schemaUrl": "<Location of schema in the Data Hub managed S3 bucket>"
}
}
]
}
スキーマフィールド が、 データ ハブ S3 バケット内のプライベートコピーを指す schemaUrl フィールドに置き換えられました。
データを検証しています
スキーマの検証なしで、データを投稿 / 配置できます。 フィーチャーが有効な場合、それらが保存されます。 失敗したすべてのオブジェクト は保存されず、位置、 ID ( 開発者が設定した場合 ) 、およびエラーメッセージが返されます。 位置は 0 から始まり、 0 が最初のオブジェクト、 1 が 2 番目、というようになります。
リクエスト
Swagger で試してください
PUT /spaces/{spaceId}/features
対応するボディーを使用する場合:
本文を要求します
{
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [
14.3222,
-2.32506
]
},
"type": "Feature",
"propertiess": {
"name": "Toyota"
}
},
{
"geometry": {
"type": "Point",
"coordinates": [
15.8319,
-2.5913
]
},
"type": "Feature",
"properties": {
"name": "Audi"
}
},
{
"type": "Feature",
"properties": {
"name": "Tesla"
}
}
]
}
応答
{
"type": "FeatureCollection",
"inserted": [
"dxAH19uIUDCU7kch"
],
"etag": "016524948bfc1213",
"streamId": "5fb211eb-973f-11e9-9406-258558785f8d",
"failed": [
{
"id": null,
"position": 0,
"message": "Feature on position 0 has JSON schema validations errors/warnings.\n[[1,184][/properties] The object must have a property whose name is \"name\".]"
},
{
"id": null,
"position": 2,
"message": "Feature on position 2 has JSON schema validations errors/warnings.\n[[1,107][] The object must have a property whose name is \"geometry\".]"
}
],
"features": [
{
"type": "Feature",
"properties": {
"name": "Audi",
"@ns:com:here:xyz": {
"space": "X0Bphg0Q",
"tags": [],
"createdAt": 1561463405914,
"updatedAt": 1561463405914
}
},
"bbox": [
15.8319,
-2.5913,
15.8319,
-2.5913
],
"id": "dxAH19uIUDCU7kch",
"geometry": {
"type": "Point",
"coordinates": [
15.8319,
-2.5913
]
}
}
]
}
Audi の機能のみが有効であったため、唯一の機能が保存されています。 最初の ( 位置 0) のプロパティにタイプミスがあるため、他の 2 つの機能でエラー が発生しました。そのため、 properties.name フィールドがありません。 最後のフィーチャー ( 位置 2) に ジオメトリ フィールドがありません。
新しいスキーマをアップロードします
別の JSON スキーマを使用するには、新しいスキーマ JSON 文字列または URL でスペース定義を更新する必要があります。
リクエスト
Swagger で試してください
PATCH /spaces/{spaceId}
{
"title": "My Space with JSON Schema Validation",
"description": "Make sure that all features contain a field 'geometry' and a property 'name'.",
"processors": [
{
"id": "schema-validator",
"params": {
"schema": "{\"definitions\":{},\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"$id\":\"http://example.com/root.json\",\"type\":\"object\",\"title\":\"TheRootSchema\",\"required\":[\"geometry\",\"type\",\"properties\"],\"properties\":{\"geometry\":{\"$id\":\"#/properties/geometry\",\"type\":\"object\",\"title\":\"TheGeometrySchema\",\"required\":[\"type\",\"coordinates\"],\"properties\":{\"type\":{\"$id\":\"#/properties/geometry/properties/type\",\"type\":\"string\",\"title\":\"TheTypeSchema\",\"default\":\"\",\"examples\":[\"Point\"],\"pattern\":\"^(.*)$\"},\"coordinates\":{\"$id\":\"#/properties/geometry/properties/coordinates\",\"type\":\"array\",\"title\":\"TheCoordinatesSchema\",\"items\":{\"$id\":\"#/properties/geometry/properties/coordinates/items\",\"type\":\"number\",\"title\":\"TheItemsSchema\",\"default\":0.0,\"examples\":[14.3222,-2.32506]}}}},\"type\":{\"$id\":\"#/properties/type\",\"type\":\"string\",\"title\":\"TheTypeSchema\",\"default\":\"\",\"examples\":[\"Feature\"],\"pattern\":\"^(.*)$\"},\"properties\":{\"$id\":\"#/properties/properties\",\"type\":\"object\",\"title\":\"ThePropertiesSchema\",\"required\":[\"name\",\"@ns:com:here:xyz\"],\"properties\":{\"name\":{\"$id\":\"#/properties/properties/properties/name\",\"type\":\"string\",\"title\":\"TheNameSchema\",\"default\":\"\",\"examples\":[\"Toyota\"],\"pattern\":\"^(.*)$\"},\"@ns:com:here:xyz\":{\"$id\":\"#/properties/properties/properties/@ns:com:here:xyz\",\"type\":\"object\",\"title\":\"The@ns:com:here:xyzSchema\",\"required\":[\"tags\"],\"properties\":{\"tags\":{\"$id\":\"#/properties/properties/properties/@ns:com:here:xyz/properties/tags\",\"type\":\"array\",\"title\":\"TheTagsSchema\",\"items\":{\"$id\":\"#/properties/properties/properties/@ns:com:here:xyz/properties/tags/items\",\"type\":\"string\",\"title\":\"TheItemsSchema\",\"default\":\"\",\"examples\":[\"yellow\"],\"pattern\":\"^(.*)$\"}}}}}}}}"
}
}
]
}
応答
{
"id": "x-demospace",
"owner":"{appId}",
"title": "My Space with JSON Schema Validation",
"description": "Make sure that all features contain a field 'geometry' and a property 'name'.",
"processors": [
{
"id": "schema-validator",
"params": {
"schemaUrl": "<Location of updated schema in the Data Hub managed S3 bucket>"
}
}
]
}
スキーマ検証を無効にしています
スキーマ検証を無効にするに は、スペース定義を更新するだけで、スキーマ検証プロセッサ定義を送信しません。 複数のプロセッサがある場合は、他のすべてのプロセッサ定義を含める必要があります。含まれていない場合は、すべてのプロセッサが無効になります。
リクエスト
Swagger で試してください
PATCH /spaces/{spaceId}
{
"title": "My Space with JSON Schema Validation",
"description": "Make sure that all features contain a field 'geometry' and a property 'name'.",
"processors": []
}
応答
{
"id": "x-demospace",
"owner":"{appId}",
"title": "My Space with JSON Schema Validation",
"description": "Make sure that all features contain a field 'geometry' and a property 'name'.",
"processors": [],
}