-
Notifications
You must be signed in to change notification settings - Fork 26
[SCHEMATIC-295] Add ability for JSON Schemas to have format:date and format:uri based on date and url validation rules #1620
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
Conversation
linglp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @andrewelamb ! Thanks for your hard work. My main concerns are:
- the look up of validation rule name using a list seems to be inefficient. See
_get_rule_by_nameand_VALIDATION_RULES - I found some of the variable names a bit unclear on first read. For example,
js_is_array,js_type, andjs_format. It was a bit confusing thatjs_is_arrayis separate fromjs_type, since "array" is technically a JSON Schema type. Also, I'm not entirely sure how js_format is used or when it's expected to be set. Would it be possible to clarify the distinction between these variables, either in comments or the docstring? Or is it possible to consolidate some of them so that we have less variables to maintain? - in
_get_validation_rule_based_fields, we overwritejs_typefor a couple of times. I am curious if there's a way to makeget_js_type_from_inputted_rulesmore "authoritative" so that the logic becomes easier to follow.
@andrewelamb just let me know when you're ready for me to take a last look |
linglp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @andrewelamb ! It looks good overall, just some nit comments.
SageGJ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additons looks good, just a left a few comments before finalizing. Thanks again!
SageGJ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The additions look good; just left a few comments before finalizing. Thanks again!
linglp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @andrewelamb ! Thanks for your hard work. I took another look and spotted some small typos. There's also a mix of "Args"/"Arguments" in the docstring. I think that we don't have a standard in Schematic, but maybe it is a good idea to start keeping them consistent.
One issue that I noticed is that if a rule is not supported in _VALIDATION_RULES, we are doing _VALIDATION_RULES.get and filter out None in the return which means an unsupported validation rule would fail silently. I am a bit concerned about this since users might believe all rules were found and used, but some may be silently skipped which can lead to confusion. If we decide not to raise an error, I think a warning can be helpful too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for format: date and format: uri in generated JSON Schemas based on new date and url validation rules.
- Introduce
JSONSchemaFormatenum and extend validation rule registry fordateandurl - Update schema creation logic to infer
formatalongsidetype,minimum,maximum, andpattern - Expand tests and expected schema fixtures to cover date, URI, and renamed
InRangecases
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| schematic/schemas/constants.py | Add JSONSchemaFormat and rename validation rule enum to ValidationRuleName |
| schematic/schemas/json_schema_validation_rule_functions.py | Register date/url rules and update rule helpers |
| schematic/schemas/create_json_schema.py | Extract and apply format from validation rules |
| tests/unit/test_json_schema_validation_rule_functions.py | Cover new date and url rules in unit tests |
| tests/unit/test_create_json_schema.py | Assert format field in Node and _get_validation_rule_based_fields tests |
| tests/data/expected_jsonschemas/expected.MockComponent.schema.json | Add "format": "date" / "format": "uri" entries |
| tests/data/expected_jsonschemas/expected.JSONSchemaComponent.schema.json | Inject new properties for Date, URL, and InRange |
| tests/data/example.model.jsonld | Include classes for String, Date, URL, InRange, Regex, List |
| tests/data/example.model.csv | Update component rows to list date, url, and inRange rules |
| tests/data/example.model.column_type_component.jsonld | Similar additions for column-type example |
| tests/data/example.model.column_type_component.invalid.jsonld | Add invalid-case entries for date, URL, and inRange |
| tests/data/example.model.column_type_component.invalid.csv | Update CSV for invalid column-type component |
| tests/data/example.model.column_type_component.csv | Update CSV for column-type component |
Comments suppressed due to low confidence (2)
schematic/schemas/constants.py:34
- [nitpick] The enum member is named
URIbut the validation rule is calledurl; consider renaming this member toURL(or adding aURLalias) for consistency withValidationRuleName.URL.
URI = "uri"
schematic/schemas/create_json_schema.py:225
- The docstring for
_get_validation_rule_based_fieldsdoes not describe the actual return tuple order (is_array, type, format, minimum, maximum, pattern); update it to reflect the current signature.
Gets the fields for the Node class that are based on the validation rules
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 LGTM! Helping in with the final final review (on top of Gianna's final review) since lingling has other program initiatives.
Appreciate the reviews and addition of warnings for validation rules not supported (maybe that's a good example of a Jira ticket but it was a good addition)
Note: I was testing the "dismiss review feature, and I am not a fan..." I appreciate everyone's reviews!
|
linglp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you @andrewelamb



Problem:
When creating JSON Schemas, the
dateandurlvalidation rules were being ignored.Solution:
When the
dateandurlvalidation rules are present, the JSON Schema property gets theformatkeyword. The value fo this keyword is either"format": "date"or"format": "uri"Testing:
DateandURLattributes were added to the test data modelJSONSchemaComponentdatatype. The expected generated JSON Schemas have these properties and the expectedformatkeyword.