Repository navigation
fix(parser-adapter-json-schema): accept an empty fragment in $schema - #5286
Merged
robert-hebel-sb merged 4 commits intoNov 4, 2026
Merged
Conversation
This was referenced Oct 28, 2026
There was a problem hiding this comment.
🟡 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; |
Contributor
Author
There was a problem hiding this comment.
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
force-pushed
the
fix/parser-adapter-json-schema-empty-fragment
branch
from
October 29, 2026 09:41
2984e76 to
7d86b6d
Compare
glowcloud
approved these changes
Oct 30, 2026
`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
force-pushed
the
fix/parser-adapter-json-schema-empty-fragment
branch
from
November 2, 2026 08:33
7d86b6d to
2ee8cd3
Compare
robert-hebel-sb
deleted the
fix/parser-adapter-json-schema-empty-fragment
branch
November 4, 2026 12:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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:detectionRegExpaccepts 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).schema/,schema#/x,schema##, other dialects and thehttp://form.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)detectionRegExptests cover each accepted and refused identifier variant.Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests