You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(json-schema-unified): add OAS 3.0 and 2.0 dialects - #11136
Stack 3/3, based on #11135 (unified view for 3.1/3.2) ← #11134 (Tailwind build) ← #11133 (spec graph).
Description
This PR extends the opt-in unified JSON Schema view (unifiedJSONSchemaEnabled) to OpenAPI 2.0 and 3.0. With the option on, every OpenAPI version now renders its Schemas/Models section and Schema tab through json-schema-unified. With it off, nothing changes.
Two new dialects, oas30 and swagger2, each with its own keyword list. Every keyword keeps the meaning it has in that version:
Boolean exclusiveMaximum/exclusiveMinimum combined with maximum/minimum read as < 10, > 0, (1, 10].
3.0 nullable: true reads as T | null. 3.0 keeps oneOf/anyOf/not, writeOnly, deprecated and the object discriminator.
2.0 has a string discriminator, allOf as its only combiner, and type: file.
Keywords outside the version (e.g. const, $defs) are treated like any unknown keyword: shown only with showExtensions. json-schema-5 showed them as plain rows; this change was confirmed.
writeOnly still hides properties from 2.0 response schemas, as json-schema-5 does (confirmed), but it isn't rendered as a 2.0 keyword.
Nested schema names (2.0/3.0 only): a property or items shows the nested schema's name, its title or else its reference name (category Category), as json-schema-5 does.
Reference path (2.0/3.0 only): an expanded nested schema shows its reference path, e.g. #/definitions/Category.
Recursive models stay expandable. swagger-client's 2.0/3.0 strategies leave cyclic $refs in place. The plugin looks the definition up by local name (resolved subtree first, else raw JSON, like findDefinition) only when the schema renders, so recursion goes only as deep as the user expands. "Expand all" stops at a reference already resolved higher up the same branch.
Models section per version: 2.0 uses definitions with the heading "Models"; 3.0 uses components/schemas with "Schemas". The layout, scroll and lazy-resolve keys are identical to json-schema-5's, so deep links and expansion state behave the same.
Parity and browsers:
The unified-json-schema Playwright project now covers all four versions (103 tests). Its guard also recognises the json-schema-5 DOM as classic.
A new webkit-unified project runs the plugin's own specs in WebKit, for the Tailwind v4 browser floor (Safari 16.4).
nodejs.yml and release-swagger-ui.yml now install chromium webkit, and the browser cache key includes WebKit. Still 4 shards.
The json-schema-unified spec gets a 2.0/3.0 dialects section.
The goal gets the opt-in capability.
The oas-versions spec records a known limitation: the oas31/oas32 Model/Models wrappers cache their instance on a static field keyed by location.pathname. This is inferred from the code and not yet reproduced; it will be fixed separately.
CLAUDE.md lists the Playwright projects.
Motivation and Context
This completes "one schema UI for every OpenAPI version" behind the opt-in flag, which is the path to retiring json-schema-5's model views. Example values, parameter input widgets and the 2.0 scheme picker remain out of scope. With the option on, the Schema tab can therefore disagree with Example Value for 2.0/3.0; this is recorded as a known limitation in the module spec.
Points to review closely:
the lazy $ref resolution (legacy.ts#getLazyRef, hooks.ts);
the CI workflow changes, which add WebKit installs and so make CI slower.
How Has This Been Tested?
The tree of this PR is identical to the fully verified final tree.
Unit:npm run test:unit → 1066 passed, 12 skipped. This includes 157 plugin tests, covering per-dialect keyword lists, the text of exclusive bounds, nullable, 2.0 discriminator and type: file, nested names with pointer decoding, the reference path for 2.0/3.0 only, 3.1 naming unchanged, recursive models, and readOnly/writeOnly for 2.0/3.0.
e2e, chromium:npx playwright test --project=chromium → 705 passed, 4 skipped. This includes new 2.0/3.0 plugin specs: Models vs Schemas heading, nested name and reference path, exclusive bounds, nullable, discriminator, a recursive model expanded two levels, the Schema tab, and readOnly/writeOnly request→response.
e2e parity:npx playwright test --project=unified-json-schema → 103 passed. It re-runs existing schema specs for 2.0, 3.0, 3.1 and 3.2 with the option on.
Eight assertions were adapted to intended differences, each in the unified branch only:
nullable shows as object | null;
deprecated is a chip, and in 2.0 it's hidden as a non-2.0 field;
the external-docs layout;
oas3-extension opens its extension blocks first;
the example value text;
one 2.0 nested-state test expands tags instead of id;
editor-1868 became stricter.
No assertion was weakened.
The guard fails when the option is forced to =false.
e2e, WebKit:npx playwright test --project=webkit-unified → 52 passed.
Build and static checks:npm run build + npm run test:artifact → 8 passed. lint-errors, tsc, e2e:typecheck are clean. check-plugin-conventions → 0 errors.
Visual check: screenshots of the 2.0/3.0 Models section and Schema tab, option off vs on, light and dark, were reviewed for differences in what information is shown.
Screenshots (if appropriate):
All captures use this PR's build and the e2e fixtures under test/e2e-playwright/static/documents/features/json-schema-unified/. Before is the classic json-schema-5 view (option off, same as the base); after is unifiedJSONSchemaEnabled=true. Each capture checks that window.ui.getConfigs().unifiedJSONSchemaEnabled really had the expected value.
OpenAPI 2.0 Models section (Pet expanded)
Before (classic)
After (unified)
After, the view shows constraint chips ([0, 30], > 0, (1, 10]), the read-only marker, the nested schema name (category Category), the 2.0 string discriminator, XML and external docs.
OpenAPI 3.0 Schemas section (Pet expanded)
Before (classic)
After (unified)
OpenAPI 3.0 Schema tab (request body of createUser)
Before (classic)
After (unified)
After, the tab shows the reference path #/components/schemas/User and the write-only marker; the readOnly id is hidden in the request schema.
Dark mode (2.0, unified)
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.
The reason will be displayed to describe this comment to others. Learn more.
Lazy-ref lookup could use the spec selectors.findSchemaDefinition re-implements the lookup that specSelectors.findDefinition (2.0) and specSelectors.findSchema (3.x, via the oas3 wrapper) already do: resolved subtree first, else the raw JSON. I compared them side by side on the same Immutable state (resolved + raw, raw only, neither, empty-Map resolved, null resolved) and the results are identical. They differ only for non-Map values (a string or boolean raw schema): the selector returns them and ours returns null, but getLazyRef's isPlainObject guard rejects them anyway, so rendering doesn't change.
Suggestion: toPlainSchema(specSelectors.findDefinition(name)). toPlainSchema keeps the plain-object conversion, so findSchemaDefinition can go. getDocumentUrl already reads the url selector, so nothing changes there. A test through getUnifiedView against the real selectors would cover the swap, since today's unit test stubs them.
The reason will be displayed to describe this comment to others. Learn more.
Correction to the comment above:specSelectors.findDefinition isn't a safe replacement for findSchemaDefinition in 2.0, so the lookup stays as it is. With the oas3 plugin loaded (the apis preset always loads it), findDefinition("Node") returns null for a 2.0 document, even though the definition is in the spec. onlyOAS3 (oas3/spec-extensions/wrap-selectors.js) falls back with ori(...args), but args still starts with the state while ori is already bound to it. The original selector therefore receives the state as the schema name. 3.0 works, since it goes through findSchema. My earlier comparison ran the raw selector functions, not the wrapped selectors of a System, so it missed this.
The old renderer has the same problem: with the oas3 plugin loaded, json-schema-5's Model renders a left-in-place $ref in a 2.0 document without its definition: as the raw $ref text, or as an empty expandable object when $$ref is also set (3.0 expands it). findDefinition is the only selector affected: I compared the other onlyOAS3-wrapped spec and auth selectors on a 2.0 document, with and without the plugin, and they return the same values.
This could be fixed in core by dropping the extra state argument in the fallback (ori(...args.slice(1))). That would also make the old renderer expand these refs in 2.0, so it belongs in a separate PR, and the unified lookup could then use findDefinition.
The reason will be displayed to describe this comment to others. Learn more.
Ref-derived names for the Schema tab's schema differ between dialects. For a schema that comes from a ref like #/components/schemas/User/properties/foo (or #/definitions/User/properties/foo in 2.0):
3.1/3.2 title (getModelName here): User/properties/foo, the remainder after the schemas prefix.
2.0/3.0 title (legacy.ts#getRefSchemaName, via fn.getTitle): foo, the last pointer token.
json-schema-5 and oas31 both return the remainder, and nothing for refs that don't point under #/definitions/ or #/components/schemas/. 2.0/3.0 currently names those as well, for example #/components/parameters/X becomes X.
Proposal: fix this in getRefSchemaName only. For 2.0/3.0 it should return the remainder after #/definitions/ (2.0) or #/components/schemas/ (3.0), and nothing for other refs. That aligns it with the 3.1/3.2 title and with the old renderers. The old renderer and the 3.1/3.2 helper stay untouched, and the two copies stay separate. Does that rule sound right, or should deeper pointers show something else, for example only the last token?
The reason will be displayed to describe this comment to others. Learn more.
Nested $ref schemas get no JumpToPath in the unified view. Here the button is placed once per Schemas-section panel (top right). json-schema-5 (2.0/3.0) also renders it for nested schemas: in object-model.jsx, every nested object that is a $ref gets a JumpToPath (.model-jump-to-path), next to the collapsed {…} and after the open brace. It passes the nested spec path (properties,key, additionalProperties, allOf,i, anyOf,i, oneOf,i, not). The root of the Schema tab gets one too when it is a $ref. With unifiedJSONSchemaEnabled on, those buttons disappear for 2.0/3.0 documents. The 3.1/3.2 renderers never called JumpToPath, not even per panel.
Proposal: show it for every nested schema that came from a $ref ($$ref), in all four dialects, with that schema's spec path, at the end of its title row next to the reference path. For 3.1/3.2 that adds buttons that were never rendered there before. JumpToPath is an empty extension point in core, so nothing changes unless a plugin provides it. It also needs the 3.1/3.2 keywords (prefixItems, patternProperties, $defs, …) mapped to spec paths.
Alternative: 2.0/3.0 now, which is parity, and 3.1/3.2 later together with the nested ref names (FOLLOW-UPS 14).
Should we handle JumpToPath for nested references?
The reason will be displayed to describe this comment to others. Learn more.
this something I was thinking about as well 😅 (src/core/plugins/json-schema-unified/SPEC.md:123-124)
tbh I have no data for this feature being valuable as we haven't got any requests for adding jump to button for OAS 3.1/OAS 3.2 schemas therefore I've decided to not include this feature in unified view
we could have it in follow-ups to have a trace of this decision
.claude/skills/FOLLOW-UPS.md)
17.**Optional, only on client request: the unified schema view has no `JumpToPath` on nested `$ref`
schemas.** Only each Schemas-section panel carries it (`json-schema-unified/components/Models/SchemaItem.tsx`).
json-schema-5 also puts it on every nested `$ref` object (`json-schema-5/components/object-model.jsx`),
with the usage-site spec path (`properties,<key>`, `additionalProperties`, `allOf,<i>`, ...); the
3.1/3.2 renderers never had it. Core `JumpToPath` renders nothing, so only plugins that override
it notice (SwaggerEditor jumps to the line). No community request so far (swagger-ui #9380 is
maintainer-filed). If a client asks:
- A plugin can already add it without changes here: wrap `JSONSchemaUnified` and pass its
`jumpToPath` prop for a schema with a local `$$ref`/`$ref`, pointing at the referenced
definition. Document that prop as an extension point first.
- The usage-site path needs per-keyword spec-path tracking in the unified renderer (it only tracks
an expansion path), shared by all four dialects, plus 3.1/3.2 keywords (`prefixItems`,
`patternProperties`, `$defs`, ...).
- The `jumpToPath` slot is styled for the panel's top-right corner; nested schemas may need a
title-row slot.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
External references can incorrectly resolve to unrelated local schemas, and referenced properties can bypass annotation filtering, leaving read-only properties in requests and write-only properties in responses.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Alias-chain expansion and __proto__ merging can hide schema properties, while reference tooltips remain inaccessible to keyboard and screen-reader users.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Reference merging can silently discard overlapping allOf constraints, and unresolved regressions also affect schema expansion state and tooltip accessibility.
Overlapping arrays other than required are replaced here, unlike the classic renderer's refSchema.mergeDeep(schema) (json-schema-5/components/model.jsx:77-80), which concatenates lists. For example, if a leftover $ref and its definition both contain allOf, mergeLazyRef({allOf: [A]}, {$ref: "…", allOf: [B]}) returns only [B], silently dropping A's constraints. OAS 3.0.4 describes these definitions as “validated independently but together compose a single object.” Preserve the classic list-merge behavior and add a regression case with overlapping combiner arrays.
Schema expansion state is not read or synchronized
With default depth settings, layoutActions.show(["components", "schemas", "Pet"], true) no longer expands Pet in the unified 3.0 view; the same regression affects ["definitions", "Pet"] in 2.0. SchemaItem writes layout state on clicks but never reads it, so both existing per-schema state and later external expand/collapse actions are ignored. Feed the per-schema isShown value into the unified expansion state and keep it synchronized with user toggles.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The schema-resolution effect omits schema from its dependencies, leaving external references unresolved after an open model is edited until it is collapsed and reopened.
No ref-derived names for nested schemas in OAS 3.1/3.2, the reference
path shown inline instead of as the json-schema-5 tooltip, and the
ignored document part of an unresolved 2.0/3.0 local ref.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Reverts the revert of "ui improvements for jump to and references":
the reference path tooltip (shown through the title toggle's peer
variants) and the jump-to button at the top right of the panel.
The isolation test keeps its current selector check.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A schema from a `$ref` is named after what follows `#/definitions/` or
`#/components/schemas/`, so `#/definitions/A/properties/b` is `A/properties/b`
and not `b`. A reference that points elsewhere gets no name. This matches the
3.1/3.2 title and json-schema-5. Both prefixes apply in both dialects.
Also track two follow-ups in FOLLOW-UPS.md: nested `JumpToPath` for `$ref`
schemas, and the core `findDefinition` bug with the oas3 plugin on 2.0.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Export the `System` interface of the json-schema-document selectors, so the
plugin's declaration can name it (TS4023). Type the DOM nodes the unified
schema tests read: `getDOMNode()` is `any` without enzyme types, which made
`Array.from` yield `unknown`. Cast the 2.0/3.0 boolean bounds to `Schema`.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Filter a property by the readOnly/writeOnly of the definition its `$ref`
points to when the resolver left the reference in place, unless the
reference sets the keyword itself.
- Do not repeat a title next to a member of allOf, oneOf, anyOf or
prefixItems: its name already holds it (`#0 Base`).
- Track in FOLLOW-UPS that the 2.0/3.0 `not` label copies the 3.1 one
(item 13), why a lookup by document URL is not trivial (item 16) and
that `nullable` is shown without an explicit `type` (item 19).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…alects
- Describe the title button of a dereferenced schema by its reference
path tooltip: the tooltip gets an id built from the schema's encoded
path, and the button an `aria-describedby` pointing at it.
- Keep a `__proto__` property when a reference's siblings are merged over
its definition, by merging into a prototype-free object.
- Say in the README that `npm run e2e` needs WebKit as well as Chromium.
- Name the 2.0 keyword test after what it asserts (no `nullable`).
- Track in FOLLOW-UPS that a reference to an alias schema shows a
reference row in an operation's Schema tab (item 20).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ection
A schema of the Schemas section now expands or collapses when
`layoutActions.show` stores a value for its key (`["definitions", name]` in
2.0, `["components", "schemas", name]` in 3.x), as json-schema-5 does. The
layout state is read for the root of each item; when nothing is stored the
depth settings still decide. A schema shown this way requests its resolved
subtree like a click does.
The element of each schema gets the id `model-<name>`, as the one of
json-schema-5's model item.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Editing the spec clears the resolved subtrees, and the schema of the
Schemas section is replaced by the raw one. The effect that asks for the
subtree of a shown schema did not depend on the schema, so an open schema
kept its references unresolved (`$ref` rows) until it was closed and
opened again. It now runs when its schema changes too, and asks only when
the schema is shown and not resolved.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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
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
This PR extends the opt-in unified JSON Schema view (
unifiedJSONSchemaEnabled) to OpenAPI 2.0 and 3.0. With the option on, every OpenAPI version now renders its Schemas/Models section and Schema tab throughjson-schema-unified. With it off, nothing changes.oas30andswagger2, each with its own keyword list. Every keyword keeps the meaning it has in that version:exclusiveMaximum/exclusiveMinimumcombined withmaximum/minimumread as< 10,> 0,(1, 10].nullable: truereads asT | null. 3.0 keepsoneOf/anyOf/not,writeOnly,deprecatedand the objectdiscriminator.discriminator,allOfas its only combiner, andtype: file.const,$defs) are treated like any unknown keyword: shown only withshowExtensions. json-schema-5 showed them as plain rows; this change was confirmed.writeOnlystill hides properties from 2.0 response schemas, as json-schema-5 does (confirmed), but it isn't rendered as a 2.0 keyword.itemsshows the nested schema's name, itstitleor else its reference name (category Category), as json-schema-5 does.#/definitions/Category.$refs in place. The plugin looks the definition up by local name (resolved subtree first, else raw JSON, likefindDefinition) only when the schema renders, so recursion goes only as deep as the user expands. "Expand all" stops at a reference already resolved higher up the same branch.definitionswith the heading "Models"; 3.0 usescomponents/schemaswith "Schemas". The layout, scroll and lazy-resolve keys are identical to json-schema-5's, so deep links and expansion state behave the same.unified-json-schemaPlaywright project now covers all four versions (103 tests). Its guard also recognises the json-schema-5 DOM as classic.webkit-unifiedproject runs the plugin's own specs in WebKit, for the Tailwind v4 browser floor (Safari 16.4).nodejs.ymlandrelease-swagger-ui.ymlnow installchromium webkit, and the browser cache key includes WebKit. Still 4 shards.configuration.md, React README,architecture,json-schema.json-schema-unifiedspec gets a 2.0/3.0 dialects section.oas-versionsspec records a known limitation: the oas31/oas32Model/Modelswrappers cache their instance on a static field keyed bylocation.pathname. This is inferred from the code and not yet reproduced; it will be fixed separately.CLAUDE.mdlists the Playwright projects.Motivation and Context
This completes "one schema UI for every OpenAPI version" behind the opt-in flag, which is the path to retiring json-schema-5's model views. Example values, parameter input widgets and the 2.0 scheme picker remain out of scope. With the option on, the Schema tab can therefore disagree with Example Value for 2.0/3.0; this is recorded as a known limitation in the module spec.
Points to review closely:
$refresolution (legacy.ts#getLazyRef,hooks.ts);How Has This Been Tested?
The tree of this PR is identical to the fully verified final tree.
npm run test:unit→ 1066 passed, 12 skipped. This includes 157 plugin tests, covering per-dialect keyword lists, the text of exclusive bounds, nullable, 2.0 discriminator andtype: file, nested names with pointer decoding, the reference path for 2.0/3.0 only, 3.1 naming unchanged, recursive models, and readOnly/writeOnly for 2.0/3.0.chromium:npx playwright test --project=chromium→ 705 passed, 4 skipped. This includes new 2.0/3.0 plugin specs: Models vs Schemas heading, nested name and reference path, exclusive bounds, nullable, discriminator, a recursive model expanded two levels, the Schema tab, and readOnly/writeOnly request→response.npx playwright test --project=unified-json-schema→ 103 passed. It re-runs existing schema specs for 2.0, 3.0, 3.1 and 3.2 with the option on.object | null;deprecatedis a chip, and in 2.0 it's hidden as a non-2.0 field;oas3-extensionopens its extension blocks first;tagsinstead ofid;editor-1868became stricter.=false.npx playwright test --project=webkit-unified→ 52 passed.npm run build+npm run test:artifact→ 8 passed.lint-errors,tsc,e2e:typecheckare clean.check-plugin-conventions→ 0 errors.Screenshots (if appropriate):
All captures use this PR's build and the e2e fixtures under
test/e2e-playwright/static/documents/features/json-schema-unified/. Before is the classic json-schema-5 view (option off, same as the base); after isunifiedJSONSchemaEnabled=true. Each capture checks thatwindow.ui.getConfigs().unifiedJSONSchemaEnabledreally had the expected value.OpenAPI 2.0 Models section (
Petexpanded)After, the view shows constraint chips (
[0, 30],> 0,(1, 10]), the read-only marker, the nested schema name (category Category), the 2.0 string discriminator, XML and external docs.OpenAPI 3.0 Schemas section (
Petexpanded)OpenAPI 3.0 Schema tab (request body of
createUser)After, the tab shows the reference path
#/components/schemas/Userand thewrite-onlymarker; the readOnlyidis hidden in the request schema.Dark mode (2.0, unified)
Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests