Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: entries as property name #6025

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
28 changes: 28 additions & 0 deletions test/e2e-cypress/static/documents/bugs/6016-oas2.yaml
Original file line number Diff line number Diff line change
@@ -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"
31 changes: 31 additions & 0 deletions test/e2e-cypress/static/documents/bugs/6016-oas3.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/e2e-cypress/tests/bugs/6016.js
Original file line number Diff line number Diff line change
@@ -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")
})
})