Verified Commit 6ac71d36 authored by deniss.marinuks's avatar deniss.marinuks
Browse files

updated timestamp pattern and validator.py

parent ec3916e1
* text=auto
\ No newline at end of file
......@@ -19,11 +19,11 @@
"properties": {
"start": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|(\\+[0-9]{2}:?[0-9]{2}))$"
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\+[0-9]{2}:?[0-9]{2})$"
},
"stop": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|(\\+[0-9]{2}:?[0-9]{2}))$"
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\+[0-9]{2}:?[0-9]{2})$"
}
},
"required": [
......@@ -44,14 +44,14 @@
"geometry": {
"type": "object",
"properties": {
"type": {
"type": {
"type": "string",
"pattern": "^(Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon)$"
},
"coordinates": {
"type": "array",
"minItems": 2,
"maxItems": 2
"type": "array",
"minItems": 2,
"maxItems": 2
}
}
},
......@@ -76,8 +76,8 @@
"sourceFiles": {
"type": "array",
"items": {
"type":"string",
"pattern" :"^[a-zA-Z0-9][a-zA-Z0-9._-]+$"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]+$"
},
"uniqueItems": true
},
......@@ -85,7 +85,7 @@
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items" : {
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
......@@ -117,5 +117,4 @@
"sourceFiles",
"files"
]
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -15,7 +15,7 @@
},
"timestamp": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|(\\+[0-9]{2}:?[0-9]{2}))$"
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\+[0-9]{2}:?[0-9]{2})$"
},
"status": {
"type": "object",
......@@ -45,14 +45,14 @@
"geometry": {
"type": "object",
"properties": {
"type": {
"type": {
"type": "string",
"pattern": "^(Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon)$"
},
"coordinates": {
"type": "array",
"minItems": 2,
"maxItems": 2
"type": "array",
"minItems": 2,
"maxItems": 2
}
}
},
......
#!/bin/python3
import re
import jsonschema
import argparse
import sys
import json
from json.decoder import JSONDecodeError
parser = argparse.ArgumentParser()
parser.add_argument('instance', help='json file you want to validate')
parser.add_argument('schema', help='json schema to use')
parser.add_argument('--debug', action='store_true',
help='expand error message')
args = parser.parse_args()
useUTF8 = False
useUTF8Sig = False
try:
with open(args.instance) as f:
json_file = json.load(f)
except JSONDecodeError:
useUTF8 = True
if useUTF8:
try:
with open(args.instance, encoding='utf-8') as f:
json_file = json.load(f)
except JSONDecodeError:
useUTF8Sig = True
with open(args.instance) as f:
json_file = json.load(f)
if useUTF8Sig:
with open(args.instance, encoding='utf-8-sig') as f:
json_file = json.load(f)
with open(args.schema) as f:
schema = json.load(f)
schema = json.load(f)
validator = jsonschema.Draft7Validator(schema)
......@@ -23,7 +44,10 @@ errors = validator.iter_errors(json_file) # get all validation errors
hasError = False
for error in errors:
hasError = True
print(error)
if args.debug:
print(error)
else:
print(error.message)
print('------')
if not hasError:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment