feat(json-schema-2020-12): add support for default keyword (#8647)

Refs #8513
This commit is contained in:
Vladimír Gorej
2023-05-10 17:32:07 +02:00
committed by GitHub
parent de3e852569
commit e6d50999ba
6 changed files with 40 additions and 1 deletions

View File

@@ -72,6 +72,7 @@ const JSONSchema = forwardRef(
const KeywordContentSchema = useComponent("KeywordContentSchema")
const KeywordTitle = useComponent("KeywordTitle")
const KeywordDescription = useComponent("KeywordDescription")
const KeywordDefault = useComponent("KeywordDefault")
const ExpandDeepButton = useComponent("ExpandDeepButton")
/**
@@ -176,6 +177,7 @@ const JSONSchema = forwardRef(
schema={schema}
dependentRequired={dependentRequired}
/>
<KeywordDefault schema={schema} />
<Keyword$schema schema={schema} />
<Keyword$vocabulary schema={schema} />
<Keyword$id schema={schema} />

View File

@@ -0,0 +1,30 @@
/**
* @prettier
*/
import React from "react"
import { schema } from "../../prop-types"
import { useFn } from "../../hooks"
const Default = ({ schema }) => {
const fn = useFn()
if (!fn.hasKeyword(schema, "default")) return null
return (
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--default">
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
Default
</span>
<span className="json-schema-2020-12-keyword__value json-schema-2020-12-keyword__value--const">
{fn.stringify(schema.default)}
</span>
</div>
)
}
Default.propTypes = {
schema: schema.isRequired,
}
export default Default

View File

@@ -162,7 +162,8 @@ export const isExpandable = (schema) => {
schema?.description ||
schema?.enum ||
fn.hasKeyword(schema, "const") ||
fn.hasKeyword(schema, "contentSchema")
fn.hasKeyword(schema, "contentSchema") ||
fn.hasKeyword(schema, "default")
)
}

View File

@@ -38,6 +38,7 @@ import KeywordDependentRequired from "./components/keywords/DependentRequired/De
import KeywordContentSchema from "./components/keywords/ContentSchema"
import KeywordTitle from "./components/keywords/Title/Title"
import KeywordDescription from "./components/keywords/Description/Description"
import KeywordDefault from "./components/keywords/Default"
import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight"
@@ -92,6 +93,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordContentSchema,
KeywordTitle,
KeywordDescription,
KeywordDefault,
Accordion,
ExpandDeepButton,
ChevronRightIcon,

View File

@@ -36,6 +36,7 @@ import KeywordDependentRequired from "./components/keywords/DependentRequired/De
import KeywordContentSchema from "./components/keywords/ContentSchema"
import KeywordTitle from "./components/keywords/Title/Title"
import KeywordDescription from "./components/keywords/Description/Description"
import KeywordDefault from "./components/keywords/Default"
import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight"
@@ -79,6 +80,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordContentSchema: KeywordContentSchema,
JSONSchema202012KeywordTitle: KeywordTitle,
JSONSchema202012KeywordDescription: KeywordDescription,
JSONSchema202012KeywordDefault: KeywordDefault,
JSONSchema202012Accordion: Accordion,
JSONSchema202012ExpandDeepButton: ExpandDeepButton,
JSONSchema202012ChevronRightIcon: ChevronRightIcon,

View File

@@ -70,6 +70,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
"JSONSchema202012KeywordDescription",
true
)
const KeywordDefault = getComponent("JSONSchema202012KeywordDefault")
const Accordion = getComponent("JSONSchema202012Accordion")
const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton")
const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon")
@@ -116,6 +117,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordContentSchema,
KeywordTitle,
KeywordDescription,
KeywordDefault,
Accordion,
ExpandDeepButton,
ChevronRightIcon,