atlanticwave-sdx / datamodel

Parsing and validation library for AtlanticWave SDX.
https://www.atlanticwave-sdx.net
MIT License
0 stars 1 forks source link

Validate and document schemas #106

Closed sajith closed 1 year ago

sajith commented 1 year ago

Fixes #105. Changes:

sajith commented 1 year ago

This appears to be the way to validate a given JSON blob against a schema with Python:

import json
import pathlib

import jsonschema
import jsonref    # to expand `$ref`

blob = json.loads(pathlib.Path("port-data.json").read_text())
schema_file = pathlib.Path("port-schema.json")
schema = jsonref.loads(schema_file.read_text(), base_uri = schema_file.absolute().as_uri())

jsonschema.validate(blob, schema)

With some changes (correct $ref etc), most of the test data files validate against the schemas we have, except for this little annoying vendor thing:

https://github.com/atlanticwave-sdx/datamodel/blob/2548a8edaf09843e647e2291d9eac9912bf7d0bf/schemas/Service.json#L15-L24

Perhaps that could be removed? The draft Data Model 2.0.0 spec has no mention of a vendor field.

YufengXin commented 1 year ago

Tthis can be commented out for now. Noticing the 'not' key, it was asked by FIU to be able to exclude certain vendor's equipments for security reasons.

sajith commented 1 year ago

Sadly JSON do not have "real" comment syntax. And it is the not that makes validator unhappy:

jsonschema.exceptions.SchemaError: [{'type': 'array', 'items': [{'type': 'string'}]}] is not of type 'object', 'boolean'

I'm guessing it should be "not": { "anyOf" : [...] }" -- that anyOf should give not the boolean it needs.

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 5903673856


Totals Coverage Status
Change from base Build 5882765968: 0.0%
Covered Lines: 1029
Relevant Lines: 1247

💛 - Coveralls
YufengXin commented 1 year ago

Yes, this should work: "not": { "anyOf" : [...] }"

YufengXin commented 1 year ago

This tool is cool. I guess it's relatively new. I googled around and didn't find such a tool two years ago!