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

Merged
merged 25 commits into from
Dec 13, 2024
Merged

DTS manifest schema #209

merged 25 commits into from
Dec 13, 2024

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
staging_service/app.py Outdated Show resolved Hide resolved
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
staging_service/app.py Outdated Show resolved Hide resolved
staging_service/app.py Outdated Show resolved Hide resolved
tests/import_specifications/test_individual_parsers.py Outdated Show resolved Hide resolved
@briehl briehl requested a review from MrCreosote December 12, 2024 22:26

Path._DATA_DIR = DATA_DIR
Path._META_DIR = META_DIR
Path._CONCIERGE_PATH = CONCIERGE_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.

This line seems pointless

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 don't like how git manages staged files pre-commit, like the one that had this fix. I get how it does it, but I don't like it.
Fixed.

Comment on lines 1277 to 1279
not_real_file = Path("not_real")
while not_real_file.exists():
not_real_file = Path(str(uuid.uuid4()))
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this doesn't just start with the UUID file?

Copy link
Member Author

@briehl briehl Dec 13, 2024

Choose a reason for hiding this comment

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

I figured "not_real" was a unique enough file name. Unless it isn't, then proceed to uuids. I can change it anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

wrong_schema = "not valid json"
schema_file = tmp_path / f"{uuid.uuid4()}.json"
schema_file.write_text(wrong_schema, encoding="utf-8")
with pytest.raises(json.JSONDecodeError, match="Expecting value: line 1 column 1"):
Copy link
Member

Choose a reason for hiding this comment

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

This seems like the wrong error, naively - there's a value there, it's just the wrong value

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the error provided by the json decoder. It's expecting a JSON value, not a bare string.

invalid = {"properties": {"some_prop": {"type": "not_real"}}}
schema_file = tmp_path / f"{uuid.uuid4()}.json"
schema_file.write_text(json.dumps(invalid), encoding="utf-8")
exp_err = f"Schema file {schema_file} is not a valid JSON schema: 'not_real' is not valid"
Copy link
Member

Choose a reason for hiding this comment

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

There's no way to get it do spit out the path to the incorrect part of the structure? For a newbie this'll be a pain to debug

Copy link
Member Author

@briehl briehl Dec 13, 2024

Choose a reason for hiding this comment

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

In that particular case, the absolute path is [], and the "schema path" is ['allOf', 0, 'type'] which is also not very helpful. Except it says "type" in it.

IMO, a newbie shouldn't be making new schemas without testing them elsewhere, throwing them at the service, and expecting it to load on startup and be super friendly.

Copy link
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

LGTM

@briehl briehl merged commit 5a7c064 into develop Dec 13, 2024
11 checks passed
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