-
Notifications
You must be signed in to change notification settings - Fork 8
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
[OS-17] JSON Schema validation #45
base: master
Are you sure you want to change the base?
Conversation
lib/jsonapi_parameters/default_handlers/to_many_relation_handler.rb
Outdated
Show resolved
Hide resolved
Co-authored-by: Paweł Strzałkowski <[email protected]>
when they should be
Co-authored-by: Patryk Ptasiński <[email protected]>
Things left to do:
|
035acc5
to
e9f8b7b
Compare
The current version works "good enough" for us at LL, there are exactly 3 tests failing and they are just nontypical usage of |
@ipepe I'm wondering whether other users may see a breaking change while updating. If I understand correctly, you are experiencing this, so this would imply a breaking change version bump. Could you share (perhaps in a confidential environment) what are the non-typical usages? Specific code lines where you execute jsonapi_parameters translation? Maybe this way we could provide an interface that would not enforce the change so the existing users would be able to take control over the update. |
@@ -0,0 +1,397 @@ | |||
{ | |||
"$schema": "http://json-schema.org/draft-06/schema#", |
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.
there is draft -07
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.
Even now 07 is not edge: http://json-schema.org/draft/2019-09/release-notes.html
I believe we should resolve the subject of version update (and whether it can be minor upgrade) in our library and then we can think about moving on to next version of schema.
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.
https://json-schema.org/draft/2019-09/schema
that's right. Therefore the draft was upgraded also in article linked in repo 👍
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.
davishmcclurg/json_schemer#44
is supporting max draft-07 currently according to readme
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.
Therefore the draft was upgraded also in article linked in repo 👍
I have no clue which article or link you are talking about.
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.
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.
oh wrong link: https://polythematik.de/2020/02/17/ruby-json-schema/
end | ||
@jsonapi_unsafe_hash = ensure_naming(params, naming_convention) | ||
|
||
JsonApi::Parameters::Validator.new(@jsonapi_unsafe_hash.deep_dup).validate! if should_prevalidate? |
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.
validate!
has been provided by rails >= 5.0
So this solution limits the benefits for rails 4.0, which are not maintained anymore.
Michał Książek is coding solution to change that
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.
That should be pretty easy to overcome, as #validate
is present since Rails 4.2.1: https://apidock.com/rails/v4.2.1/ActiveModel/Validations/validate
So perhaps it is worth to check whether this method is defined, and if not, then just call validate
and raise on failure.
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.
Since we already limit ourselves to >= 4.1.8, we might as well limit ourselves to 4.2.1.
https://github.com/visualitypl/jsonapi_parameters/blob/master/jsonapi_parameters.gemspec#L25
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.
We spoke with Michał to drop activeModel validation at all - it does not provide big value
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.
Indeed from what I can see in the upcoming PR to this branch, this seems like a move in good direction. We just have to ensure this will be a solid solution, as this will be something technically "invented here" whereas up until this point we have used proven and well tested ActiveModel validations.
Unknown(s), to debate(s), discussables: