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 @@ ...@@ -19,11 +19,11 @@
"properties": { "properties": {
"start": { "start": {
"type": "string", "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": { "stop": {
"type": "string", "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": [ "required": [
...@@ -44,14 +44,14 @@ ...@@ -44,14 +44,14 @@
"geometry": { "geometry": {
"type": "object", "type": "object",
"properties": { "properties": {
"type": { "type": {
"type": "string", "type": "string",
"pattern": "^(Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon)$" "pattern": "^(Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon)$"
}, },
"coordinates": { "coordinates": {
"type": "array", "type": "array",
"minItems": 2, "minItems": 2,
"maxItems": 2 "maxItems": 2
} }
} }
}, },
...@@ -76,8 +76,8 @@ ...@@ -76,8 +76,8 @@
"sourceFiles": { "sourceFiles": {
"type": "array", "type": "array",
"items": { "items": {
"type":"string", "type": "string",
"pattern" :"^[a-zA-Z0-9][a-zA-Z0-9._-]+$" "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]+$"
}, },
"uniqueItems": true "uniqueItems": true
}, },
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"uniqueItems": true, "uniqueItems": true,
"items" : { "items": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
...@@ -117,5 +117,4 @@ ...@@ -117,5 +117,4 @@
"sourceFiles", "sourceFiles",
"files" "files"
] ]
} }
\ No newline at end of file
\ No newline at end of file
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
}, },
"timestamp": { "timestamp": {
"type": "string", "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": { "status": {
"type": "object", "type": "object",
...@@ -45,14 +45,14 @@ ...@@ -45,14 +45,14 @@
"geometry": { "geometry": {
"type": "object", "type": "object",
"properties": { "properties": {
"type": { "type": {
"type": "string", "type": "string",
"pattern": "^(Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon)$" "pattern": "^(Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon)$"
}, },
"coordinates": { "coordinates": {
"type": "array", "type": "array",
"minItems": 2, "minItems": 2,
"maxItems": 2 "maxItems": 2
} }
} }
}, },
......
#!/bin/python3 #!/bin/python3
import re
import jsonschema import jsonschema
import argparse import argparse
import sys import sys
import json import json
from json.decoder import JSONDecodeError
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('instance', help='json file you want to validate') parser.add_argument('instance', help='json file you want to validate')
parser.add_argument('schema', help='json schema to use') parser.add_argument('schema', help='json schema to use')
parser.add_argument('--debug', action='store_true',
help='expand error message')
args = parser.parse_args() 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: if useUTF8Sig:
json_file = json.load(f) with open(args.instance, encoding='utf-8-sig') as f:
json_file = json.load(f)
with open(args.schema) as f: with open(args.schema) as f:
schema = json.load(f) schema = json.load(f)
validator = jsonschema.Draft7Validator(schema) validator = jsonschema.Draft7Validator(schema)
...@@ -23,7 +44,10 @@ errors = validator.iter_errors(json_file) # get all validation errors ...@@ -23,7 +44,10 @@ errors = validator.iter_errors(json_file) # get all validation errors
hasError = False hasError = False
for error in errors: for error in errors:
hasError = True hasError = True
print(error) if args.debug:
print(error)
else:
print(error.message)
print('------') print('------')
if not hasError: 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