fix: coerce multipart initial property values to string (via #5166)

* coerce multipart initial property values to string

* add tests
This commit is contained in:
kyle
2019-02-07 15:35:22 -06:00
committed by GitHub
parent 48e4fb937d
commit d3c2e2777f
3 changed files with 49 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ import React from "react"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import { Map, OrderedMap, List } from "immutable"
import { getCommonExtensions, getSampleSchema } from "core/utils"
import { getCommonExtensions, getSampleSchema, stringify } from "core/utils"
const RequestBody = ({
requestBody,
@@ -89,9 +89,13 @@ const RequestBody = ({
})
}
if (typeof initialValue !== "string" && type === "object") {
initialValue = stringify(initialValue)
}
const isFile = type === "string" && (format === "binary" || format === "base64")
return <tr key={key} className="parameters">
return <tr key={key} className="parameters" data-property-name={key}>
<td className="col parameters-col_name">
<div className={required ? "parameter__name required" : "parameter__name"}>
{ key }

View File

@@ -0,0 +1,23 @@
openapi: "3.0.0"
paths:
/:
post:
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
first:
type: object
example:
one: abc
two: 123
second:
type: array
items:
type: string
example:
- "hi"

View File

@@ -0,0 +1,19 @@
describe("#5164: multipart property initial values", () => {
it("should provide correct initial values for objects and arrays", () => {
const correctObjectValue = JSON.stringify({
"one": "abc",
"two": 123
}, null, 2)
cy
.visit("?url=/documents/bugs/5164.yaml")
.get("#operations-default-post_")
.click()
.get(".try-out__btn")
.click()
.get(`.parameters[data-property-name="first"] textarea`)
.should("have.value", correctObjectValue)
.get(`.parameters[data-property-name="second"] input`)
.should("have.value", "hi")
})
})