feat(json-schema-2020-12): add support for const keyword (#8622)
Refs #8513
This commit is contained in:
@@ -63,6 +63,7 @@ const JSONSchema = forwardRef(({ schema, name, onExpand }, ref) => {
|
|||||||
"KeywordUnevaluatedProperties"
|
"KeywordUnevaluatedProperties"
|
||||||
)
|
)
|
||||||
const KeywordType = useComponent("KeywordType")
|
const KeywordType = useComponent("KeywordType")
|
||||||
|
const KeywordConst = useComponent("KeywordConst")
|
||||||
const KeywordFormat = useComponent("KeywordFormat")
|
const KeywordFormat = useComponent("KeywordFormat")
|
||||||
const KeywordTitle = useComponent("KeywordTitle")
|
const KeywordTitle = useComponent("KeywordTitle")
|
||||||
const KeywordDescription = useComponent("KeywordDescription")
|
const KeywordDescription = useComponent("KeywordDescription")
|
||||||
@@ -157,6 +158,7 @@ const JSONSchema = forwardRef(({ schema, name, onExpand }, ref) => {
|
|||||||
<KeywordContains schema={schema} />
|
<KeywordContains schema={schema} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<KeywordConst 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} />
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
import React from "react"
|
||||||
|
|
||||||
|
import { schema } from "../../prop-types"
|
||||||
|
import { useFn } from "../../hooks"
|
||||||
|
|
||||||
|
const Const = ({ schema }) => {
|
||||||
|
const fn = useFn()
|
||||||
|
|
||||||
|
if (!fn.hasKeyword(schema, "const")) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--const">
|
||||||
|
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
|
||||||
|
Const
|
||||||
|
</span>
|
||||||
|
<span className="json-schema-2020-12-keyword__value json-schema-2020-12-keyword__value--const">
|
||||||
|
{fn.stringify(schema.const)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Const.propTypes = {
|
||||||
|
schema: schema.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Const
|
||||||
@@ -41,6 +41,18 @@
|
|||||||
color: #6b6b6b;
|
color: #6b6b6b;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--const {
|
||||||
|
@include text_code();
|
||||||
|
color: #6b6b6b;
|
||||||
|
font-style: normal;
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 10px;
|
||||||
|
line-height: 1.5;
|
||||||
|
padding: 1px 4px 1px 4px;
|
||||||
|
border: 1px dashed #6b6b6b;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.json-schema-2020-12-keyword__name--secondary + .json-schema-2020-12-keyword__value--secondary::before {
|
.json-schema-2020-12-keyword__name--secondary + .json-schema-2020-12-keyword__value--secondary::before {
|
||||||
|
|||||||
@@ -159,6 +159,22 @@ export const isExpandable = (schema) => {
|
|||||||
fn.hasKeyword(schema, "propertyNames") ||
|
fn.hasKeyword(schema, "propertyNames") ||
|
||||||
fn.hasKeyword(schema, "unevaluatedItems") ||
|
fn.hasKeyword(schema, "unevaluatedItems") ||
|
||||||
fn.hasKeyword(schema, "unevaluatedProperties") ||
|
fn.hasKeyword(schema, "unevaluatedProperties") ||
|
||||||
schema?.description
|
schema?.description ||
|
||||||
|
fn.hasKeyword(schema, "const")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const stringify = (value) => {
|
||||||
|
if (
|
||||||
|
value === null ||
|
||||||
|
["number", "bigint", "boolean"].includes(typeof value)
|
||||||
|
) {
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return `[${value.map(stringify).join(", ")}]`
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify(value)
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import KeywordPropertyNames from "./components/keywords/PropertyNames"
|
|||||||
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
|
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
|
||||||
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
|
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
|
||||||
import KeywordType from "./components/keywords/Type/Type"
|
import KeywordType from "./components/keywords/Type/Type"
|
||||||
|
import KeywordConst from "./components/keywords/Const"
|
||||||
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"
|
||||||
import KeywordDescription from "./components/keywords/Description/Description"
|
import KeywordDescription from "./components/keywords/Description/Description"
|
||||||
@@ -45,6 +46,7 @@ import {
|
|||||||
getType,
|
getType,
|
||||||
hasKeyword,
|
hasKeyword,
|
||||||
isExpandable,
|
isExpandable,
|
||||||
|
stringify,
|
||||||
} from "./fn"
|
} from "./fn"
|
||||||
|
|
||||||
export const withJSONSchemaContext = (Component, overrides = {}) => {
|
export const withJSONSchemaContext = (Component, overrides = {}) => {
|
||||||
@@ -78,6 +80,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
|
|||||||
KeywordUnevaluatedItems,
|
KeywordUnevaluatedItems,
|
||||||
KeywordUnevaluatedProperties,
|
KeywordUnevaluatedProperties,
|
||||||
KeywordType,
|
KeywordType,
|
||||||
|
KeywordConst,
|
||||||
KeywordFormat,
|
KeywordFormat,
|
||||||
KeywordTitle,
|
KeywordTitle,
|
||||||
KeywordDescription,
|
KeywordDescription,
|
||||||
@@ -106,6 +109,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
|
|||||||
isBooleanJSONSchema,
|
isBooleanJSONSchema,
|
||||||
hasKeyword,
|
hasKeyword,
|
||||||
isExpandable,
|
isExpandable,
|
||||||
|
stringify,
|
||||||
...overrides.fn,
|
...overrides.fn,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import KeywordPropertyNames from "./components/keywords/PropertyNames"
|
|||||||
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
|
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
|
||||||
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
|
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
|
||||||
import KeywordType from "./components/keywords/Type/Type"
|
import KeywordType from "./components/keywords/Type/Type"
|
||||||
|
import KeywordConst from "./components/keywords/Const"
|
||||||
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"
|
||||||
import KeywordDescription from "./components/keywords/Description/Description"
|
import KeywordDescription from "./components/keywords/Description/Description"
|
||||||
@@ -68,6 +69,7 @@ const JSONSchema202012Plugin = () => ({
|
|||||||
JSONSchema202012KeywordUnevaluatedItems: KeywordUnevaluatedItems,
|
JSONSchema202012KeywordUnevaluatedItems: KeywordUnevaluatedItems,
|
||||||
JSONSchema202012KeywordUnevaluatedProperties: KeywordUnevaluatedProperties,
|
JSONSchema202012KeywordUnevaluatedProperties: KeywordUnevaluatedProperties,
|
||||||
JSONSchema202012KeywordType: KeywordType,
|
JSONSchema202012KeywordType: KeywordType,
|
||||||
|
JSONSchema202012KeywordConst: KeywordConst,
|
||||||
JSONSchema202012KeywordFormat: KeywordFormat,
|
JSONSchema202012KeywordFormat: KeywordFormat,
|
||||||
JSONSchema202012KeywordTitle: KeywordTitle,
|
JSONSchema202012KeywordTitle: KeywordTitle,
|
||||||
JSONSchema202012KeywordDescription: KeywordDescription,
|
JSONSchema202012KeywordDescription: KeywordDescription,
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
|||||||
"JSONSchema202012KeywordUnevaluatedProperties"
|
"JSONSchema202012KeywordUnevaluatedProperties"
|
||||||
)
|
)
|
||||||
const KeywordType = getComponent("JSONSchema202012KeywordType")
|
const KeywordType = getComponent("JSONSchema202012KeywordType")
|
||||||
|
const KeywordConst = getComponent("JSONSchema202012KeywordConst")
|
||||||
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
|
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
|
||||||
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle")
|
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle")
|
||||||
const KeywordDescription = getComponent(
|
const KeywordDescription = getComponent(
|
||||||
@@ -101,6 +102,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
|||||||
KeywordUnevaluatedItems,
|
KeywordUnevaluatedItems,
|
||||||
KeywordUnevaluatedProperties,
|
KeywordUnevaluatedProperties,
|
||||||
KeywordType,
|
KeywordType,
|
||||||
|
KeywordConst,
|
||||||
KeywordFormat,
|
KeywordFormat,
|
||||||
KeywordTitle,
|
KeywordTitle,
|
||||||
KeywordDescription,
|
KeywordDescription,
|
||||||
|
|||||||
Reference in New Issue
Block a user