Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Ajv ? Geojson #59

Open
ghost opened this issue Aug 11, 2020 · 1 comment
Open

Compatibility with Ajv ? Geojson #59

ghost opened this issue Aug 11, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 11, 2020

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

@ghost
Copy link
Author

ghost commented Aug 11, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants