Open ghost opened 4 years ago
Context : Validate input data with Ajv
Request.Body
{ "type":"FeatureCollection", "features":[ { "type":"Feature", "geometry":{ "type":"Point", "coordinates":[ 102, 0.5 ] }, "properties":{ "prop0":"value0" } }, { "type":"Feature", "geometry":{ "type":"LineString", "coordinates":[ [ 102, 0 ], [ 103, 1 ], [ 104, 0 ], [ 105, 1 ] ] }, "properties":{ "prop0":"value0", "prop1":0 } }, { "type":"Feature", "geometry":{ "type":"Polygon", "coordinates":[ [ [ 100, 0 ], [ 101, 0 ], [ 101, 1 ], [ 100, 1 ], [ 100, 0 ] ] ] }, "properties":{ "prop0":"value0", "prop1":{ "this":"that" } } } ] }``` **Schema generated from the request.body** ```json { "$id":"http://json-schema.org/draft-04/schema#", "$schema":"http://json-schema.org/draft-04/schema#", "title":"Product", "type":"object", "properties":{ "type":{ "type":"string" }, "features":{ "type":"array", "items":{ "type":"object", "properties":{ "type":{ "type":"string" }, "geometry":{ "type":"object", "properties":{ "type":{ "type":"string" }, "coordinates":{ "type":"array", "items":{ "oneOf":[ { "type":"number" }, { "type":"number" }, { "type":"number" }, { "type":"number" }, { "type":"number" } ], "type":"array" } } } }, "properties":{ "type":"object", "properties":{ "prop0":{ "type":"string" }, "prop1":{ "type":"object", "properties":{ "this":{ "type":"string" } } } } } }, "required":[ "type", "geometry", "properties" ] } } } }
Schema validation with Ajv
[ { keyword: 'type', dataPath: '.features[0].geometry.coordinates[0]', schemaPath: '#/properties/features/items/properties/geometry/properties/coordinates/items/type', params: { type: 'array' }, message: 'should be array' } ]
Why Ajv detects an issue ?
Thx
See link : https://gist.github.com/ThomasG77/d9c04724e63f3d327bd3ff7534bc0968
Context : Validate input data with Ajv
Request.Body
Schema validation with Ajv
Why Ajv detects an issue ?
Thx