Skip to content

Commit

Permalink
fix: entries as property name
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-lai committed May 20, 2020
1 parent b85ae03 commit 59ad986
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
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")
})
})

0 comments on commit 59ad986

Please sign in to comment.