diff --git a/src/core/utils.js b/src/core/utils.js index 36baa2e8e63..1ef08971562 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -18,6 +18,7 @@ import _memoize from "lodash/memoize" import find from "lodash/find" import some from "lodash/some" import eq from "lodash/eq" +import isFunction from "lodash/isFunction" import { memoizedSampleFromSchema, memoizedCreateXMLExample } from "core/plugins/samples/fn" import win from "./window" import cssEscape from "css.escape" @@ -80,11 +81,14 @@ export function fromJSOrdered(js) { if (Array.isArray(js)) { return Im.Seq(js).map(fromJSOrdered).toList() } - if (js.entries) { + if (isFunction(js.entries)) { // handle multipart/form-data const objWithHashedKeys = createObjWithHashedKeys(js) return Im.OrderedMap(objWithHashedKeys).map(fromJSOrdered) } + if (js.entries && !isFunction(js.entries)) { + return Im.OrderedMap(js.entries).map(fromJSOrdered) + } return Im.OrderedMap(js).map(fromJSOrdered) } diff --git a/test/e2e-cypress/static/documents/bugs/6016-oas2.yaml b/test/e2e-cypress/static/documents/bugs/6016-oas2.yaml new file mode 100644 index 00000000000..79538589419 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/6016-oas2.yaml @@ -0,0 +1,28 @@ +swagger: "2.0" +info: + description: "OAS2 sample with entries as property name" + version: "0.0.1" + title: "Swagger Sample" +paths: + /pet: + post: + summary: "Add a new pet to the store" + description: "" + parameters: + - in: "body" + name: "body" + schema: + $ref: "#/definitions/Pet" + responses: + "405": + description: "Invalid input" +definitions: + Pet: + type: "object" + properties: + id: + type: "integer" + entries: # <-- evaluate + type: "array" + items: + type: "string" diff --git a/test/e2e-cypress/static/documents/bugs/6016-oas3.yaml b/test/e2e-cypress/static/documents/bugs/6016-oas3.yaml new file mode 100644 index 00000000000..475138c79e5 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/6016-oas3.yaml @@ -0,0 +1,31 @@ +openapi: 3.0.2 +info: + title: OAS 3.0 sample with entries as property name + version: 0.1.0 +paths: + /test/: + get: + summary: Test + operationId: test_test__get + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Testmodel' +components: + schemas: + Testmodel: + title: Testmodel + required: + - name + - entries + type: object + properties: + name: + title: Name + type: string + entries: + title: Entries + type: integer diff --git a/test/e2e-cypress/tests/bugs/6016.js b/test/e2e-cypress/tests/bugs/6016.js new file mode 100644 index 00000000000..ef82bf822d2 --- /dev/null +++ b/test/e2e-cypress/tests/bugs/6016.js @@ -0,0 +1,12 @@ +describe("Entries should be valid property name", () => { + it("should render a OAS3.0 definition that uses 'entries' as a property name", () => { + cy.visit("/?url=/documents/bugs/6016-oas3.yaml") + .get("#operations-tag-default") + .should("exist") + }) + it("should render a OAS2.0 definition that uses 'entries' as a property name", () => { + cy.visit("/?url=/documents/bugs/6016-oas2.yaml") + .get("#operations-default-post_pet") + .should("exist") + }) +})