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: add support for custom JSONSchema keyword dynenum - allowing dynamic validation lookups against a CSV (remote, CKAN or local) #1890

Open
jqnatividad opened this issue Jun 17, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@jqnatividad
Copy link
Owner

Now that the jsonschema crate supports custom keywords, I'm considering adding a dynlookup keyword to allow validating a field against a CSV - with the CSV being either remote (http/s scheme supported) or in the local filesystem.

Though I'm sure we can have a full-blown luau script to do custom validation, it's not as convenient as JSONschema validation.

WDYT?

Originally posted by @jqnatividad in #1872 (comment)

@jqnatividad jqnatividad changed the title Now that the jsonschema crate supports [custom keywords](https://github.com/Stranger6667/jsonschema-rs?tab=readme-ov-file#custom-keywords), I'm considering adding a dynlookup keyword to allow validating a field against a CSV - with the CSV being either remote (http/s scheme supported) or in the local filesystem. validate: add support for custom JSONSchema keyword dynlookup - allowing validation lookups against a CSV (remote or local) Jun 17, 2024
@jqnatividad jqnatividad added the enhancement New feature or request label Jun 17, 2024
@jqnatividad jqnatividad changed the title validate: add support for custom JSONSchema keyword dynlookup - allowing validation lookups against a CSV (remote or local) validate: add support for custom JSONSchema keyword dynenum - allowing dynamic validation lookups against a CSV (remote or local) Jun 17, 2024
@jqnatividad
Copy link
Owner Author

jqnatividad commented Jun 17, 2024

Call the custom keyword dynenum - a dynamic version of the JSONschema spec's enum
https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.2

dynenum points to a CSV file. If no path is specified, it will be fetched from the same directory as the JSONSchema validation file.

It will be a one-column CSV, with optional display and description columns, i.e.:

value, display, description
manhattan, Manhattan, Manhattan County
queens, Queens, Queens County
brooklyn, Brooklyn, Kings County
staten_island, Staten Island, Staten Island County
bronx, Bronx, Bronx County

The names of the column do not matter, it will just treat the first column as the value column, the second column as the display column, and the third column as the description column.

The value column will be the one used for case-sensitive validation.

If the CSV file is remote, it will be downloaded and cached in the ~/.qsv-cache directory. The cached CSV enums are automatically updated using the http headers' ETag.

If the JSONSchema Validation file is also remote, the dynenum CSV files are assumed to be at the same URL as the JSONSchema file unless the CSV files have absolute URLs.

jqnatividad added a commit that referenced this issue Jun 18, 2024
…m keyword validator

for expanded `validate` functionality, paving way for `dynenums` custom keyword
see #1890
@jqnatividad
Copy link
Owner Author

In addition, if the CSV is on a CKAN site, have the ability to search the site for the latest version of a package, similar to luau's lookuptables function.

@jqnatividad jqnatividad changed the title validate: add support for custom JSONSchema keyword dynenum - allowing dynamic validation lookups against a CSV (remote or local) validate: add support for custom JSONSchema keyword dynenum - allowing dynamic validation lookups against a CSV (remote, CKAN or local) Jun 19, 2024
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
None yet
Development

No branches or pull requests

1 participant