Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for boolean JSON Schema
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed Apr 14, 2023
1 parent 17db5fc commit 867b7ec
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 55 deletions.

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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}>
Expand Down
1 change: 0 additions & 1 deletion src/core/plugins/json-schema-2020-12/components/_all.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import './BooleanJSONSchema/boolean-json-schema';
@import './JSONSchema/json-schema';
@import './Accordion/accordion';
@import './ExpandDeepButton/expand-deep-button';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 0 additions & 2 deletions src/core/plugins/json-schema-2020-12/hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,7 +19,6 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
const value = {
components: {
JSONSchema,
BooleanJSONSchema,
KeywordProperties,
KeywordType,
KeywordFormat,
Expand Down
2 changes: 0 additions & 2 deletions src/core/plugins/json-schema-2020-12/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,7 +16,6 @@ import { withJSONSchemaContext } from "./hoc"
const JSONSchema202012Plugin = () => ({
components: {
JSONSchema202012: JSONSchema,
BooleanJSONSchema202012: BooleanJSONSchema,
JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat,
Expand Down
2 changes: 0 additions & 2 deletions src/core/plugins/oas31/wrap-components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -29,7 +28,6 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
},
components: {
JSONSchema,
BooleanJSONSchema,
KeywordProperties,
KeywordType,
KeywordFormat,
Expand Down

0 comments on commit 867b7ec

Please sign in to comment.