Skip to content

feat: Add Draft 2020-12 - #971

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

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

Conversation

@Roman3349

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 (copied from Draft2019) and a draft2020-12 dialect registered in Factory.
  • 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.

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).
  • unevaluatedItems/unevaluatedProperties are not supported.
  • $vocabulary is not supported (optional/format-assertion.json).
  • The optional test cases skipped for 2019-09 (ECMAScript regex, bignum, some formats, …) 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

Add basic support for Draft 2020-12 based on the Draft 2019-09 implementation,
including the mandatory prefixItems/items changes and a bundled meta-schema.

Draft 2020-12 requires format assertion to be disabled by default. Add
CHECK_MODE_FORMAT_ASSERTION to opt in, CHECK_MODE_DISABLE_FORMAT takes
precedence when both are set. Other drafts are not affected.

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

The pattern constraints of Draft 2020-12 passed "found" as the first
error parameter, so the message template "Does not match the regex
pattern %s" was filled with the validated value instead of the pattern.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant