Skip to content

Commit d3c2e27

Browse files
authored
fix: coerce multipart initial property values to string (via #5166)
* coerce multipart initial property values to string * add tests
1 parent 48e4fb9 commit d3c2e27

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/core/plugins/oas3/components/request-body.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22
import PropTypes from "prop-types"
33
import ImPropTypes from "react-immutable-proptypes"
44
import { Map, OrderedMap, List } from "immutable"
5-
import { getCommonExtensions, getSampleSchema } from "core/utils"
5+
import { getCommonExtensions, getSampleSchema, stringify } from "core/utils"
66

77
const RequestBody = ({
88
requestBody,
@@ -83,15 +83,19 @@ const RequestBody = ({
8383

8484
let initialValue = prop.get("default") || prop.get("example") || ""
8585

86-
if(initialValue === "" && type === "object") {
86+
if (initialValue === "" && type === "object") {
8787
initialValue = getSampleSchema(prop, false, {
8888
includeWriteOnly: true
8989
})
9090
}
9191

92+
if (typeof initialValue !== "string" && type === "object") {
93+
initialValue = stringify(initialValue)
94+
}
95+
9296
const isFile = type === "string" && (format === "binary" || format === "base64")
9397

94-
return <tr key={key} className="parameters">
98+
return <tr key={key} className="parameters" data-property-name={key}>
9599
<td className="col parameters-col_name">
96100
<div className={required ? "parameter__name required" : "parameter__name"}>
97101
{ key }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: "3.0.0"
2+
3+
paths:
4+
/:
5+
post:
6+
requestBody:
7+
required: true
8+
content:
9+
multipart/form-data:
10+
schema:
11+
type: object
12+
properties:
13+
first:
14+
type: object
15+
example:
16+
one: abc
17+
two: 123
18+
second:
19+
type: array
20+
items:
21+
type: string
22+
example:
23+
- "hi"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe("#5164: multipart property initial values", () => {
2+
it("should provide correct initial values for objects and arrays", () => {
3+
const correctObjectValue = JSON.stringify({
4+
"one": "abc",
5+
"two": 123
6+
}, null, 2)
7+
8+
cy
9+
.visit("?url=/documents/bugs/5164.yaml")
10+
.get("#operations-default-post_")
11+
.click()
12+
.get(".try-out__btn")
13+
.click()
14+
.get(`.parameters[data-property-name="first"] textarea`)
15+
.should("have.value", correctObjectValue)
16+
.get(`.parameters[data-property-name="second"] input`)
17+
.should("have.value", "hi")
18+
})
19+
})

0 commit comments

Comments
 (0)