Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for contentSchema keyword (#8645)
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n authored May 10, 2023
1 parent 9208818 commit f549a1d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const JSONSchema = forwardRef(
const KeywordConstraint = useComponent("KeywordConstraint")
const KeywordDependentRequired = useComponent("KeywordDependentRequired")
const KeywordFormat = useComponent("KeywordFormat")
const KeywordContentSchema = useComponent("KeywordContentSchema")
const KeywordTitle = useComponent("KeywordTitle")
const KeywordDescription = useComponent("KeywordDescription")
const ExpandDeepButton = useComponent("ExpandDeepButton")
Expand Down Expand Up @@ -168,6 +169,7 @@ const JSONSchema = forwardRef(
<KeywordItems schema={schema} />
<KeywordUnevaluatedItems schema={schema} />
<KeywordContains schema={schema} />
<KeywordContentSchema schema={schema} />
</>
)}
<KeywordEnum schema={schema} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @prettier
*/
import React from "react"

import { schema } from "../../prop-types"
import { useFn, useComponent } from "../../hooks"

const ContentSchema = ({ schema }) => {
const fn = useFn()
const JSONSchema = useComponent("JSONSchema")

/**
* Rendering.
*/
if (!fn.hasKeyword(schema, "contentSchema")) return null

const name = (
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
Content schema
</span>
)

return (
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--contentSchema">
<JSONSchema name={name} schema={schema.contentSchema} />
</div>
)
}

ContentSchema.propTypes = {
schema: schema.isRequired,
}

export default ContentSchema
3 changes: 2 additions & 1 deletion src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export const isExpandable = (schema) => {
fn.hasKeyword(schema, "unevaluatedProperties") ||
schema?.description ||
schema?.enum ||
fn.hasKeyword(schema, "const")
fn.hasKeyword(schema, "const") ||
fn.hasKeyword(schema, "contentSchema")
)
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/plugins/json-schema-2020-12/hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import KeywordConst from "./components/keywords/Const"
import KeywordConstraint from "./components/keywords/Constraint/Constraint"
import KeywordDependentRequired from "./components/keywords/DependentRequired/DependentRequired"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordContentSchema from "./components/keywords/ContentSchema"
import KeywordTitle from "./components/keywords/Title/Title"
import KeywordDescription from "./components/keywords/Description/Description"
import Accordion from "./components/Accordion/Accordion"
Expand Down Expand Up @@ -90,6 +91,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordConstraint,
KeywordDependentRequired,
KeywordFormat,
KeywordContentSchema,
KeywordTitle,
KeywordDescription,
Accordion,
Expand Down
2 changes: 2 additions & 0 deletions src/core/plugins/json-schema-2020-12/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import KeywordConst from "./components/keywords/Const"
import KeywordConstraint from "./components/keywords/Constraint/Constraint"
import KeywordDependentRequired from "./components/keywords/DependentRequired/DependentRequired"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordContentSchema from "./components/keywords/ContentSchema"
import KeywordTitle from "./components/keywords/Title/Title"
import KeywordDescription from "./components/keywords/Description/Description"
import Accordion from "./components/Accordion/Accordion"
Expand Down Expand Up @@ -77,6 +78,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordConstraint: KeywordConstraint,
JSONSchema202012KeywordDependentRequired: KeywordDependentRequired,
JSONSchema202012KeywordFormat: KeywordFormat,
JSONSchema202012KeywordContentSchema: KeywordContentSchema,
JSONSchema202012KeywordTitle: KeywordTitle,
JSONSchema202012KeywordDescription: KeywordDescription,
JSONSchema202012Accordion: Accordion,
Expand Down
4 changes: 4 additions & 0 deletions src/core/plugins/oas31/wrap-components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
"JSONSchema202012KeywordDependentRequired"
)
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
const KeywordContentSchema = getComponent(
"JSONSchema202012KeywordContentSchema"
)
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle")
const KeywordDescription = getComponent(
"JSONSchema202012KeywordDescription",
Expand Down Expand Up @@ -112,6 +115,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordConstraint,
KeywordDependentRequired,
KeywordFormat,
KeywordContentSchema,
KeywordTitle,
KeywordDescription,
Accordion,
Expand Down

0 comments on commit f549a1d

Please sign in to comment.