feat(json-schema-2020-12): add support for enum keyword (#8623)
Refs #8513
This commit is contained in:
@@ -63,6 +63,7 @@ const JSONSchema = forwardRef(({ schema, name, onExpand }, ref) => {
|
||||
"KeywordUnevaluatedProperties"
|
||||
)
|
||||
const KeywordType = useComponent("KeywordType")
|
||||
const KeywordEnum = useComponent("KeywordEnum")
|
||||
const KeywordConst = useComponent("KeywordConst")
|
||||
const KeywordFormat = useComponent("KeywordFormat")
|
||||
const KeywordTitle = useComponent("KeywordTitle")
|
||||
@@ -158,6 +159,7 @@ const JSONSchema = forwardRef(({ schema, name, onExpand }, ref) => {
|
||||
<KeywordContains schema={schema} />
|
||||
</>
|
||||
)}
|
||||
<KeywordEnum schema={schema} />
|
||||
<KeywordConst schema={schema} />
|
||||
<Keyword$schema schema={schema} />
|
||||
<Keyword$vocabulary schema={schema} />
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import React from "react"
|
||||
|
||||
import { schema } from "../../../prop-types"
|
||||
import { useFn } from "../../../hooks"
|
||||
|
||||
const Enum = ({ schema }) => {
|
||||
const fn = useFn()
|
||||
|
||||
if (!Array.isArray(schema?.enum)) return null
|
||||
|
||||
return (
|
||||
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--enum">
|
||||
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
|
||||
Allowed values
|
||||
</span>
|
||||
<ul>
|
||||
{schema.enum.map((element) => {
|
||||
const strigifiedElement = fn.stringify(element)
|
||||
|
||||
return (
|
||||
<li key={strigifiedElement}>
|
||||
<span className="json-schema-2020-12-keyword__value json-schema-2020-12-keyword__value--const">
|
||||
{strigifiedElement}
|
||||
</span>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Enum.propTypes = {
|
||||
schema: schema.isRequired,
|
||||
}
|
||||
|
||||
export default Enum
|
||||
@@ -0,0 +1,12 @@
|
||||
.json-schema-2020-12-keyword--enum {
|
||||
& > ul {
|
||||
display: inline-block;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
|
||||
li {
|
||||
display: inline;
|
||||
list-style-type: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,3 +66,4 @@
|
||||
@import './Title/title';
|
||||
@import './Properties/properties';
|
||||
@import './PatternProperties/pattern-properties';
|
||||
@import './Enum/enum';
|
||||
|
||||
@@ -160,6 +160,7 @@ export const isExpandable = (schema) => {
|
||||
fn.hasKeyword(schema, "unevaluatedItems") ||
|
||||
fn.hasKeyword(schema, "unevaluatedProperties") ||
|
||||
schema?.description ||
|
||||
schema?.enum ||
|
||||
fn.hasKeyword(schema, "const")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import KeywordPropertyNames from "./components/keywords/PropertyNames"
|
||||
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
|
||||
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
|
||||
import KeywordType from "./components/keywords/Type/Type"
|
||||
import KeywordEnum from "./components/keywords/Enum/Enum"
|
||||
import KeywordConst from "./components/keywords/Const"
|
||||
import KeywordFormat from "./components/keywords/Format/Format"
|
||||
import KeywordTitle from "./components/keywords/Title/Title"
|
||||
@@ -80,6 +81,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
|
||||
KeywordUnevaluatedItems,
|
||||
KeywordUnevaluatedProperties,
|
||||
KeywordType,
|
||||
KeywordEnum,
|
||||
KeywordConst,
|
||||
KeywordFormat,
|
||||
KeywordTitle,
|
||||
|
||||
@@ -29,6 +29,7 @@ import KeywordPropertyNames from "./components/keywords/PropertyNames"
|
||||
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
|
||||
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
|
||||
import KeywordType from "./components/keywords/Type/Type"
|
||||
import KeywordEnum from "./components/keywords/Enum/Enum"
|
||||
import KeywordConst from "./components/keywords/Const"
|
||||
import KeywordFormat from "./components/keywords/Format/Format"
|
||||
import KeywordTitle from "./components/keywords/Title/Title"
|
||||
@@ -69,6 +70,7 @@ const JSONSchema202012Plugin = () => ({
|
||||
JSONSchema202012KeywordUnevaluatedItems: KeywordUnevaluatedItems,
|
||||
JSONSchema202012KeywordUnevaluatedProperties: KeywordUnevaluatedProperties,
|
||||
JSONSchema202012KeywordType: KeywordType,
|
||||
JSONSchema202012KeywordEnum: KeywordEnum,
|
||||
JSONSchema202012KeywordConst: KeywordConst,
|
||||
JSONSchema202012KeywordFormat: KeywordFormat,
|
||||
JSONSchema202012KeywordTitle: KeywordTitle,
|
||||
|
||||
@@ -56,6 +56,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
||||
"JSONSchema202012KeywordUnevaluatedProperties"
|
||||
)
|
||||
const KeywordType = getComponent("JSONSchema202012KeywordType")
|
||||
const KeywordEnum = getComponent("JSONSchema202012KeywordEnum")
|
||||
const KeywordConst = getComponent("JSONSchema202012KeywordConst")
|
||||
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
|
||||
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle")
|
||||
@@ -102,6 +103,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
||||
KeywordUnevaluatedItems,
|
||||
KeywordUnevaluatedProperties,
|
||||
KeywordType,
|
||||
KeywordEnum,
|
||||
KeywordConst,
|
||||
KeywordFormat,
|
||||
KeywordTitle,
|
||||
|
||||
Reference in New Issue
Block a user