diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/$defs.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/$defs.jsx index 200d6ca2c93..3c0a6b088af 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/$defs.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/$defs.jsx @@ -5,13 +5,14 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../prop-types" -import { useComponent, useIsExpandedDeeply } from "../../hooks" +import { useComponent, useIsExpanded, useIsExpandedDeeply } from "../../hooks" import { JSONSchemaDeepExpansionContext } from "../../context" const $defs = ({ schema }) => { const $defs = schema?.$defs || {} + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/$vocabulary/$vocabulary.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/$vocabulary/$vocabulary.jsx index 8ff0bc7ae1c..f33ba92004f 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/$vocabulary/$vocabulary.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/$vocabulary/$vocabulary.jsx @@ -5,11 +5,16 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../../prop-types" -import { useComponent, useIsExpandedDeeply } from "../../../hooks" +import { + useComponent, + useIsExpanded, + useIsExpandedDeeply, +} from "../../../hooks" const $vocabulary = ({ schema }) => { + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const Accordion = useComponent("Accordion") const handleExpansion = useCallback(() => { diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/AllOf.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/AllOf.jsx index c38e944532e..8d01800f0a1 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/AllOf.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/AllOf.jsx @@ -5,14 +5,20 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../prop-types" -import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks" +import { + useFn, + useComponent, + useIsExpanded, + useIsExpandedDeeply, +} from "../../hooks" import { JSONSchemaDeepExpansionContext } from "../../context" const AllOf = ({ schema }) => { const allOf = schema?.allOf || [] const fn = useFn() + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/AnyOf.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/AnyOf.jsx index 634e6c2524a..d968409104f 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/AnyOf.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/AnyOf.jsx @@ -5,14 +5,20 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../prop-types" -import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks" +import { + useFn, + useComponent, + useIsExpanded, + useIsExpandedDeeply, +} from "../../hooks" import { JSONSchemaDeepExpansionContext } from "../../context" const AnyOf = ({ schema }) => { const anyOf = schema?.anyOf || [] const fn = useFn() + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/DependentSchemas.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/DependentSchemas.jsx index a9a94405543..63c3596a195 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/DependentSchemas.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/DependentSchemas.jsx @@ -5,13 +5,14 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../prop-types" -import { useComponent, useIsExpandedDeeply } from "../../hooks" +import { useComponent, useIsExpanded, useIsExpandedDeeply } from "../../hooks" import { JSONSchemaDeepExpansionContext } from "../../context" const DependentSchemas = ({ schema }) => { const dependentSchemas = schema?.dependentSchemas || [] + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/OneOf.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/OneOf.jsx index 6ad7b824ba0..1d93bcff327 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/OneOf.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/OneOf.jsx @@ -5,14 +5,20 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../prop-types" -import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks" +import { + useFn, + useComponent, + useIsExpanded, + useIsExpandedDeeply, +} from "../../hooks" import { JSONSchemaDeepExpansionContext } from "../../context" const OneOf = ({ schema }) => { const oneOf = schema?.oneOf || [] const fn = useFn() + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/PrefixItems.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/PrefixItems.jsx index 798a40a888a..cb83c4c1447 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/PrefixItems.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/PrefixItems.jsx @@ -5,14 +5,20 @@ import React, { useCallback, useState } from "react" import classNames from "classnames" import { schema } from "../../prop-types" -import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks" +import { + useFn, + useComponent, + useIsExpandedDeeply, + useIsExpanded, +} from "../../hooks" import { JSONSchemaDeepExpansionContext } from "../../context" const PrefixItems = ({ schema }) => { const prefixItems = schema?.prefixItems || [] const fn = useFn() + const isExpanded = useIsExpanded() const isExpandedDeeply = useIsExpandedDeeply() - const [expanded, setExpanded] = useState(isExpandedDeeply) + const [expanded, setExpanded] = useState(isExpanded || isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") diff --git a/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js b/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js new file mode 100644 index 00000000000..9a9ff18b498 --- /dev/null +++ b/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js @@ -0,0 +1,20 @@ +/** + * @prettier + */ + +describe("JSON Schema 2020-12 complex keywords expansion", () => { + it("should deeply expand all Schemas and complex keywords", () => { + cy.visit("/pages/json-schema-2020-12-expansion/").then( + () => { + cy.get(".json-schema-2020-12-accordion") + .find(".json-schema-2020-12-accordion__icon--collapsed") + .should("not.exist") + cy.contains("anyOf1-p1-p2-p1").should("exist") + cy.contains("oneOf1-p1-p2-p1").should("exist") + cy.contains("Prefix items").should("exist") + cy.contains("exampleDef").should("exist") + cy.contains("https://json-schema.org/draft/2020-12/vocab/core").should("exist") + } + ) + }) +}) diff --git a/test/e2e-cypress/static/pages/json-schema-2020-12-expansion/expansion.yaml b/test/e2e-cypress/static/pages/json-schema-2020-12-expansion/expansion.yaml new file mode 100644 index 00000000000..5e7f7958ce9 --- /dev/null +++ b/test/e2e-cypress/static/pages/json-schema-2020-12-expansion/expansion.yaml @@ -0,0 +1,100 @@ +openapi: "3.1.0" +info: + version: "0.0.1" + title: "Swagger UI Webpack Setup" + description: "Demonstrates Swagger UI" +components: + schemas: {} +security: [] +paths: + /pets: + get: + responses: + 200: + description: "OK" + content: + application/json: + schema: + $vocabulary: + https://json-schema.org/draft/2020-12/vocab/core: true + https://json-schema.org/draft/2020-12/vocab/applicator: true + https://json-schema.org/draft/2020-12/vocab/validation: true + https://json-schema.org/draft/2020-12/vocab/meta-data: true + https://json-schema.org/draft/2020-12/vocab/format-annotation: false + https://example.com/my-custom-vocab: true + $defs: + exampleDef: + type: string + allOf: + - oneOf: + - type: object + properties: + oneOf1-p1: + type: object + properties: + oneOf1-p1-p1: + type: string + oneOf1-p1-p2: + type: object + properties: + oneOf1-p1-p2-p1: + type: string + oneOf1-p2: + type: string + - type: object + properties: + oneOf2-p1: + type: string + oneOf2-p2: + type: string + - anyOf: + - type: object + properties: + anyOf1-p1: + type: object + properties: + anyOf1-p1-p1: + type: string + anyOf1-p1-p2: + type: object + properties: + anyOf1-p1-p2-p1: + type: string + anyOf1-p2: + type: string + - type: object + properties: + anyOf2-p1: + type: object + properties: + anyOf2-p1-p1: + type: string + anyOf2-p2: + type: string + - type: object + properties: + p1: + type: object + properties: + p1-p1: + type: string + p1-p2: + type: object + properties: + p1-p2-p1: + type: string + dependentSchemas: + p1-p1: + properties: + p3: + type: array + prefixItems: + - type: string + enum: [a, b, c] + required: [p3] + p2: + type: string + prefixItems: + - type: string + enum: [a, b, c] +tags: [] diff --git a/test/e2e-cypress/static/pages/json-schema-2020-12-expansion/index.html b/test/e2e-cypress/static/pages/json-schema-2020-12-expansion/index.html new file mode 100644 index 00000000000..93a26c93398 --- /dev/null +++ b/test/e2e-cypress/static/pages/json-schema-2020-12-expansion/index.html @@ -0,0 +1,65 @@ + + + + + + + Swagger UI + + + + + + +
+ + + + + + +