Create JSON schema for MIT TIMDEX records #111
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose and background context
Create a JSON schema that can be used to validate generated MIT TIMDEX records.
Here are a few things I learned about structuring the JSON schemas:
How to represent custom classes: Initially, I struggled to understand how to represent custom classes. For instance, how do we represent the following in a JSON schema:
Eventually, I realized that we just have to represent these custom classes--like
AlternateTitle
--as instances of the JSONobject
type, which translates to a Python dictionary. Therefore, the example above can be represented in a JSON schema as:Referencing
$defs
to simplify JSON schemas: While creating the JSON schema, I noticed I was repeating several lines of code just to define a "list of strings". This is when JSON schema's $defs functionality can come in handy! There may be additional repeated steps we can capture into a $def 🤔How can a reviewer manually see the effects of these changes?
To perform some quick, high-level tests on the JSON schema, I created a script in
tests/test_jsonschema.py
. If you look at this test, I essentially copied the schema from the JSON document (transmogrifier/schemas/mit-schema-timdex.json
) into this module. To see the JSON schema validation in action, you can run:Note: I'm sure this is a temporary module and will be improved when figure out how to implement JSON schema validation effectively into transmogrifier!
Includes new or updated dependencies?
YES
Changes expectations for external applications?
NO
What are the relevant tickets?
Developer
Code Reviewer(s)