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

sr/json: support drafts 201909 and 202012 with jsoncons #21473

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

pgellert
Copy link
Contributor

@pgellert pgellert commented Jul 17, 2024

rapidjson does not support validating schemas above draft 5, so previously we have been rewriting newer schemas in draft 4's metaschema in order to validate them. This is error prone and gets increasingly complicated for later drafts.

Instead, here we implement validating schemas against their metaschemas using the jsoncons library which has support for drafts 4, 6, 7, 2019-09, 2020-12, which covers our expected use cases.

As part of this, we also extend support for the 2019-09 and 2020-12 drafts.

Fixes https://redpandadata.atlassian.net/browse/CORE-5088
Fixes https://redpandadata.atlassian.net/browse/CORE-5089

Depends on https://github.com/redpanda-data/vtools/pull/2963

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.2.x
  • v24.1.x
  • v23.3.x

Release Notes

  • none

@BenPope
Copy link
Member

BenPope commented Jul 18, 2024

Fix for heap-buffer-overflow: danielaparker/jsoncons#528

@pgellert
Copy link
Contributor Author

Thanks Ben!

Force-pushed to make this ready for review:

  • first: address remaining todos
  • second: rebase to dev, now streaming the schema into jsoncons::json::parse(...)

@pgellert pgellert marked this pull request as ready for review July 22, 2024 14:17
@pgellert pgellert requested review from BenPope and a team as code owners July 22, 2024 14:17
@pgellert pgellert requested review from ivotron and removed request for a team July 22, 2024 14:17
@pgellert
Copy link
Contributor Author

Force-pushed to fix the failing oss build. Git cloning an untagged hash doesn't seem to work easily with FetchContent so I went with pulling it in as a tarball from github. This is similar to how the new bazel build pulls in its dependencies.

@michael-redpanda
Copy link
Contributor

fyi may need to update this: https://github.com/redpanda-data/redpanda/blob/dev/licenses/third_party.md

@andijcr andijcr self-requested a review July 23, 2024 16:03
Copy link
Member

@BenPope BenPope left a comment

Choose a reason for hiding this comment

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

No objections

pgellert added 5 commits July 24, 2024 16:32
This is needed because the next commit introduces jsoncons for
validating json schemas against their draft's metaschema and jsoncons
does not have support for draft 5.

Other schema registries do not support draft 5 either, so it is unlikely
that we would have customers that need to use draft 5 explicitly (and
can't just use the largely equivalent draft 4).
* Add an error test case for a schema that is invalid for the specific
  draft's metaschema only.
* Add an assertion that invalid schemas do raise an error.
To be used in the next commit.
rapidjson does not support validating schemas above draft 5, so
previously we have been rewriting newer schemas in draft 4's metaschema
in order to validate them. This is error prone and gets increasingly
complicated for later drafts.

Instead, this commit pulls in the jsoncons library which has support for
validing schemas in drafts 4, 6, 7, 2019-09, 2020-12, which covers our
expected use cases.
This adds support for validating schemas of the 2019-09 and 2020-12
drafts. The assertion keywords introduced in these drafts are not yet
validated for compatibility across successive schema versions. The
implementation of these keywords is going to be implemented later.

https://json-schema.org/draft/2019-09/release-notes
https://json-schema.org/draft/2020-12/release-notes
@pgellert
Copy link
Contributor Author

Force-pushed: rebased to dev and added jsoncons to third_party.md with its Boost v1 license: ada73ff

@pgellert pgellert requested a review from BenPope July 24, 2024 15:35
Copy link
Contributor

@andijcr andijcr left a comment

Choose a reason for hiding this comment

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

probably there will be merge conflicts with #21354 (or vice-versa, whichever gets merged before)

@pgellert pgellert added this to the v24.2.1-final-RC milestone Jul 25, 2024
@BenPope BenPope merged commit f29b3bf into redpanda-data:dev Jul 25, 2024
19 checks passed
@vbotbuildovich
Copy link
Collaborator

/backport v24.2.x

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

Successfully merging this pull request may close these issues.

5 participants