fix(oas31): fix extendable behavior in OpenAPI 3.1 base dialect keywords (#8660)

This change is related to JSON Schema 2020-12.

Refs #8513
This commit is contained in:
Vladimír Gorej
2023-05-12 13:01:31 +02:00
committed by GitHub
parent 01d2376b5f
commit 36148cbb50
3 changed files with 46 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ const Discriminator = ({ schema, getSystem }) => {
const { fn, getComponent } = getSystem() const { fn, getComponent } = getSystem()
const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012 const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012
const isExpandedDeeply = useIsExpandedDeeply() const isExpandedDeeply = useIsExpandedDeeply()
const isExpandable = !!discriminator.mapping
const [expanded, setExpanded] = useState(isExpandedDeeply) const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false) const [expandedDeeply, setExpandedDeeply] = useState(false)
const Accordion = useComponent("Accordion") const Accordion = useComponent("Accordion")
@@ -41,12 +42,24 @@ const Discriminator = ({ schema, getSystem }) => {
return ( return (
<JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}> <JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}>
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--discriminator"> <div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--discriminator">
<Accordion expanded={expanded} onChange={handleExpansion}> {isExpandable ? (
<>
<Accordion expanded={expanded} onChange={handleExpansion}>
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary">
Discriminator
</span>
</Accordion>
<ExpandDeepButton
expanded={expanded}
onClick={handleExpansionDeep}
/>
</>
) : (
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary"> <span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary">
Discriminator Discriminator
</span> </span>
</Accordion> )}
<ExpandDeepButton expanded={expanded} onClick={handleExpansionDeep} />
{discriminator.propertyName && ( {discriminator.propertyName && (
<span className="json-schema-2020-12__attribute json-schema-2020-12__attribute--muted"> <span className="json-schema-2020-12__attribute json-schema-2020-12__attribute--muted">
{discriminator.propertyName} {discriminator.propertyName}

View File

@@ -12,6 +12,7 @@ const ExternalDocs = ({ schema, getSystem }) => {
const { fn, getComponent } = getSystem() const { fn, getComponent } = getSystem()
const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012 const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012
const isExpandedDeeply = useIsExpandedDeeply() const isExpandedDeeply = useIsExpandedDeeply()
const isExpandable = !!(externalDocs.description || externalDocs.url)
const [expanded, setExpanded] = useState(isExpandedDeeply) const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false) const [expandedDeeply, setExpandedDeeply] = useState(false)
const Accordion = useComponent("Accordion") const Accordion = useComponent("Accordion")
@@ -43,12 +44,23 @@ const ExternalDocs = ({ schema, getSystem }) => {
return ( return (
<JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}> <JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}>
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--externalDocs"> <div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--externalDocs">
<Accordion expanded={expanded} onChange={handleExpansion}> {isExpandable ? (
<>
<Accordion expanded={expanded} onChange={handleExpansion}>
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary">
External documentation
</span>
</Accordion>
<ExpandDeepButton
expanded={expanded}
onClick={handleExpansionDeep}
/>
</>
) : (
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary"> <span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary">
External documentation External documentation
</span> </span>
</Accordion> )}
<ExpandDeepButton expanded={expanded} onClick={handleExpansionDeep} />
<strong className="json-schema-2020-12__attribute json-schema-2020-12__attribute--primary"> <strong className="json-schema-2020-12__attribute json-schema-2020-12__attribute--primary">
object object
</strong> </strong>

View File

@@ -10,6 +10,7 @@ const Xml = ({ schema, getSystem }) => {
const { fn, getComponent } = getSystem() const { fn, getComponent } = getSystem()
const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012 const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012
const isExpandedDeeply = useIsExpandedDeeply() const isExpandedDeeply = useIsExpandedDeeply()
const isExpandable = !!(xml.name || xml.namespace || xml.prefix)
const [expanded, setExpanded] = useState(isExpandedDeeply) const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false) const [expandedDeeply, setExpandedDeeply] = useState(false)
const Accordion = useComponent("Accordion") const Accordion = useComponent("Accordion")
@@ -39,12 +40,23 @@ const Xml = ({ schema, getSystem }) => {
return ( return (
<JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}> <JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}>
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--xml"> <div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--xml">
<Accordion expanded={expanded} onChange={handleExpansion}> {isExpandable ? (
<>
<Accordion expanded={expanded} onChange={handleExpansion}>
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary">
XML
</span>
</Accordion>
<ExpandDeepButton
expanded={expanded}
onClick={handleExpansionDeep}
/>
</>
) : (
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary"> <span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--secondary">
XML XML
</span> </span>
</Accordion> )}
<ExpandDeepButton expanded={expanded} onClick={handleExpansionDeep} />
{xml.attribute === true && ( {xml.attribute === true && (
<span className="json-schema-2020-12__attribute json-schema-2020-12__attribute--muted"> <span className="json-schema-2020-12__attribute json-schema-2020-12__attribute--muted">
attribute attribute