Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for items keyword
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed Apr 26, 2023
1 parent e27107a commit 1f1f045
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const JSONSchema = ({ schema, name }) => {
const KeywordElse = useComponent("KeywordElse")
const KeywordDependentSchemas = useComponent("KeywordDependentSchemas")
const KeywordPrefixItems = useComponent("KeywordPrefixItems")
const KeywordItems = useComponent("KeywordItems")
const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat")
Expand Down Expand Up @@ -123,6 +124,7 @@ const JSONSchema = ({ schema, name }) => {
<KeywordElse schema={schema} />
<KeywordDependentSchemas schema={schema} />
<KeywordPrefixItems schema={schema} />
<KeywordItems schema={schema} />
<Keyword$schema schema={schema} />
<Keyword$vocabulary schema={schema} />
<Keyword$id schema={schema} />
Expand Down
30 changes: 30 additions & 0 deletions src/core/plugins/json-schema-2020-12/components/keywords/Items.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 Items = ({ schema }) => {
if (!schema?.items) return null

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

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

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

export default Items
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 @@ -142,6 +142,7 @@ export const isExpandable = (schema) => {
schema?.else ||
schema?.dependentSchemas ||
schema?.prefixItems ||
schema?.items ||
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 @@ -22,6 +22,7 @@ import KeywordThen from "./components/keywords/Then"
import KeywordElse from "./components/keywords/Else"
import KeywordDependentSchemas from "./components/keywords/DependentSchemas"
import KeywordPrefixItems from "./components/keywords/PrefixItems"
import KeywordItems from "./components/keywords/Items"
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 @@ -61,6 +62,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordElse,
KeywordDependentSchemas,
KeywordPrefixItems,
KeywordItems,
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 @@ -21,6 +21,7 @@ import KeywordThen from "./components/keywords/Then"
import KeywordElse from "./components/keywords/Else"
import KeywordDependentSchemas from "./components/keywords/DependentSchemas"
import KeywordPrefixItems from "./components/keywords/PrefixItems"
import KeywordItems from "./components/keywords/Items"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title"
Expand Down Expand Up @@ -52,6 +53,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordElse: KeywordElse,
JSONSchema202012KeywordDependentSchemas: KeywordDependentSchemas,
JSONSchema202012KeywordPrefixItems: KeywordPrefixItems,
JSONSchema202012KeywordItems: KeywordItems,
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 @@ -31,6 +31,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
"JSONSchema202012KeywordDependentSchemas"
)
const KeywordPrefixItems = getComponent("JSONSchema202012KeywordPrefixItems")
const KeywordItems = getComponent("JSONSchema202012KeywordItems")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
Expand Down Expand Up @@ -68,6 +69,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordElse,
KeywordDependentSchemas,
KeywordPrefixItems,
KeywordItems,
KeywordProperties,
KeywordType,
KeywordFormat,
Expand Down

0 comments on commit 1f1f045

Please sign in to comment.