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

Refs #8513
This commit is contained in:
Vladimir Gorej
2023-04-21 13:10:09 +02:00
committed by Vladimír Gorej
parent bf21a4ce3e
commit dea5dbb10e
8 changed files with 50 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ const JSONSchema = ({ schema, name }) => {
const KeywordAnyOf = useComponent("KeywordAnyOf")
const KeywordOneOf = useComponent("KeywordOneOf")
const KeywordNot = useComponent("KeywordNot")
const KeywordIf = useComponent("KeywordIf")
const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat")
@@ -113,6 +114,7 @@ const JSONSchema = ({ schema, name }) => {
<KeywordAnyOf schema={schema} />
<KeywordOneOf schema={schema} />
<KeywordNot schema={schema} />
<KeywordIf schema={schema} />
<Keyword$schema schema={schema} />
<Keyword$vocabulary schema={schema} />
<Keyword$id schema={schema} />

View File

@@ -12,6 +12,7 @@
@import './keywords/AnyOf/any-of';
@import './keywords/OneOf/one-of';
@import './keywords/Not/not';
@import './keywords/If/if';
@import './keywords/Type/type';
@import './keywords/Format/format';
@import './keywords/Description/description';

View File

@@ -0,0 +1,30 @@
/**
* @prettier
*/
import React from "react"
import { schema } from "../../../prop-types"
import { useComponent } from "../../../hooks"
const If = ({ schema }) => {
if (!schema?.if) return null
const JSONSchema = useComponent("JSONSchema")
const name = (
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--if">
If
</span>
)
return (
<div className="json-schema-2020-12__if">
<JSONSchema name={name} schema={schema.if} />
</div>
)
}
If.propTypes = {
schema: schema.isRequired,
}
export default If

View File

@@ -0,0 +1,10 @@
.json-schema-2020-12 {
&__if {
.json-schema-2020-12-core-keyword--if {
@extend .json-schema-2020-12-core-keyword--allOf;
}
}
}

View File

@@ -130,6 +130,7 @@ export const isExpandable = (schema) => {
schema?.anyOf ||
schema?.oneOf ||
schema?.not ||
schema?.if ||
schema?.description ||
schema?.properties
)

View File

@@ -17,6 +17,7 @@ import KeywordAllOf from "./components/keywords/AllOf/AllOf"
import KeywordAnyOf from "./components/keywords/AnyOf/AnyOf"
import KeywordOneOf from "./components/keywords/OneOf/OneOf"
import KeywordNot from "./components/keywords/Not/Not"
import KeywordIf from "./components/keywords/If/If"
import KeywordProperties from "./components/keywords/Properties/Properties"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
@@ -51,6 +52,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordAnyOf,
KeywordOneOf,
KeywordNot,
KeywordIf,
KeywordProperties,
KeywordType,
KeywordFormat,

View File

@@ -16,6 +16,7 @@ import KeywordAllOf from "./components/keywords/AllOf/AllOf"
import KeywordAnyOf from "./components/keywords/AnyOf/AnyOf"
import KeywordOneOf from "./components/keywords/OneOf/OneOf"
import KeywordNot from "./components/keywords/Not/Not"
import KeywordIf from "./components/keywords/If/If"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title"
@@ -42,6 +43,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordAnyOf: KeywordAnyOf,
JSONSchema202012KeywordOneOf: KeywordOneOf,
JSONSchema202012KeywordNot: KeywordNot,
JSONSchema202012KeywordIf: KeywordIf,
JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat,

View File

@@ -24,6 +24,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf")
const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf")
const KeywordNot = getComponent("JSONSchema202012KeywordNot")
const KeywordIf = getComponent("JSONSchema202012KeywordIf")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
@@ -56,6 +57,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordAnyOf,
KeywordOneOf,
KeywordNot,
KeywordIf,
KeywordProperties,
KeywordType,
KeywordFormat,