Skip to content

feat: Add Draft 2020-12 - #971

Open
Roman3349 wants to merge 9 commits into
jsonrainbow:mainfrom
Roman3349:feat/draft-2020-12
Open

Roman3349 wants to merge 9 commits into
jsonrainbow:mainfrom
Roman3349:feat/draft-2020-12

Conversation

@Roman3349

@Roman3349 Roman3349 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds basic support for Draft 2020-12, based on the Draft 2019-09 implementation. Only changes required by the 2020-12 specification are made. The motivation was to add the draft 2020-12 to validate the OpenAPI specification v3.1, which is a subset of the draft 2020-12.

  • New Draft2020 constraint set and a draft2020-12 dialect registered in Factory. Following the existing pattern, the constraints and the Factory are full copies of the Draft 2019-09 classes, not subclasses, and no Draft2019 class is changed. Only ItemsConstraint, the new PrefixItemsConstraint, FormatConstraint, Factory and Draft2020Constraint differ from their Draft 2019-09 counterparts, apart from links to the specification.
  • prefixItems/items as required by 2020-12:
    • additionalItems is removed and the array form of items is replaced by prefixItems.
    • New PrefixItemsConstraint validates array items by position.
    • items now takes a single schema and only applies to items after those covered by prefixItems.
  • Bundled, flattened meta-schema dist/schema/json-schema-draft-2020-12.json, plus its URL mapping in UriRetriever.
  • format is an annotation by default, as 2020-12 requires (§7.2.1: assertion "MUST be disabled by default"). The new Constraint::CHECK_MODE_FORMAT_ASSERTION flag enables it. CHECK_MODE_DISABLE_FORMAT wins if both flags are set. Other drafts are not affected.
  • The JSON Schema Test Suite now runs for draft2020-12 in strict mode. The optional/format tests run with CHECK_MODE_FORMAT_ASSERTION enabled.

Draft 2019-09 changes merged into main while this PR was open are carried over to Draft 2020-12:

Same limitations as Draft 2019-09, and the matching test cases are skipped:

  • $dynamicRef/$dynamicAnchor are not supported (the successors of $recursiveRef/$recursiveAnchor, which aren't supported in 2019-09 either).
  • $vocabulary is not supported (optional/format-assertion.json).
  • The optional test cases skipped for 2019-09 (hostname, idn-hostname and time formats, the regex format, float overflow, …) are skipped for 2020-12 as well.

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional Notes

This PR also contains the commits of other open PRs, so that Draft 2020-12 gets their fixes too. The last commit applies them to the Draft 2020-12 classes:

Once those are merged, their commits drop out of this PR when it is rebased. #984 ($recursiveRef) can be ported to Draft 2020-12 in the same way once it is merged.

CHECK_MODE_FORMAT_ASSERTION uses 0x00000800, as #1007 (fail-fast) takes 0x00000400.

@Roman3349
Roman3349 force-pushed the feat/draft-2020-12 branch 2 times, most recently from 6d8fb3e to 7b5a541 Compare October 14, 2026 21:05
@DannyvdSluijs

Copy link
Copy Markdown
Collaborator

Thanks for the efforts @Roman3349

I want to wait a bit with adding the 2020-12 draft as the 2019 draft is still gaining fixes and the test suite is just passing 91%. Besides that adding a new draft requires more work such as expanding the bowtie implementation and the documentation.

Also I'm planning to review #931 soon whihc should be a good improvement for 2019 which we also need in 2020-12 if I'm not mistaken.

So please bear with me on this PR as it might take some more time to see it through.

@Roman3349

Roman3349 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

To make the review easier, I've deduplicated the Draft 2020-12 constraints. Constraints that are the same as in Draft 2019-09 are now thin subclasses of the Draft2019 classes, and Draft2020\Factory extends Draft2019\Factory. Only items, prefixItems, unevaluatedProperties and the format assertion check have their own code, and no Draft2019 file is touched. The diff went down from about 3,240 to 1,670 added lines.

I've also rebased the branch onto the current main and squashed it into a single commit. The description is updated accordingly.

@DannyvdSluijs

Copy link
Copy Markdown
Collaborator

Hi Roman,

As explained earlier at this point I would rather duplicate classes (to avoid creating hybrid schema drafts which actually don't belong anywhere). So having Draft 2020-12 extends from 2019-09 goes against that. Ideally I want to merge 2020-12 support but with code duplication. Do you think you can make that change? The next mayor version (no plans yet) we could revisit this idea all together but for now I would rather keep the existing pattern.

I'm a bit stuck for time but ill try and do my best to get this PR reviewed once changed.

@Roman3349

Copy link
Copy Markdown
Contributor Author

Done. The Draft 2020-12 constraints and its Factory are now full copies of the Draft 2019-09 classes instead of subclasses, so Draft 2020-12 is self-contained like the other drafts. Only ItemsConstraint, PrefixItemsConstraint, UnevaluatedPropertiesConstraint and FormatConstraint differ from their Draft 2019-09 counterparts. The change is in a separate commit to make it easier to review; I updated the description accordingly.

@DannyvdSluijs

Copy link
Copy Markdown
Collaborator

@Roman3349 a quick question did all the other PR's get ported into 2020-12 draft? An initial review by AI flagged some missing feature/fixes. Such as unevaluated items, ext intl check and the email format.

@Roman3349

Copy link
Copy Markdown
Contributor Author

Thanks for checking, it was right about two of them:

The email format is already covered: #1005 is part of this PR, and its changes are applied to Draft 2020-12 in 1a98dfd. Apart from the 2020-12 specific changes, Draft2020\FormatConstraint is now identical to the Draft 2019-09 one.

The only Draft 2019-09 PR not ported is #984 ($recursiveRef), as it's still open. I've updated the description.

…RFC 3986 and RFC 5321

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
… address literals

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
…aft 2020-12

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
…in Draft 2020-12

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
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.

2 participants