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

Validate and document schemas #106

Merged
merged 12 commits into from
Aug 18, 2023
Merged

Validate and document schemas #106

merged 12 commits into from
Aug 18, 2023

Conversation

sajith
Copy link
Member

@sajith sajith commented Aug 17, 2023

Fixes #105. Changes:

  • Adds some tests to validate component descriptions (topology, node, port,..) against their corresponding schemas.
  • Updates the schemas so that $ref values refer to the correct external files, and other things that surfaced when testing.
  • Formats the schemas using python3 -m json.tool <infile> <outfile. I just like mechanically formatted files. ;-)

@sajith sajith added the enhancement New feature or request label Aug 17, 2023
@sajith sajith self-assigned this Aug 17, 2023
@sajith
Copy link
Member Author

sajith commented Aug 18, 2023

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:

"vendor": {
"not": [
{
"type": "array",
"items": {
"type": "string"
}
}
]
},

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

@YufengXin
Copy link
Collaborator

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
Copy link
Member Author

sajith commented Aug 18, 2023

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
Copy link

coveralls commented Aug 18, 2023

Pull Request Test Coverage Report for Build 5903673856

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 74.635%

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

💛 - Coveralls

@YufengXin
Copy link
Collaborator

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

@sajith sajith marked this pull request as ready for review August 18, 2023 14:17
@sajith sajith requested a review from YufengXin August 18, 2023 14:17
@YufengXin
Copy link
Collaborator

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

@sajith sajith merged commit 29c46bf into main Aug 18, 2023
6 checks passed
@sajith sajith deleted the 105.schema-updates branch August 18, 2023 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

Update, validate, and document JSON schemas
3 participants