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

Feat/add jsonschema json option #3327

Closed

Conversation

ItayBenAmi
Copy link

Adds the option to validate JSON fields with a given JSON schema option.

This is done by adding JsonSchema as an optional string field in schema.JsonOptions and validating the JSON value with the JSON schema in the validators.checkJsonValue check.

The JSON schema validation was written using the https://pkg.go.dev/github.com/santhosh-tekuri/jsonschema/v5 library, which leads the line in terms of performance and correctness of GO JSON schema validator libraries, as can be seen here: https://dev.to/vearutop/benchmarking-correctness-and-performance-of-go-json-schema-validators-3247. It also supports the latest meta-schema (Draft 2020-12), which is used in the checkJsonSchema function to validate a given JSON schema.

Closes #1154.

If a value for it is given, it is validated against the Draft7 meta schema in the JsonOptions Validate function.
In the checkJsonValue function, if a JsonSchema option was selected, the JSON is validated against the given jsonschema,
and the appropriate errors are returned in case of a validation error
…h-tekuri/jsonschema,

 which supports newer jsonschema versions as well as having better error formatting and performance
…ainst the JSON schema in the checkJsonValue function.

Also fixed JsonSchema validation in the scenario where there is an empty JsonOptions object. Updated unit test accordingly
@ganigeorgiev
Copy link
Member

ganigeorgiev commented Sep 16, 2023

Thank you, but I'm not sure about the suggested implementation and I'll close the PR for now.

The linked task remains with a very low priority (see also #3271).

Couple things that I wish eventually to tackle if this ended up getting merged:

  • The Admin UI json field options also needs to be updated to reflect the change.

  • Check if possible to skip the external dependencies, even if that means implementing only the latest version of the spec (I haven't checked the JSON schema spec to see how much work that will require and whether it will be feasible at all).

@ItayBenAmi
Copy link
Author

Thank you very much for your time.

As for the two things you mentioned:

  • I added the option in the admin ui in my local branch and can open a new PR if necessary.
  • I believe that implementing JSON schema validation in line with the latest spec without any external dependencies would
    overly complicate things so I would recommend using an external library if you decide to implement this feature in the future.

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.

Feature Request: JSON Schema to Field Type JSON
2 participants