2.2.7 • Published 4 years ago

@spacemakerai/ajv v2.2.7

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Spacemaker AJV JSONSchema Validator

Contains common JSON schema validator for use both on server and in browser. The current validator follows the JSONSchema draft 7. The validator also contains extended validation keywords for use in combination with, among other things, support for validating GeoJSON.

Extended validation keywords

geometry

For use with GeoJSON geometry:

Schema:

{
    geometry: {
        truncate?: { precision?: number, coordinates?: number },
        hasArea?: boolean | { exclusiveMinimum?: number; max?: number },
        rewind?: boolean,
        kinks?: boolean | { min?: number; max?: number }
    }
}

Example use with Polygon schema with hasArea validation:

{
  "type": "object",
  "required": ["type", "coordinates"],
  "geometry": {
    "hasArea": true
  },
  "properties": {
    "type": {
      "const": "Polygon"
    },
    "coordinates": {
      "type": "array",
      "items": {
        "type": "array",
        "minItems": 4,
        "items": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "number"
          }
        }
      }
    },
    "bbox": {
      "type": "array",
      "minItems": 4,
      "items": {
        "type": "number"
      }
    }
  }
}

uniqueFeatures

For use with GeoJSON Feature arrays:

Schema:

{
  uniqueFeatures: boolean
}

Example use with FeatureCollection schema:

{
  "type": "object",
  "required": ["type", "features"],
  "properties": {
    "type": {
      "enum": ["FeatureCollection"]
    },
    "features": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["type", "geometry", "properties"],
        "properties": {
          "type": {
            "enum": ["Feature"]
          },
          "id": {
            "type": "string"
          },
          "properties": {
            "type": "object",
            "required": [],
            "properties": {
              "area": {
                "type": "number"
              }
            },
            "additionalProperties": true
          },
          "geometry": {
            "type": "object",
            "required": ["type", "coordinates"],
            "properties": {
              "type": {
                "enum": ["Polygon"]
              },
              "coordinates": {
                "type": "array",
                "items": {
                  "type": "array",
                  "minItems": 4,
                  "items": {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 3,
                    "items": {
                      "type": "number"
                    }
                  }
                }
              }
            },
            "additionalProperties": false,
            "geometry": {
              "rewind": true,
              "hasArea": true,
              "truncate": {
                "coordinates": 2
              },
              "kinks": false
            }
          }
        },
        "additionalProperties": false
      },
      "uniqueItems": true,
      "uniqueFeatures": true,
      "additionalItems": false
    }
  },
  "additionalProperties": false
}
2.2.7

4 years ago

2.2.6

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago