feat(json-schema-2020-12): add support for boolean JSON Schema
Refs #8513
This commit is contained in:
committed by
Vladimír Gorej
parent
161c5af17d
commit
83ba76c117
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
import { booleanSchema } from "../../prop-types"
|
||||
|
||||
const BooleanJSONSchema = ({ schema, name }) => {
|
||||
return (
|
||||
<article className="json-schema-2020-12 json-schema-2020-12--boolean">
|
||||
<span>{name}</span>
|
||||
<span>{schema ? "true" : "false"}</span>
|
||||
</article>
|
||||
)
|
||||
}
|
||||
|
||||
BooleanJSONSchema.propTypes = {
|
||||
schema: booleanSchema.isRequired,
|
||||
name: PropTypes.string,
|
||||
}
|
||||
|
||||
BooleanJSONSchema.defaultProps = {
|
||||
name: "",
|
||||
}
|
||||
|
||||
export default BooleanJSONSchema
|
||||
@@ -25,7 +25,6 @@ const JSONSchema = ({ schema, name }) => {
|
||||
const fn = useFn()
|
||||
const [level, nextLevel] = useLevel()
|
||||
const isEmbedded = useIsEmbedded()
|
||||
const BooleanJSONSchema = useComponent("BooleanJSONSchema")
|
||||
const Accordion = useComponent("Accordion")
|
||||
const KeywordProperties = useComponent("KeywordProperties")
|
||||
const KeywordType = useComponent("KeywordType")
|
||||
@@ -56,13 +55,6 @@ const JSONSchema = ({ schema, name }) => {
|
||||
setExpandedDeeply(expandedDeeply)
|
||||
}, [expandedDeeply])
|
||||
|
||||
/**
|
||||
* Rendering handlers.
|
||||
*/
|
||||
if (fn.isBooleanJSONSchema(schema)) {
|
||||
return <BooleanJSONSchema schema={schema} name={name} />
|
||||
}
|
||||
|
||||
return (
|
||||
<JSONSchemaLevelContext.Provider value={nextLevel}>
|
||||
<JSONSchemaDeepExpansionContext.Provider value={expandedDeeply}>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
@import './BooleanJSONSchema/boolean-json-schema';
|
||||
@import './JSONSchema/json-schema';
|
||||
@import './Accordion/accordion';
|
||||
@import './ExpandDeepButton/expand-deep-button';
|
||||
|
||||
@@ -6,7 +6,7 @@ import React from "react"
|
||||
import { schema } from "../../../prop-types"
|
||||
|
||||
const Description = ({ schema }) => {
|
||||
if (!schema.description) return null
|
||||
if (!schema?.description) return null
|
||||
|
||||
return (
|
||||
<div className="json-schema-2020-12__description">{schema.description}</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ import React from "react"
|
||||
import { schema } from "../../../prop-types"
|
||||
|
||||
const Format = ({ schema }) => {
|
||||
if (!schema.format) return null
|
||||
if (!schema?.format) return null
|
||||
|
||||
return <span className="json-schema-2020-12__format">{schema.format}</span>
|
||||
}
|
||||
|
||||
@@ -9,12 +9,7 @@ import { useFn, useComponent } from "../../hooks"
|
||||
const Properties = ({ schema }) => {
|
||||
const fn = useFn()
|
||||
const JSONSchema = useComponent("JSONSchema")
|
||||
|
||||
if (fn.isBooleanJSONSchema(schema)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const properties = schema.properties || {}
|
||||
const properties = schema?.properties || {}
|
||||
|
||||
if (Object.keys(properties).length === 0) {
|
||||
return null
|
||||
|
||||
@@ -9,19 +9,19 @@ export const upperFirst = (value) => {
|
||||
}
|
||||
|
||||
export const getTitle = (schema) => {
|
||||
if (schema.title) return upperFirst(schema.title)
|
||||
if (schema.$anchor) return upperFirst(schema.$anchor)
|
||||
if (schema.$id) return schema.$id
|
||||
if (schema?.title) return upperFirst(schema.title)
|
||||
if (schema?.$anchor) return upperFirst(schema.$anchor)
|
||||
if (schema?.$id) return schema.$id
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
export const getType = (schema) => {
|
||||
if (Array.isArray(schema.type)) {
|
||||
if (Array.isArray(schema?.type)) {
|
||||
return schema.type.map(String).join(" | ")
|
||||
}
|
||||
|
||||
if (schema.type != null) {
|
||||
if (schema?.type != null) {
|
||||
return String(schema.type)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import React from "react"
|
||||
|
||||
import JSONSchema from "./components/JSONSchema/JSONSchema"
|
||||
import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema"
|
||||
import KeywordProperties from "./components/keywords/Properties"
|
||||
import KeywordType from "./components/keywords/Type/Type"
|
||||
import KeywordFormat from "./components/keywords/Format/Format"
|
||||
@@ -20,7 +19,6 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
|
||||
const value = {
|
||||
components: {
|
||||
JSONSchema,
|
||||
BooleanJSONSchema,
|
||||
KeywordProperties,
|
||||
KeywordType,
|
||||
KeywordFormat,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @prettier
|
||||
*/
|
||||
import JSONSchema from "./components/JSONSchema/JSONSchema"
|
||||
import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema"
|
||||
import KeywordProperties from "./components/keywords/Properties"
|
||||
import KeywordType from "./components/keywords/Type/Type"
|
||||
import KeywordFormat from "./components/keywords/Format/Format"
|
||||
@@ -17,7 +16,6 @@ import { withJSONSchemaContext } from "./hoc"
|
||||
const JSONSchema202012Plugin = () => ({
|
||||
components: {
|
||||
JSONSchema202012: JSONSchema,
|
||||
BooleanJSONSchema202012: BooleanJSONSchema,
|
||||
JSONSchema202012KeywordProperties: KeywordProperties,
|
||||
JSONSchema202012KeywordType: KeywordType,
|
||||
JSONSchema202012KeywordFormat: KeywordFormat,
|
||||
|
||||
@@ -9,7 +9,6 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
||||
const { getComponent, fn } = getSystem()
|
||||
const Models = getComponent("OAS31Models", true)
|
||||
const JSONSchema = getComponent("JSONSchema202012")
|
||||
const BooleanJSONSchema = getComponent("BooleanJSONSchema202012")
|
||||
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
|
||||
const KeywordType = getComponent("JSONSchema202012KeywordType")
|
||||
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
|
||||
@@ -29,7 +28,6 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
|
||||
},
|
||||
components: {
|
||||
JSONSchema,
|
||||
BooleanJSONSchema,
|
||||
KeywordProperties,
|
||||
KeywordType,
|
||||
KeywordFormat,
|
||||
|
||||
Reference in New Issue
Block a user