Skip to content

Commit

Permalink
fix: remove special handling of non-FormData entries (#6036)
Browse files Browse the repository at this point in the history
Ref: #6033

* 'createObjWithHashedKeys' validation consistency with isFunction
* 'createObjWithHashedKeys' additional jsdoc example
  • Loading branch information
tim-lai committed May 28, 2020
1 parent add5753 commit 68185dd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ export function fromJSOrdered(js) {
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 All @@ -97,11 +94,21 @@ export function fromJSOrdered(js) {
* Append a hashIdx and counter to the key name, if multiple exists
* if single, key name = <original>
* if multiple, key name = <original><hashIdx><count>
* @example <caption>single entry for vegetable</caption>
* fdObj.entries.vegtables: "carrot"
* // returns newObj.vegetables : "carrot"
* @example <caption>multiple entries for fruits[]</caption>
* fdObj.entries.fruits[]: "apple"
* // returns newObj.fruits[]_**[]1 : "apple"
* fdObj.entries.fruits[]: "banana"
* // returns newObj.fruits[]_**[]2 : "banana"
* fdObj.entries.fruits[]: "grape"
* // returns newObj.fruits[]_**[]3 : "grape"
* @param {FormData} fdObj - a FormData object
* @return {Object} - a plain object
*/
export function createObjWithHashedKeys (fdObj) {
if (!fdObj.entries) {
if (!isFunction(fdObj.entries)) {
return fdObj // not a FormData object with iterable
}
const newObj = {}
Expand Down
34 changes: 32 additions & 2 deletions test/e2e-cypress/tests/bugs/6016.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
describe("Entries should be valid property name", () => {
it("should render a OAS3.0 definition that uses 'entries' as a property name", () => {
it("should render a OAS3.0 definition that uses 'entries' as a 'components' 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", () => {
it("should render expanded Operations of OAS3.0 definition that uses 'entries' as a 'components' property name", () => {
cy.visit("/?url=/documents/bugs/6016-oas3.yaml")
.get("#operations-default-test_test__get")
.click()
.get("#operations-default-test_test__get > div .opblock-body")
.should("exist")

})
it("should render expanded Models of OAS3.0 definition that uses 'entries' as a 'components' property name", () => {
cy.visit("/?url=/documents/bugs/6016-oas3.yaml")
.get("#model-Testmodel > span .model-box")
.click()
.get("div .model-box")
.should("exist")
})
it("should render a OAS2.0 definition that uses 'entries' as a 'definitions' property name", () => {
cy.visit("/?url=/documents/bugs/6016-oas2.yaml")
.get("#operations-default-post_pet")
.should("exist")
})
it("should render expanded Operations of OAS2.0 definition that uses 'entries' as a 'definitions' property name", () => {
cy.visit("/?url=/documents/bugs/6016-oas2.yaml")
.get("#operations-default-post_pet")
.click()
.get("#operations-default-post_pet > div .opblock-body")
.should("exist")

})
it("should render expanded Models of OAS2.0 definition that uses 'entries' as a 'defintions' property name", () => {
cy.visit("/?url=/documents/bugs/6016-oas2.yaml")
.get("#model-Pet > span .model-box")
.click()
.get("div .model-box")
.should("exist")
})
})

0 comments on commit 68185dd

Please sign in to comment.