Browse Source

fix: entries as property name (#6025)

bubble
Tim Lai 4 years ago
committed by GitHub
parent
commit
3a65070bf5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 1 deletions
  1. +5
    -1
      src/core/utils.js
  2. +28
    -0
      test/e2e-cypress/static/documents/bugs/6016-oas2.yaml
  3. +31
    -0
      test/e2e-cypress/static/documents/bugs/6016-oas3.yaml
  4. +12
    -0
      test/e2e-cypress/tests/bugs/6016.js

+ 5
- 1
src/core/utils.js View File

@@ -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)
}



+ 28
- 0
test/e2e-cypress/static/documents/bugs/6016-oas2.yaml View File

@@ -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
- 0
test/e2e-cypress/static/documents/bugs/6016-oas3.yaml View File

@@ -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
- 0
test/e2e-cypress/tests/bugs/6016.js View File

@@ -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")
})
})

Loading…
Cancel
Save