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

DTS manifest schema #209

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open

DTS manifest schema #209

wants to merge 22 commits into from

Conversation

briehl
Copy link
Member

@briehl briehl commented Dec 3, 2024

(changes look big - they're mostly Pipfile.lock)

Adds the DTS manifest JSON schema, does some basic validation with it and returns errors.

To do that, here's the short version of what this PR does:

  • updates requirements.txt / Pipfile to include jsonschema
  • add the jsonschema as a separate file under import_specifications
  • update the config to take the path to the jsonschema file
  • builds the FileTypeResolution object so that it invokes the parser with the loaded schema
  • validates the schema, throw errors if it's not real
  • tests for the above

Actual parsing via the schema comes in the next PR. This is mostly about setup and validation.

Base automatically changed from dts-manifest-endpoint to develop December 10, 2024 01:44
@briehl briehl marked this pull request as ready for review December 10, 2024 02:18
deployment/conf/deployment.cfg Outdated Show resolved Hide resolved
staging_service/app.py Show resolved Hide resolved
Comment on lines 657 to 660
if Path._DTS_MANIFEST_SCHEMA_PATH is None:
raise Exception("Please provide DTS_MANIFEST_SCHEMA in the config file")
global _DTS_MANIFEST_SCHEMA
_DTS_MANIFEST_SCHEMA = DTS_MANIFEST_SCHEMA_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you load / parse the schema here to fail early?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to the config / schema parsing code noting that there's no tests, it's all tested manually, and if you make changes you need to add tests or test manually?

staging_service/app.py Outdated Show resolved Hide resolved
import_specifications/schema/dts_manifest.json Outdated Show resolved Hide resolved
import_specifications/schema/dts_manifest.json Outdated Show resolved Hide resolved
import_specifications/schema/dts_manifest.json Outdated Show resolved Hide resolved
import_specifications/schema/dts_manifest.json Outdated Show resolved Hide resolved
try:
jsonschema.Draft202012Validator.check_schema(dts_schema)
except jsonschema.exceptions.SchemaError as err:
raise Exception(f"Schema file {schema_path} is not a valid JSON schema: {err.message}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise Exception(f"Schema file {schema_path} is not a valid JSON schema: {err.message}")
raise Exception(f"Schema file {schema_path} is not a valid JSON schema: {err.message}") from err

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, knew I forgot something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


Path._DATA_DIR = DATA_DIR
Path._META_DIR = META_DIR
Path._CONCIERGE_PATH = CONCIERGE_PATH
Path._DTS_MANIFEST_SCHEMA_PATH = DTS_MANIFEST_SCHEMA_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is having this stored in the Path class still useful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only left it there to keep the config pattern. But since it's not used, I suppose not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

errors.append(Error(ErrorType.PARSE_FAIL, "Manifest is not a dictionary", spcsrc))

return _error(Error(ErrorType.PARSE_FAIL, "Manifest is not a dictionary", spcsrc))
validator = jsonschema.Draft202012Validator(dts_manifest_schema)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this line also be moved to the config section, so this function expects a validator class? Then the warning about invalid schemas should be moot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 879 to 883
@pytest.mark.parametrize("bad_schema", [None, 1, [], {"foo"}])
def test_dts_manifest_bad_schema(bad_schema):
f = _get_test_file("manifest_small.json")
with pytest.raises(Exception):
parse_dts_manifest(f, bad_schema)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No checking the error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moot with the change to pass in the validator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link

sonarcloud bot commented Dec 12, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants