feat(json-schema-2020-12): add support for dependentSchemas keyword
Refs #8513
This commit is contained in:
committed by
Vladimír Gorej
parent
503aa19f36
commit
a8e351f462
@@ -48,6 +48,7 @@ const JSONSchema = ({ schema, name }) => {
|
|||||||
const KeywordIf = useComponent("KeywordIf")
|
const KeywordIf = useComponent("KeywordIf")
|
||||||
const KeywordThen = useComponent("KeywordThen")
|
const KeywordThen = useComponent("KeywordThen")
|
||||||
const KeywordElse = useComponent("KeywordElse")
|
const KeywordElse = useComponent("KeywordElse")
|
||||||
|
const KeywordDependentSchemas = useComponent("KeywordDependentSchemas")
|
||||||
const KeywordProperties = useComponent("KeywordProperties")
|
const KeywordProperties = useComponent("KeywordProperties")
|
||||||
const KeywordType = useComponent("KeywordType")
|
const KeywordType = useComponent("KeywordType")
|
||||||
const KeywordFormat = useComponent("KeywordFormat")
|
const KeywordFormat = useComponent("KeywordFormat")
|
||||||
@@ -119,6 +120,7 @@ const JSONSchema = ({ schema, name }) => {
|
|||||||
<KeywordIf schema={schema} />
|
<KeywordIf schema={schema} />
|
||||||
<KeywordThen schema={schema} />
|
<KeywordThen schema={schema} />
|
||||||
<KeywordElse schema={schema} />
|
<KeywordElse schema={schema} />
|
||||||
|
<KeywordDependentSchemas schema={schema} />
|
||||||
<Keyword$schema schema={schema} />
|
<Keyword$schema schema={schema} />
|
||||||
<Keyword$vocabulary schema={schema} />
|
<Keyword$vocabulary schema={schema} />
|
||||||
<Keyword$id schema={schema} />
|
<Keyword$id schema={schema} />
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
@import './keywords/If/if';
|
@import './keywords/If/if';
|
||||||
@import './keywords/Then/then';
|
@import './keywords/Then/then';
|
||||||
@import './keywords/Else/else';
|
@import './keywords/Else/else';
|
||||||
|
@import './keywords/DependentSchemas/dependent-schemas';
|
||||||
@import './keywords/Type/type';
|
@import './keywords/Type/type';
|
||||||
@import './keywords/Format/format';
|
@import './keywords/Format/format';
|
||||||
@import './keywords/Description/description';
|
@import './keywords/Description/description';
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const AllOf = ({ schema }) => {
|
|||||||
<div className="json-schema-2020-12__allOf">
|
<div className="json-schema-2020-12__allOf">
|
||||||
<Accordion expanded={expanded} onChange={handleExpansion}>
|
<Accordion expanded={expanded} onChange={handleExpansion}>
|
||||||
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--allOf">
|
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--allOf">
|
||||||
AllOf
|
All of
|
||||||
</span>
|
</span>
|
||||||
<span className="json-schema-2020-12__type">
|
<span className="json-schema-2020-12__type">
|
||||||
{fn.getType({ allOf })}
|
{fn.getType({ allOf })}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const AnyOf = ({ schema }) => {
|
|||||||
<div className="json-schema-2020-12__anyOf">
|
<div className="json-schema-2020-12__anyOf">
|
||||||
<Accordion expanded={expanded} onChange={handleExpansion}>
|
<Accordion expanded={expanded} onChange={handleExpansion}>
|
||||||
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--anyOf">
|
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--anyOf">
|
||||||
AnyOf
|
Any of
|
||||||
</span>
|
</span>
|
||||||
<span className="json-schema-2020-12__type">
|
<span className="json-schema-2020-12__type">
|
||||||
{fn.getType({ anyOf })}
|
{fn.getType({ anyOf })}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
import React, { useCallback, useState } from "react"
|
||||||
|
|
||||||
|
import { schema } from "../../../prop-types"
|
||||||
|
import { useComponent, useIsExpandedDeeply } from "../../../hooks"
|
||||||
|
|
||||||
|
const DependentSchemas = ({ schema }) => {
|
||||||
|
const dependentSchemas = schema?.dependentSchemas || []
|
||||||
|
|
||||||
|
if (typeof dependentSchemas !== "object") return null
|
||||||
|
if (Object.keys(dependentSchemas).length === 0) return null
|
||||||
|
|
||||||
|
const isExpandedDeeply = useIsExpandedDeeply()
|
||||||
|
const [expanded, setExpanded] = useState(isExpandedDeeply)
|
||||||
|
const Accordion = useComponent("Accordion")
|
||||||
|
const JSONSchema = useComponent("JSONSchema")
|
||||||
|
|
||||||
|
const handleExpansion = useCallback(() => {
|
||||||
|
setExpanded((prev) => !prev)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="json-schema-2020-12__dependentSchemas">
|
||||||
|
<Accordion expanded={expanded} onChange={handleExpansion}>
|
||||||
|
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--dependentSchemas">
|
||||||
|
Dependent schemas
|
||||||
|
</span>
|
||||||
|
<span className="json-schema-2020-12__type">object</span>
|
||||||
|
</Accordion>
|
||||||
|
{expanded && (
|
||||||
|
<ul>
|
||||||
|
{Object.entries(dependentSchemas).map(([schemaName, schema]) => (
|
||||||
|
<li key={schemaName} className="json-schema-2020-12-property">
|
||||||
|
<JSONSchema name={schemaName} schema={schema} />
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
DependentSchemas.propTypes = {
|
||||||
|
schema: schema.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DependentSchemas
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
.json-schema-2020-12 {
|
||||||
|
&__dependentSchemas {
|
||||||
|
@extend .json-schema-2020-12__allOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-core-keyword {
|
||||||
|
&--dependentSchemas {
|
||||||
|
@extend .json-schema-2020-12-core-keyword--allOf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ const OneOf = ({ schema }) => {
|
|||||||
<div className="json-schema-2020-12__oneOf">
|
<div className="json-schema-2020-12__oneOf">
|
||||||
<Accordion expanded={expanded} onChange={handleExpansion}>
|
<Accordion expanded={expanded} onChange={handleExpansion}>
|
||||||
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--oneOf">
|
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--oneOf">
|
||||||
OneOf
|
One of
|
||||||
</span>
|
</span>
|
||||||
<span className="json-schema-2020-12__type">
|
<span className="json-schema-2020-12__type">
|
||||||
{fn.getType({ oneOf })}
|
{fn.getType({ oneOf })}
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ export const isExpandable = (schema) => {
|
|||||||
schema?.if ||
|
schema?.if ||
|
||||||
schema?.then ||
|
schema?.then ||
|
||||||
schema?.else ||
|
schema?.else ||
|
||||||
|
schema?.dependentSchemas ||
|
||||||
schema?.description ||
|
schema?.description ||
|
||||||
schema?.properties
|
schema?.properties
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import KeywordNot from "./components/keywords/Not/Not"
|
|||||||
import KeywordIf from "./components/keywords/If/If"
|
import KeywordIf from "./components/keywords/If/If"
|
||||||
import KeywordThen from "./components/keywords/Then/Then"
|
import KeywordThen from "./components/keywords/Then/Then"
|
||||||
import KeywordElse from "./components/keywords/Else/Else"
|
import KeywordElse from "./components/keywords/Else/Else"
|
||||||
|
import KeywordDependentSchemas from "./components/keywords/DependentSchemas/DependentSchemas"
|
||||||
import KeywordProperties from "./components/keywords/Properties/Properties"
|
import KeywordProperties from "./components/keywords/Properties/Properties"
|
||||||
import KeywordType from "./components/keywords/Type/Type"
|
import KeywordType from "./components/keywords/Type/Type"
|
||||||
import KeywordFormat from "./components/keywords/Format/Format"
|
import KeywordFormat from "./components/keywords/Format/Format"
|
||||||
@@ -57,6 +58,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
|
|||||||
KeywordIf,
|
KeywordIf,
|
||||||
KeywordThen,
|
KeywordThen,
|
||||||
KeywordElse,
|
KeywordElse,
|
||||||
|
KeywordDependentSchemas,
|
||||||
KeywordProperties,
|
KeywordProperties,
|
||||||
KeywordType,
|
KeywordType,
|
||||||
KeywordFormat,
|
KeywordFormat,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import KeywordNot from "./components/keywords/Not/Not"
|
|||||||
import KeywordIf from "./components/keywords/If/If"
|
import KeywordIf from "./components/keywords/If/If"
|
||||||
import KeywordThen from "./components/keywords/Then/Then"
|
import KeywordThen from "./components/keywords/Then/Then"
|
||||||
import KeywordElse from "./components/keywords/Else/Else"
|
import KeywordElse from "./components/keywords/Else/Else"
|
||||||
|
import KeywordDependentSchemas from "./components/keywords/DependentSchemas/DependentSchemas"
|
||||||
import KeywordType from "./components/keywords/Type/Type"
|
import KeywordType from "./components/keywords/Type/Type"
|
||||||
import KeywordFormat from "./components/keywords/Format/Format"
|
import KeywordFormat from "./components/keywords/Format/Format"
|
||||||
import KeywordTitle from "./components/keywords/Title/Title"
|
import KeywordTitle from "./components/keywords/Title/Title"
|
||||||
@@ -48,6 +49,7 @@ const JSONSchema202012Plugin = () => ({
|
|||||||
JSONSchema202012KeywordIf: KeywordIf,
|
JSONSchema202012KeywordIf: KeywordIf,
|
||||||
JSONSchema202012KeywordThen: KeywordThen,
|
JSONSchema202012KeywordThen: KeywordThen,
|
||||||
JSONSchema202012KeywordElse: KeywordElse,
|
JSONSchema202012KeywordElse: KeywordElse,
|
||||||
|
JSONSchema202012KeywordDependentSchemas: KeywordDependentSchemas,
|
||||||
JSONSchema202012KeywordProperties: KeywordProperties,
|
JSONSchema202012KeywordProperties: KeywordProperties,
|
||||||
JSONSchema202012KeywordType: KeywordType,
|
JSONSchema202012KeywordType: KeywordType,
|
||||||
JSONSchema202012KeywordFormat: KeywordFormat,
|
JSONSchema202012KeywordFormat: KeywordFormat,
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
|||||||
const KeywordIf = getComponent("JSONSchema202012KeywordIf")
|
const KeywordIf = getComponent("JSONSchema202012KeywordIf")
|
||||||
const KeywordThen = getComponent("JSONSchema202012KeywordThen")
|
const KeywordThen = getComponent("JSONSchema202012KeywordThen")
|
||||||
const KeywordElse = getComponent("JSONSchema202012KeywordElse")
|
const KeywordElse = getComponent("JSONSchema202012KeywordElse")
|
||||||
|
const KeywordDependentSchemas = getComponent(
|
||||||
|
"JSONSchema202012KeywordDependentSchemas"
|
||||||
|
)
|
||||||
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
|
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
|
||||||
const KeywordType = getComponent("JSONSchema202012KeywordType")
|
const KeywordType = getComponent("JSONSchema202012KeywordType")
|
||||||
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
|
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
|
||||||
@@ -62,6 +65,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
|||||||
KeywordIf,
|
KeywordIf,
|
||||||
KeywordThen,
|
KeywordThen,
|
||||||
KeywordElse,
|
KeywordElse,
|
||||||
|
KeywordDependentSchemas,
|
||||||
KeywordProperties,
|
KeywordProperties,
|
||||||
KeywordType,
|
KeywordType,
|
||||||
KeywordFormat,
|
KeywordFormat,
|
||||||
|
|||||||
Reference in New Issue
Block a user