feat(json-schema-2020-12): add support for allOf keyword

Refs #8513
This commit is contained in:
Vladimir Gorej
2023-04-20 15:04:46 +02:00
committed by Vladimír Gorej
parent 2f08f6424b
commit 4ea28a9310
8 changed files with 87 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ const JSONSchema = ({ schema, name }) => {
const Keyword$dynamicRef = useComponent("Keyword$dynamicRef") const Keyword$dynamicRef = useComponent("Keyword$dynamicRef")
const Keyword$defs = useComponent("Keyword$defs") const Keyword$defs = useComponent("Keyword$defs")
const Keyword$comment = useComponent("Keyword$comment") const Keyword$comment = useComponent("Keyword$comment")
const KeywordAllOf = useComponent("KeywordAllOf")
const KeywordProperties = useComponent("KeywordProperties") const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType") const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat") const KeywordFormat = useComponent("KeywordFormat")
@@ -104,14 +105,17 @@ const JSONSchema = ({ schema, name }) => {
{!isCircular && isExpandable && ( {!isCircular && isExpandable && (
<KeywordProperties schema={schema} /> <KeywordProperties schema={schema} />
)} )}
<KeywordAllOf 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} />
<Keyword$anchor schema={schema} /> <Keyword$anchor schema={schema} />
<Keyword$dynamicAnchor schema={schema} /> <Keyword$dynamicAnchor schema={schema} />
<Keyword$ref schema={schema} /> <Keyword$ref schema={schema} />
{!isCircular && isExpandable && (
<Keyword$defs schema={schema} />
)}
<Keyword$dynamicRef schema={schema} /> <Keyword$dynamicRef schema={schema} />
<Keyword$defs schema={schema} />
<Keyword$comment schema={schema} /> <Keyword$comment schema={schema} />
</div> </div>
)} )}

View File

@@ -3,6 +3,7 @@
@import './ExpandDeepButton/expand-deep-button'; @import './ExpandDeepButton/expand-deep-button';
@import './keywords/$vocabulary/$vocabulary'; @import './keywords/$vocabulary/$vocabulary';
@import './keywords/$defs/$defs'; @import './keywords/$defs/$defs';
@import './keywords/AllOf/all-of';
@import './keywords/Type/type'; @import './keywords/Type/type';
@import './keywords/Format/format'; @import './keywords/Format/format';
@import './keywords/Description/description'; @import './keywords/Description/description';

View File

@@ -0,0 +1,56 @@
/**
* @prettier
*/
import React, { useCallback, useState } from "react"
import { schema } from "../../../prop-types"
import { useFn, useComponent, useIsExpandedDeeply } from "../../../hooks"
const AllOf = ({ schema }) => {
const allOf = schema?.allOf || []
if (!Array.isArray(allOf) || allOf.length === 0) {
return null
}
const fn = useFn()
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__allOf">
<Accordion expanded={expanded} onChange={handleExpansion}>
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--allOf">
AllOf
</span>
<span className="json-schema-2020-12__type">
{fn.getType({ allOf })}
</span>
</Accordion>
{expanded && (
<ul>
{allOf.map((schema, index) => (
<li key={`#${index}`} className="json-schema-2020-12-property">
<JSONSchema
name={`#${index} ${fn.getTitle(schema)}`}
schema={schema}
/>
</li>
))}
</ul>
)}
</div>
)
}
AllOf.propTypes = {
schema: schema.isRequired,
}
export default AllOf

View File

@@ -0,0 +1,18 @@
.json-schema-2020-12 {
&__allOf {
& ul {
padding: 0;
margin: 0 0 0 20px;
border-left: 1px dashed rgba($section-models-model-container-background-color, 0.1);
}
}
&-core-keyword {
&--allOf {
color: $text-code-default-font-color;
font-style: normal;
}
}
}

View File

@@ -122,6 +122,7 @@ export const isExpandable = (schema) => {
schema?.$dynamicRef || schema?.$dynamicRef ||
schema?.$defs || schema?.$defs ||
schema?.$comment || schema?.$comment ||
schema?.allOf ||
schema?.description || schema?.description ||
schema?.properties schema?.properties
) )

View File

@@ -13,6 +13,7 @@ import Keyword$ref from "./components/keywords/$ref"
import Keyword$dynamicRef from "./components/keywords/$dynamicRef" import Keyword$dynamicRef from "./components/keywords/$dynamicRef"
import Keyword$defs from "./components/keywords/$defs/$defs" import Keyword$defs from "./components/keywords/$defs/$defs"
import Keyword$comment from "./components/keywords/$comment" import Keyword$comment from "./components/keywords/$comment"
import KeywordAllOf from "./components/keywords/AllOf/AllOf"
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"
@@ -43,6 +44,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
Keyword$dynamicRef, Keyword$dynamicRef,
Keyword$defs, Keyword$defs,
Keyword$comment, Keyword$comment,
KeywordAllOf,
KeywordProperties, KeywordProperties,
KeywordType, KeywordType,
KeywordFormat, KeywordFormat,

View File

@@ -12,6 +12,7 @@ import Keyword$ref from "./components/keywords/$ref"
import Keyword$dynamicRef from "./components/keywords/$dynamicRef" import Keyword$dynamicRef from "./components/keywords/$dynamicRef"
import Keyword$defs from "./components/keywords/$defs/$defs" import Keyword$defs from "./components/keywords/$defs/$defs"
import Keyword$comment from "./components/keywords/$comment" import Keyword$comment from "./components/keywords/$comment"
import KeywordAllOf from "./components/keywords/AllOf/AllOf"
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"
@@ -34,6 +35,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012Keyword$dynamicRef: Keyword$dynamicRef, JSONSchema202012Keyword$dynamicRef: Keyword$dynamicRef,
JSONSchema202012Keyword$defs: Keyword$defs, JSONSchema202012Keyword$defs: Keyword$defs,
JSONSchema202012Keyword$comment: Keyword$comment, JSONSchema202012Keyword$comment: Keyword$comment,
JSONSchema202012KeywordAllOf: KeywordAllOf,
JSONSchema202012KeywordProperties: KeywordProperties, JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat, JSONSchema202012KeywordFormat: KeywordFormat,

View File

@@ -20,6 +20,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const Keyword$dynamicRef = getComponent("JSONSchema202012Keyword$dynamicRef") const Keyword$dynamicRef = getComponent("JSONSchema202012Keyword$dynamicRef")
const Keyword$defs = getComponent("JSONSchema202012Keyword$defs") const Keyword$defs = getComponent("JSONSchema202012Keyword$defs")
const Keyword$comment = getComponent("JSONSchema202012Keyword$comment") const Keyword$comment = getComponent("JSONSchema202012Keyword$comment")
const KeywordAllOf = getComponent("JSONSchema202012KeywordAllOf")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
@@ -48,6 +49,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
Keyword$dynamicRef, Keyword$dynamicRef,
Keyword$defs, Keyword$defs,
Keyword$comment, Keyword$comment,
KeywordAllOf,
KeywordProperties, KeywordProperties,
KeywordType, KeywordType,
KeywordFormat, KeywordFormat,