fix(json-schema-2020-12): render property schema title - #11062
Open
joshuablac wants to merge 1 commit into
Open
joshuablac wants to merge 1 commit into
joshuablac wants to merge 1 commit into
Conversation
What was wrong: When an API describes a field and gives it a friendly name (a "title"), for example a field called "nickname" titled "Pet nickname", Swagger UI showed only "nickname" for OpenAPI 3.1 documents. The friendly name was silently thrown away. What this changes: Swagger UI now shows the friendly name in italics next to the field name, e.g. "nickname Pet nickname". If the friendly name is just the field name again (like "color" titled "color"), it is not repeated. Also adds automated tests that check both cases. Fixes swagger-api#11053 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the stated behavior and includes focused regression coverage.
Review effort: Lite
Findings: None
What changed in this PR
Fixes OpenAPI 3.1 property-schema title rendering while preserving property names as primary labels.
Changes:
- Adds secondary schema titles with duplicate suppression.
- Adds styling for secondary labels.
- Adds fixture data and Cypress coverage.
| File | Description |
|---|---|
Title.jsx |
Renders explicit schema titles beside primary labels. |
_title.scss |
Styles secondary titles. |
schema-title.cy.js |
Tests rendering and deduplication. |
json-schema-2020-12-title.yaml |
Adds titled properties to the fixture. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
In OpenAPI 3.1 / JSON Schema 2020-12 rendering, a
titleset on a property schema was never shown.Propertiesrenders each property throughJSONSchemawithname={propertyName}.JSONSchemathen passes that name as thetitleprop ofKeywordTitle.Titlerenderedtitle || fn.getTitle(schema), so the property key always won and the schema's owntitlewas dropped.This PR keeps the property key as the primary label. When the schema has its own
title,Titlealso renders it next to the key as a secondary label (json-schema-2020-12__title-secondary, normal weight, italic).getTitle(schema, { lookup: "basic" }). This means only a realtitlekeyword is shown, never$anchor/$idfallbacks.#0 Cat, and properties whose title just repeats the key (colorwithtitle: color, whichgetTitlewould upper-case toColor).Behavior note: a
$ref'd schema that has atitleand is rendered under its component key (e.g. a request/response body referencing#/components/schemas/Petwithtitle: My Pet) now showsPetfollowed byMy Pet. Previously only the key was shown.Motivation and Context
Fixes #11053
How Has This Been Tested?
schema-title.cy.js, plusnickname(title: Pet nickname) andcolor(title: color) properties to its fixture.main(Expected to find content: 'Pet nickname') and passes with this change.colorgets no repeated secondary label.features/plugins/json-schema-2020-12,oas31andoas32locally: 17 specs, 88 tests, all passing.npm run lint-errorspasses,stylelintpasses on the changed SCSS, andnpm run buildsucceeds.npm run test:unit: the only failures are 18 tests intest/unit/core/utils.js(Cannot delete property 'location' of #<Window>). They fail identically without this change. The cause is my local Node/jsdom version, not this PR.Screenshots (if appropriate):
Fixture
json-schema-2020-12-title.yaml, modelPetexpanded (before / after):Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests
🤖 Generated with Claude Code