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

[WIP] Schema validator #52

Open
wants to merge 1 commit into
base: os-17/json-schema-validation
Choose a base branch
from

Conversation

michalksiazek
Copy link

Proposed change to not use ActiveModel::Validations.

TODO:

  • Test output of those validation errors
  • Meta and errors should be optional (currently validator returns that as schema errors)

@choosen choosen changed the base branch from master to os-17/json-schema-validation January 29, 2021 14:50
Copy link
Contributor

@choosen choosen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine 👍

Can you remove active_model from dev_deps ?
And upgrade schema to v7 + schemer upgrade (as discussion in target PR)
http://json-schema.org/specification-links.html#draft-7

Comment on lines +25 to +29
errors = []

schema.validate(payload).each do |validation_error|
errors << nice_error(validation_error)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errors = []
schema.validate(payload).each do |validation_error|
errors << nice_error(validation_error)
end
errors = schema.validate(payload).map do |validation_error|
nice_error(validation_error)
end

@Marahin
Copy link
Collaborator

Marahin commented Jan 29, 2021

I already removed my previous comment; I didn't realize it was actually a request to merge into target PR.

@Marahin
Copy link
Collaborator

Marahin commented Jan 29, 2021

About meta and other optional keywords, if I remember correctly I've done that as manual change in the schema (basically making it less strict):

https://github.com/visualitypl/jsonapi_parameters/pull/45/files#diff-0b898c8dfb1316b8cc5b9fa193dd5bcea2d856082ea8777060f2b44e5b72225eR78

Try that, maybe that will resolve the issue.

Comment on lines +24 to +29
unless schema.valid?(payload) # rubocop:disable Style/GuardClause
errors = []

schema.validate(payload).each do |validation_error|
errors << nice_error(validation_error)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schemer seems not caching validation result so:

Suggested change
unless schema.valid?(payload) # rubocop:disable Style/GuardClause
errors = []
schema.validate(payload).each do |validation_error|
errors << nice_error(validation_error)
end
validation_errors = schema.validate(payload)
unless validation_errors.blank? # rubocop:disable Style/GuardClause
errors = validation_errors.map do |validation_error|
nice_error(validation_error)
end

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.

3 participants