Skip to content

fix(parser-adapter-json-schema): accept an empty fragment in $schema - #5286

Merged
robert-hebel-sb merged 4 commits into
mainfrom
fix/parser-adapter-json-schema-empty-fragment
Nov 4, 2026
Merged

robert-hebel-sb merged 4 commits into
mainfrom
fix/parser-adapter-json-schema-empty-fragment

Conversation

@robert-hebel-sb

Copy link
Copy Markdown
Contributor

Description

https://json-schema.org/draft/2020-12/schema# identifies the same dialect as …/schema (an empty fragment is normalised away), as swagger-client and Swagger UI already treat it.

  • apidom-parser-adapter-json-schema-json-2020-12: detectionRegExp accepts the identifier with an optional #.
  • apidom-parser-adapter-json-schema-yaml-2020-12: same for plain, single- and double-quoted values and JSON-style quoted values. A plain value must end at the identifier (only whitespace or a comment may follow).
  • Both still refuse schema/, schema#/x, schema##, other dialects and the http:// form.
  • READMEs describe the detection.

Motivation and Context

The JSON adapter required the identifier without #. The YAML adapter matched a plain …schema# only because nothing anchored the end of a plain value, and did not match a quoted one. Split out of #5283 so that it can be reviewed and released on its own; the apidom-ls detection test for the empty fragment in #5283 depends on it.

How Has This Been Tested?

  • apidom-parser-adapter-json-schema-json-2020-12: npm run test (12 passing), npx eslint ./ (0 problems)
  • apidom-parser-adapter-json-schema-yaml-2020-12: npm run test (13 passing), npx eslint ./ (0 problems)
  • New detectionRegExp tests cover each accepted and refused identifier variant.

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new detection boundary rejects valid YAML flow mappings because it treats commas and closing braces as URI continuations, requiring contextual delimiter handling and regression coverage.

1 open issue
What changed in this PR

Updates ApiDOM’s JSON Schema 2020-12 adapters to recognize $schema identifiers with an empty fragment (#), supporting the language-service work in #5283.

Changes:

  • Accepts optional # in JSON and YAML detection and tightens unquoted YAML value boundaries.
  • Adds detection regression tests and documents the accepted identifiers.
  • Adds the 2020-12 namespace and adapters to the workspace unlink command.
File Description
packages/​apidom-parser-adapter-json-schema-yaml-2020-12/​test/​adapter.ts Tests accepted YAML forms and rejected identifier suffixes.
packages/​apidom-parser-adapter-json-schema-yaml-2020-12/​src/​adapter.ts Updates fragment matching and plain-value boundaries.
packages/​apidom-parser-adapter-json-schema-yaml-2020-12/​README.md Documents YAML empty-fragment detection.
packages/​apidom-parser-adapter-json-schema-json-2020-12/​test/​adapter.ts Tests JSON empty fragments and invalid identifiers.
packages/​apidom-parser-adapter-json-schema-json-2020-12/​src/​adapter.ts Allows an optional empty fragment in JSON detection.
packages/​apidom-parser-adapter-json-schema-json-2020-12/​README.md Documents JSON empty-fragment detection.
package.json Includes 2020-12 packages in global unlink cleanup.

Review effort: Balanced

*/
export const detectionRegExp =
/(?<YAML>^(["']?)\$schema\2\s*:\s*(["']?)https:\/\/json-schema\.org\/draft\/(?<version_yaml>2020-12)\/schema\3)|(?<JSON>"\$schema"\s*:\s*"https:\/\/json-schema\.org\/draft\/(?<version_json>2020-12)\/schema")/m;
/(?<YAML>^(["']?)\$schema\2\s*:\s*(["']?)https:\/\/json-schema\.org\/draft\/(?<version_yaml>2020-12)\/schema#?\3(?:(?<=["'])|(?=[ \t]*$|[ \t]+#)))|(?<JSON>"\$schema"\s*:\s*"https:\/\/json-schema\.org\/draft\/(?<version_json>2020-12)\/schema#?")/m;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 2984e76: ,/} now terminate a plain $schema value when the line is in a multi-line flow mapping (previous line ends with { or ,); block-style suffixes are still rejected. Added regression tests with and without # for both detect() and detectionRegExp.

@robert-hebel-sb
robert-hebel-sb force-pushed the fix/parser-adapter-json-schema-empty-fragment branch from 2984e76 to 7d86b6d Compare October 29, 2026 09:41
RobertHebel and others added 4 commits November 2, 2026 09:33
`https://json-schema.org/draft/2020-12/schema#` identifies the same dialect (an empty fragment is
normalised away), as swagger-client and Swagger UI already treat it. The JSON adapter's
`detectionRegExp` required the identifier without `#`; the YAML adapter matched a plain `...schema#`
only because nothing anchored the end of a plain value, and no quoted `...schema#`. Both now accept
the identifier with an optional empty fragment and still refuse other fragments and suffixes
(`schema/`, `schema#/x`, `schema##`), other dialects and the `http://` form. A plain YAML value must
end at the identifier: only whitespace or a comment may follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ction

The lookahead after a plain YAML $schema value had overlapping whitespace quantifiers, which could
backtrack polynomially on long runs of tabs (CodeQL js/polynomial-redos). Split it into two
non-overlapping alternatives; accepted and rejected inputs are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In flow context a `,` or `}` terminates a plain scalar, so the stricter value boundary rejected
valid multi-line flow mappings such as `{\n$schema: <id>,\ntype: object\n}`. Accept these
delimiters when the previous line ends with `{` or `,`, while still rejecting them as suffixes of
block-style values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@robert-hebel-sb
robert-hebel-sb force-pushed the fix/parser-adapter-json-schema-empty-fragment branch from 7d86b6d to 2ee8cd3 Compare November 2, 2026 08:33
@robert-hebel-sb
robert-hebel-sb merged commit ff6162e into main Nov 4, 2026
9 checks passed
@robert-hebel-sb
robert-hebel-sb deleted the fix/parser-adapter-json-schema-empty-fragment branch November 4, 2026 12:27
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.

4 participants