Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for unevaluatedProperties
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed Apr 26, 2023
1 parent aba7f98 commit 3a5a605
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const JSONSchema = ({ schema, name }) => {
)
const KeywordPropertyNames = useComponent("KeywordPropertyNames")
const KeywordUnevaluatedItems = useComponent("KeywordUnevaluatedItems")
const KeywordUnevaluatedProperties = useComponent(
"KeywordUnevaluatedProperties"
)
const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat")
const KeywordTitle = useComponent("KeywordTitle")
Expand Down Expand Up @@ -124,6 +127,7 @@ const JSONSchema = ({ schema, name }) => {
<KeywordProperties schema={schema} />
<KeywordPatternProperties schema={schema} />
<KeywordAdditionalProperties schema={schema} />
<KeywordUnevaluatedProperties schema={schema} />
<KeywordPropertyNames schema={schema} />
<KeywordAllOf schema={schema} />
<KeywordAnyOf schema={schema} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @prettier
*/
import React from "react"

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

const UnevaluatedProperties = ({ schema }) => {
const fn = useFn()

if (!fn.hasKeyword(schema, "unevaluatedProperties")) return null

const { unevaluatedProperties } = schema
const JSONSchema = useComponent("JSONSchema")
const name = (
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
Unevaluated properties
</span>
)

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

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

export default UnevaluatedProperties
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 @@ -158,6 +158,7 @@ export const isExpandable = (schema) => {
fn.hasKeyword(schema, "additionalProperties") ||
fn.hasKeyword(schema, "propertyNames") ||
fn.hasKeyword(schema, "unevaluatedItems") ||
fn.hasKeyword(schema, "unevaluatedProperties") ||
schema?.description
)
}
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 @@ -29,6 +29,7 @@ import KeywordPatternProperties from "./components/keywords/PatternProperties/Pa
import KeywordAdditionalProperties from "./components/keywords/AdditionalProperties"
import KeywordPropertyNames from "./components/keywords/PropertyNames"
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
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 @@ -75,6 +76,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordAdditionalProperties,
KeywordPropertyNames,
KeywordUnevaluatedItems,
KeywordUnevaluatedProperties,
KeywordType,
KeywordFormat,
KeywordTitle,
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 @@ -27,6 +27,7 @@ import KeywordPatternProperties from "./components/keywords/PatternProperties/Pa
import KeywordAdditionalProperties from "./components/keywords/AdditionalProperties"
import KeywordPropertyNames from "./components/keywords/PropertyNames"
import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems"
import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties"
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 @@ -65,6 +66,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordAdditionalProperties: KeywordAdditionalProperties,
JSONSchema202012KeywordPropertyNames: KeywordPropertyNames,
JSONSchema202012KeywordUnevaluatedItems: KeywordUnevaluatedItems,
JSONSchema202012KeywordUnevaluatedProperties: KeywordUnevaluatedProperties,
JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat,
JSONSchema202012KeywordTitle: KeywordTitle,
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 @@ -46,6 +46,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordUnevaluatedItems = getComponent(
"JSONSchema202012KeywordUnevaluatedItems"
)
const KeywordUnevaluatedProperties = getComponent(
"JSONSchema202012KeywordUnevaluatedProperties"
)
const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle")
Expand Down Expand Up @@ -89,6 +92,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordAdditionalProperties,
KeywordPropertyNames,
KeywordUnevaluatedItems,
KeywordUnevaluatedProperties,
KeywordType,
KeywordFormat,
KeywordTitle,
Expand Down

0 comments on commit 3a5a605

Please sign in to comment.