diff --git a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx index 29708eae..1886703f 100644 --- a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx +++ b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx @@ -35,7 +35,7 @@ const JSONSchema = forwardRef( ) => { const fn = useFn() // this implementation assumes that $id is always non-relative URI - const pathToken = identifier || schema.$id || name + const pathToken = identifier || schema?.$id || name const { path } = usePath(pathToken) const { isExpanded, setExpanded, setCollapsed } = useIsExpanded(pathToken) const [level, nextLevel] = useLevel() diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/AdditionalProperties.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/AdditionalProperties.jsx index c16d3f03..a093d78c 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/AdditionalProperties.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/AdditionalProperties.jsx @@ -8,7 +8,6 @@ import { useFn, useComponent } from "../../hooks" const AdditionalProperties = ({ schema }) => { const fn = useFn() - const { additionalProperties } = schema const JSONSchema = useComponent("JSONSchema") if (!fn.hasKeyword(schema, "additionalProperties")) return null @@ -24,14 +23,14 @@ const AdditionalProperties = ({ schema }) => { return (
- {additionalProperties === true ? ( + {schema.additionalProperties === true ? ( <> {name} allowed - ) : additionalProperties === false ? ( + ) : schema.additionalProperties === false ? ( <> {name} @@ -41,7 +40,7 @@ const AdditionalProperties = ({ schema }) => { ) : ( )} diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Constraint/Constraint.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Constraint/Constraint.jsx index 4a784f39..161a7034 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/Constraint/Constraint.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Constraint/Constraint.jsx @@ -4,17 +4,29 @@ import React from "react" import PropTypes from "prop-types" +import { isPlainObject } from "../../../fn" + /** * This component represents various constraint keywords * from JSON Schema 2020-12 validation vocabulary. */ -const Constraint = ({ constraint }) => ( - - {constraint.value} - -) +const Constraint = ({ constraint }) => { + if ( + !isPlainObject(constraint) || + typeof constraint.scope !== "string" || + typeof constraint.value !== "string" + ) { + return null + } + + return ( + + {constraint.value} + + ) +} Constraint.propTypes = { constraint: PropTypes.shape({ diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/DependentRequired/DependentRequired.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/DependentRequired/DependentRequired.jsx index dcea3f2d..cc04eacd 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/DependentRequired/DependentRequired.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/DependentRequired/DependentRequired.jsx @@ -7,7 +7,9 @@ import PropTypes from "prop-types" import * as propTypes from "../../../prop-types" const DependentRequired = ({ dependentRequired }) => { - if (dependentRequired.length === 0) return null + if (!Array.isArray(dependentRequired) || dependentRequired.length === 0) { + return null + } return (
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx index 311b6669..8f31f1c6 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx @@ -8,7 +8,6 @@ import { useFn, useComponent } from "../../hooks" const PropertyNames = ({ schema }) => { const fn = useFn() - const { propertyNames } = schema const JSONSchema = useComponent("JSONSchema") const name = ( @@ -25,7 +24,7 @@ const PropertyNames = ({ schema }) => {
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx index 2ae434cf..4acb8230 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx @@ -8,7 +8,6 @@ import { useFn, useComponent } from "../../hooks" const UnevaluatedItems = ({ schema }) => { const fn = useFn() - const { unevaluatedItems } = schema const JSONSchema = useComponent("JSONSchema") /** @@ -26,7 +25,7 @@ const UnevaluatedItems = ({ schema }) => {
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx index 07609265..302f1fe6 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx @@ -8,7 +8,6 @@ import { useFn, useComponent } from "../../hooks" const UnevaluatedProperties = ({ schema }) => { const fn = useFn() - const { unevaluatedProperties } = schema const JSONSchema = useComponent("JSONSchema") /** @@ -26,7 +25,7 @@ const UnevaluatedProperties = ({ schema }) => {
diff --git a/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/empty-schema.cy.js b/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/empty-schema.cy.js new file mode 100644 index 00000000..56287740 --- /dev/null +++ b/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/empty-schema.cy.js @@ -0,0 +1,12 @@ +/** + * @prettier + */ + +describe("Empty JSON Schema 2020-12", () => { + it("should render as schema of type `any`", () => { + cy.visit("/?url=/documents/features/json-schema-2020-12-empty-schema.yaml") + + cy.get(".json-schema-2020-12__title").should("contain", "Test") + cy.get(".json-schema-2020-12__attribute").should("contain", "any") + }) +}) diff --git a/test/e2e-cypress/static/documents/features/json-schema-2020-12-empty-schema.yaml b/test/e2e-cypress/static/documents/features/json-schema-2020-12-empty-schema.yaml new file mode 100644 index 00000000..5fa70bd4 --- /dev/null +++ b/test/e2e-cypress/static/documents/features/json-schema-2020-12-empty-schema.yaml @@ -0,0 +1,4 @@ +openapi: 3.1.0 +components: + schemas: + Test: