Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for not keyword
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed Apr 26, 2023
1 parent 1583079 commit bf21a4c
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const JSONSchema = ({ schema, name }) => {
const KeywordAllOf = useComponent("KeywordAllOf")
const KeywordAnyOf = useComponent("KeywordAnyOf")
const KeywordOneOf = useComponent("KeywordOneOf")
const KeywordNot = useComponent("KeywordNot")
const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat")
Expand Down Expand Up @@ -111,6 +112,7 @@ const JSONSchema = ({ schema, name }) => {
<KeywordAllOf schema={schema} />
<KeywordAnyOf schema={schema} />
<KeywordOneOf schema={schema} />
<KeywordNot schema={schema} />
<Keyword$schema schema={schema} />
<Keyword$vocabulary schema={schema} />
<Keyword$id schema={schema} />
Expand All @@ -132,7 +134,7 @@ const JSONSchema = ({ schema, name }) => {
}

JSONSchema.propTypes = {
name: PropTypes.string,
name: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
schema: propTypes.schema.isRequired,
}

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 @@ -11,6 +11,7 @@
@import './keywords/AllOf/all-of';
@import './keywords/AnyOf/any-of';
@import './keywords/OneOf/one-of';
@import './keywords/Not/not';
@import './keywords/Type/type';
@import './keywords/Format/format';
@import './keywords/Description/description';
Expand Down
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 Not = ({ schema }) => {
if (!schema?.not) return null

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

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

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

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



Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Title = ({ title, schema }) => {
}

Title.propTypes = {
title: PropTypes.string,
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
schema: schema.isRequired,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
@include text_headline($section-models-model-title-font-color);
display: inline-block;
font-weight: bold;

& .json-schema-2020-12-core-keyword {
margin: 0;
}
}



&-property {
margin: 7px 0;

Expand Down
5 changes: 5 additions & 0 deletions src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const getType = (schema, processedSchemas = new WeakSet()) => {
return null
}

if (schema.not && getType(schema.not) === "any") {
return "never"
}

const typeString = Array.isArray(type)
? type.map((t) => (t === "array" ? getArrayType() : t)).join(" | ")
: type && type.includes("array")
Expand Down Expand Up @@ -125,6 +129,7 @@ export const isExpandable = (schema) => {
schema?.allOf ||
schema?.anyOf ||
schema?.oneOf ||
schema?.not ||
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 @@ -16,6 +16,7 @@ import Keyword$comment from "./components/keywords/$comment"
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 KeywordProperties from "./components/keywords/Properties/Properties"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
Expand Down Expand Up @@ -49,6 +50,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordAllOf,
KeywordAnyOf,
KeywordOneOf,
KeywordNot,
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 @@ -15,6 +15,7 @@ import Keyword$comment from "./components/keywords/$comment"
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 KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title"
Expand All @@ -40,6 +41,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordAllOf: KeywordAllOf,
JSONSchema202012KeywordAnyOf: KeywordAnyOf,
JSONSchema202012KeywordOneOf: KeywordOneOf,
JSONSchema202012KeywordNot: KeywordNot,
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 @@ -23,6 +23,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordAllOf = getComponent("JSONSchema202012KeywordAllOf")
const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf")
const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf")
const KeywordNot = getComponent("JSONSchema202012KeywordNot")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
Expand Down Expand Up @@ -54,6 +55,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordAllOf,
KeywordAnyOf,
KeywordOneOf,
KeywordNot,
KeywordProperties,
KeywordType,
KeywordFormat,
Expand Down

0 comments on commit bf21a4c

Please sign in to comment.