Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ import { useFn } from "../../../hooks"

const Title = ({ title = "", schema }) => {
const fn = useFn()
const schemaTitle = fn.getTitle(schema, { lookup: "basic" })
const renderedTitle = title || fn.getTitle(schema)
const hasSecondaryTitle =
typeof title === "string" &&
title !== "" &&
schemaTitle !== "" &&
!title.toLowerCase().includes(schemaTitle.toLowerCase())

if (!renderedTitle) return null

return <strong className="json-schema-2020-12__title">{renderedTitle}</strong>
return (
<strong className="json-schema-2020-12__title">
{renderedTitle}
{hasSecondaryTitle && (
<span className="json-schema-2020-12__title-secondary">
{schemaTitle}
</span>
)}
</strong>
)
}

Title.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
& .json-schema-2020-12-keyword__name {
margin: 0;
}

&-secondary {
margin-left: 10px;
font-weight: normal;
font-style: italic;
}
}

&-property {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ describe("JSON Schema 2020-12 title keyword", () => {
.contains("Error")
.should("exist")
})

it("should render a title for schema properties", () => {
cy.visit(
"/?url=/documents/features/json-schema-2020-12-title.yaml&defaultModelsExpandDepth=2"
)
.get(".json-schema-2020-12-property")
.contains(".json-schema-2020-12__title", "nickname")
.contains("Pet nickname")
.should("exist")
})

it("should not repeat a property title that matches the property name", () => {
cy.visit(
"/?url=/documents/features/json-schema-2020-12-title.yaml&defaultModelsExpandDepth=2"
)
.get(".json-schema-2020-12-property")
.contains(".json-schema-2020-12__title", "color")
.find(".json-schema-2020-12__title-secondary")
.should("not.exist")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ components:
type: string
tag:
type: string
nickname:
type: string
title: Pet nickname
color:
type: string
title: color
Pets:
title: My Pets
type: array
Expand Down