Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for if keyword
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed Apr 26, 2023
1 parent bf21a4c commit dea5dbb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const JSONSchema = ({ schema, name }) => {
const KeywordAnyOf = useComponent("KeywordAnyOf")
const KeywordOneOf = useComponent("KeywordOneOf")
const KeywordNot = useComponent("KeywordNot")
const KeywordIf = useComponent("KeywordIf")
const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat")
Expand Down Expand Up @@ -113,6 +114,7 @@ const JSONSchema = ({ schema, name }) => {
<KeywordAnyOf schema={schema} />
<KeywordOneOf schema={schema} />
<KeywordNot schema={schema} />
<KeywordIf schema={schema} />
<Keyword$schema schema={schema} />
<Keyword$vocabulary schema={schema} />
<Keyword$id schema={schema} />
Expand Down
1 change: 1 addition & 0 deletions src/core/plugins/json-schema-2020-12/components/_all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@import './keywords/AnyOf/any-of';
@import './keywords/OneOf/one-of';
@import './keywords/Not/not';
@import './keywords/If/if';
@import './keywords/Type/type';
@import './keywords/Format/format';
@import './keywords/Description/description';
Expand Down
30 changes: 30 additions & 0 deletions src/core/plugins/json-schema-2020-12/components/keywords/If/If.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @prettier
*/
import React from "react"

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

const If = ({ schema }) => {
if (!schema?.if) return null

const JSONSchema = useComponent("JSONSchema")
const name = (
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--if">
If
</span>
)

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

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

export default If
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.json-schema-2020-12 {
&__if {
.json-schema-2020-12-core-keyword--if {
@extend .json-schema-2020-12-core-keyword--allOf;
}
}
}



1 change: 1 addition & 0 deletions src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const isExpandable = (schema) => {
schema?.anyOf ||
schema?.oneOf ||
schema?.not ||
schema?.if ||
schema?.description ||
schema?.properties
)
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 @@ -17,6 +17,7 @@ import KeywordAllOf from "./components/keywords/AllOf/AllOf"
import KeywordAnyOf from "./components/keywords/AnyOf/AnyOf"
import KeywordOneOf from "./components/keywords/OneOf/OneOf"
import KeywordNot from "./components/keywords/Not/Not"
import KeywordIf from "./components/keywords/If/If"
import KeywordProperties from "./components/keywords/Properties/Properties"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
Expand Down Expand Up @@ -51,6 +52,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordAnyOf,
KeywordOneOf,
KeywordNot,
KeywordIf,
KeywordProperties,
KeywordType,
KeywordFormat,
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 @@ -16,6 +16,7 @@ import KeywordAllOf from "./components/keywords/AllOf/AllOf"
import KeywordAnyOf from "./components/keywords/AnyOf/AnyOf"
import KeywordOneOf from "./components/keywords/OneOf/OneOf"
import KeywordNot from "./components/keywords/Not/Not"
import KeywordIf from "./components/keywords/If/If"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title"
Expand All @@ -42,6 +43,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordAnyOf: KeywordAnyOf,
JSONSchema202012KeywordOneOf: KeywordOneOf,
JSONSchema202012KeywordNot: KeywordNot,
JSONSchema202012KeywordIf: KeywordIf,
JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat,
Expand Down
2 changes: 2 additions & 0 deletions src/core/plugins/oas31/wrap-components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf")
const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf")
const KeywordNot = getComponent("JSONSchema202012KeywordNot")
const KeywordIf = getComponent("JSONSchema202012KeywordIf")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
Expand Down Expand Up @@ -56,6 +57,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordAnyOf,
KeywordOneOf,
KeywordNot,
KeywordIf,
KeywordProperties,
KeywordType,
KeywordFormat,
Expand Down

0 comments on commit dea5dbb

Please sign in to comment.