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

Use json schemer #46

Merged
merged 2 commits into from
Jun 17, 2021
Merged

Use json schemer #46

merged 2 commits into from
Jun 17, 2021

Conversation

amygurski
Copy link
Contributor

@amygurski amygurski commented Jun 14, 2021

Summary

Replace json-schema gem with json_schemer. json-schema is no longer maintained (voxpupuli/json-schema/issues/423) and only supports up to draft 4. Replace with json_schemer which supports draft 4, 6 and 7.

Major version bump because this change fully drops support of drafts 1, 2 and 3.

Closes issue #45 .

Caveats

  • Schema URL is more strict. Updated readme.
  • Schema must be string json or ruby keys must be strings. Updated readme.
  • Values must be ruby objects or string key objects. They can no longer be json strings. Removed the validatable_value method accordingly. Values passed in will have to adhere to this.
  • Options available with the json-schemer gem are different than the json-schema gems and no attempts were made to support those.
  • Finally, there may be things about what this gem needs to do for different use cases that I missed testing/updating.

Testing

  • rspec passes.
  • Used the updated gem to test validation in a rails project using json drafts 4 and 6. Previously, validation failed on the draft 6 validations with: Schema not found: http://json-schema.org/draft-06/schema# because json-schema didn't recognize the schema. With these changes, it's able to validate both the draft 4 schema as previous and also the draft 6.

@amygurski amygurski marked this pull request as draft June 14, 2021 19:24
@amygurski amygurski force-pushed the use_json_schemer branch 4 times, most recently from 8a31664 to e38f5fd Compare June 16, 2021 19:20
@amygurski amygurski marked this pull request as ready for review June 16, 2021 19:20
@amygurski amygurski marked this pull request as draft June 16, 2021 19:21
json_schemer supports more current drafts 4, 6, and 7 compared to
json-schema which is limited to draft 4 or earlier.
Major version jump because this version drops support of schema drafts
1, 2 and 3 in favor of supporting versions 6 and 7.
@amygurski amygurski marked this pull request as ready for review June 16, 2021 21:40
@remi
Copy link
Member

remi commented Jun 17, 2021

Looks good to me! Thank you very much @amygurski! 👌🙂

@remi remi merged commit 4a92bc3 into mirego:master Jun 17, 2021
nTraum added a commit to CitizenLabDotCo/citizenlab that referenced this pull request Mar 3, 2022
The gem provides no changelog unfortunately, but looking at the commits https://github.com/mirego/activerecord_json_validator/commits/master the most prominent thing here is Rails 7 upgrades, which is what I'm looking for. :)

It also replaces json-schema with json-schemer. The former is not maintained anymore and only supports up to draft 4. The new gem supports draft 4, 6 and 7.

See mirego/activerecord_json_validator#46 for details.
ConnerMan added a commit to ConnerMan/activerecord_json_validator that referenced this pull request Mar 16, 2022
After migrating to json schemer in mirego#46, passing a string path as the
schema will raise JSON::ParserError. JSON Schemer
supports Pathname, so simply removing to_s from the Rails.root.join call
works.
ConnerMan added a commit to ConnerMan/activerecord_json_validator that referenced this pull request Mar 16, 2022
After migrating to json schemer in mirego#46, passing a string path as the
schema will raise JSON::ParserError. JSON Schemer
supports Pathname, so simply removing to_s from the Rails.root.join call
works.
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