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

Refs #8513
This commit is contained in:
Vladimir Gorej
2023-04-14 15:02:01 +02:00
committed by Vladimír Gorej
parent c4ec33b82c
commit a7efbf5b19
11 changed files with 61 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ const JSONSchema = ({ schema, name }) => {
const KeywordProperties = useComponent("KeywordProperties") const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType") const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat") const KeywordFormat = useComponent("KeywordFormat")
const KeywordDescription = useComponent("KeywordDescription")
const ExpandDeepButton = useComponent("ExpandDeepButton") const ExpandDeepButton = useComponent("ExpandDeepButton")
/** /**
@@ -85,6 +86,7 @@ const JSONSchema = ({ schema, name }) => {
</div> </div>
{expanded && ( {expanded && (
<div className="json-schema-2020-12-body"> <div className="json-schema-2020-12-body">
<KeywordDescription schema={schema} />
<KeywordProperties schema={schema} /> <KeywordProperties schema={schema} />
</div> </div>
)} )}

View File

@@ -38,11 +38,6 @@
} }
} }
&__description {
color: #6b6b6b;
font-size: 12px;
}
&__limit { &__limit {
@include text_code(); @include text_code();
margin-left: 10px; margin-left: 10px;

View File

@@ -4,3 +4,4 @@
@import './ExpandDeepButton/expand-deep-button'; @import './ExpandDeepButton/expand-deep-button';
@import './keywords/Type/type'; @import './keywords/Type/type';
@import './keywords/Format/format'; @import './keywords/Format/format';
@import './keywords/Description/description';

View File

@@ -0,0 +1,20 @@
/**
* @prettier
*/
import React from "react"
import { schema } from "../../../prop-types"
const Description = ({ schema }) => {
if (!schema.description) return null
return (
<div className="json-schema-2020-12__description">{schema.description}</div>
)
}
Description.propTypes = {
schema: schema.isRequired,
}
export default Description

View File

@@ -0,0 +1,5 @@
.json-schema-2020-12__description {
color: #6b6b6b;
font-size: 12px;
margin-left: 20px;
}

View File

@@ -8,6 +8,7 @@ import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema"
import KeywordProperties from "./components/keywords/Properties" import KeywordProperties from "./components/keywords/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"
import KeywordDescription from "./components/keywords/Description/Description"
import Accordion from "./components/Accordion/Accordion" import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton" import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight" import ChevronRightIcon from "./components/icons/ChevronRight"
@@ -22,6 +23,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordProperties, KeywordProperties,
KeywordType, KeywordType,
KeywordFormat, KeywordFormat,
KeywordDescription,
Accordion, Accordion,
ExpandDeepButton, ExpandDeepButton,
ChevronRightIcon, ChevronRightIcon,

View File

@@ -6,6 +6,7 @@ import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema"
import KeywordProperties from "./components/keywords/Properties" import KeywordProperties from "./components/keywords/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"
import KeywordDescription from "./components/keywords/Description/Description"
import Accordion from "./components/Accordion/Accordion" import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton" import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight" import ChevronRightIcon from "./components/icons/ChevronRight"
@@ -19,6 +20,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordProperties: KeywordProperties, JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat, JSONSchema202012KeywordFormat: KeywordFormat,
JSONSchema202012KeywordDescription: KeywordDescription,
JSONSchema202012Accordion: Accordion, JSONSchema202012Accordion: Accordion,
JSONSchema202012ExpandDeepButton: ExpandDeepButton, JSONSchema202012ExpandDeepButton: ExpandDeepButton,
JSONSchema202012ChevronRightIcon: ChevronRightIcon, JSONSchema202012ChevronRightIcon: ChevronRightIcon,

View File

@@ -14,6 +14,7 @@ import InfoWrapper from "./wrap-components/info"
import ModelsWrapper from "./wrap-components/models" import ModelsWrapper from "./wrap-components/models"
import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter" import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter"
import VersionStampWrapper from "./wrap-components/version-stamp" import VersionStampWrapper from "./wrap-components/version-stamp"
import JSONSchema202012KeywordDescriptionWrapper from "./wrap-components/json-schema-2020-12-keyword-description"
import { import {
license as selectLicense, license as selectLicense,
contact as selectContact, contact as selectContact,
@@ -77,6 +78,8 @@ const OAS31Plugin = ({ fn }) => {
VersionPragmaFilter: VersionPragmaFilterWrapper, VersionPragmaFilter: VersionPragmaFilterWrapper,
VersionStamp: VersionStampWrapper, VersionStamp: VersionStampWrapper,
Models: ModelsWrapper, Models: ModelsWrapper,
JSONSchema202012KeywordDescription:
JSONSchema202012KeywordDescriptionWrapper,
}, },
statePlugins: { statePlugins: {
spec: { spec: {

View File

@@ -0,0 +1,20 @@
/**
* @prettier
*/
import React from "react"
import { createOnlyOAS31ComponentWrapper } from "../fn"
const JSONSchema202012KeywordDescriptionWrapper =
createOnlyOAS31ComponentWrapper(({ schema, getComponent }) => {
if (!schema.description) return null
const MarkDown = getComponent("Markdown")
return (
<div className="json-schema-2020-12__description">
<MarkDown source={schema.description} />
</div>
)
})
export default JSONSchema202012KeywordDescriptionWrapper

View File

@@ -13,6 +13,10 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
const KeywordDescription = getComponent(
"JSONSchema202012KeywordDescription",
true
)
const Accordion = getComponent("JSONSchema202012Accordion") const Accordion = getComponent("JSONSchema202012Accordion")
const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton") const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton")
const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon") const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon")
@@ -27,6 +31,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordProperties, KeywordProperties,
KeywordType, KeywordType,
KeywordFormat, KeywordFormat,
KeywordDescription,
Accordion, Accordion,
ExpandDeepButton, ExpandDeepButton,
ChevronRightIcon, ChevronRightIcon,

View File

@@ -7,5 +7,5 @@ import OAS31Plugin from "../plugins/oas31"
import JSONSchema202012Plugin from "../plugins/json-schema-2020-12" import JSONSchema202012Plugin from "../plugins/json-schema-2020-12"
export default function PresetApis() { export default function PresetApis() {
return [BasePreset, OAS3Plugin, OAS31Plugin, JSONSchema202012Plugin] return [BasePreset, OAS3Plugin, JSONSchema202012Plugin, OAS31Plugin]
} }