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

fix: Applied minimum amount of changes to adapt ajv-merge-patch to ajv v7 and v8 #39

Merged
merged 5 commits into from
Aug 1, 2021

Conversation

rpl
Copy link
Contributor

@rpl rpl commented Mar 29, 2021

This PR contains the minimum amount of changes I had to apply locally to make all the existing ajv-merge-patch tests to pass on both ajv v7 and ajv v8 (and it is related to #38):

  • Ajv >= v7 is exporting the Ajv class as an ESM default export
  • ajv's addKeyword type signature did change and it is now expecting the kayword to be a property of the keyword definition (and not a separate string parameter)
  • rename "id" to "$id" in one of the json schema fixture used in the tests (apparently "id" was already deprecated in draft-06, but Ajv v7 seems to make renaming "id" to "$id" mandatory, v6-to-v8-migration guide does also mention it as a mandatory change to migrate to more recent ajv versions, but I was getting the error also while running the tests with ajv v7)
  • error.dataPath has been renamed to error.instancePath in Ajv v8 (which seems also expected, because it is explicitly mentioned in v6-to-v8-migration guide notes)

I had to also change the following assertions which I'm not 100% sure if they are expected differences:

  • error.dataPath (named instancePath in v8) actual value changed from ".q" to "/q" (the original asserted value in test_validate was ".q", but on Ajv v7 and v8 the value we get is now "/q")
  • error.schemaPath actual value changed from "#/properties/q/type" to #/${keyword}/properties/q/type and "#/required into '#/${keyword}/required' (basically in Ajv >= v7 the keyword seems to be part of the resulting error schemaPath, in <v6 it wasn't)

@rpl
Copy link
Contributor Author

rpl commented Mar 29, 2021

@epoberezkin I'm not sure if this was what you had in mind for #38 (and how the unevaluatedProperties Ajv feature could be used as an alternative approach as you did mention in #38 (comment)), but I briefly tried to adapt ajv-merge-patch to ajv >= v7 and these changes did seems to be mostly expected (and the test do pass on nodejs versions a bit more recent than v4 and v6) and so I opened this PR in case it may be helpful for #38.

Would you mind to look into the changes in this PR and confirm if the changes to the new values got for the error dataPath and schemaPath described in the issue description are expected (or if there are more changes to look into)?

Thanks in advance for your help!

@treardon17 treardon17 mentioned this pull request Apr 15, 2021
@epoberezkin
Copy link
Member

Looks ok, it should be released as a major version change.

Does Ajv v7 need to be supported, or could it be skipped to support only v8?

If so, versions need to be updated (and .default could be dropped).

Thank you!

@rpl
Copy link
Contributor Author

rpl commented May 5, 2021

Looks ok, it should be released as a major version change.

👍 yeah seems more than reasonable (I haven't bumped the package version in this PR, I personally prefer to put the package version bumps in their own separate commits and I see that you are doing the same in this repo)

Does Ajv v7 need to be supported, or could it be skipped to support only v8?
If so, versions need to be updated (and .default could be dropped).

Personally I'm totally fine with only supporting Ajv v8 in the new version, and given that doing that does also reduce the size of this PR even further I did also already update this PR accordingly.

Thank you!

@epoberezkin Thank you for your work on ajv! Let me know if there is any other change needed on this PR and I'll be more than happy to come back to this asap to update it accordingly.

@treardon17
Copy link

@rpl @epoberezkin thanks for looking into upgrading this package! 😄

@jrthib
Copy link

jrthib commented May 19, 2021

Looking forward to this update

@rpl
Copy link
Contributor Author

rpl commented May 19, 2021

@epoberezkin is there any other change needed on this PR to make it ready for being merged and released? (last round of changes I pushed should cover your last round of comments from #39 (comment))

@willdurand
Copy link

@epoberezkin hey, do you think we could merge this PR and get a new release?

@treardon17
Copy link

@epoberezkin sorry to keep bugging you about this... Would it be possible to take another look at this PR and get this merged?

@epoberezkin epoberezkin merged commit 7d02dc7 into ajv-validator:master Aug 1, 2021
@epoberezkin
Copy link
Member

thank you - it works!

@epoberezkin
Copy link
Member

it's released as 5.0.0.

Any further changes - please send issue or PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants