Skip to content

Commit 87ded99

Browse files
authored
fix(sample-gen): oas3 form-data object should generate example (#7355)
1 parent 89146ba commit 87ded99

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ const RequestBody = ({
165165
const useInitialValue = useInitialValFromSchemaSamples || useInitialValFromEnum
166166

167167
let initialValue = ""
168-
if(type === "array" && !useInitialValue) {
168+
if (type === "array" && !useInitialValue) {
169169
initialValue = []
170-
} else if (useInitialValue) {
170+
}
171+
if (type === "object" || useInitialValue) {
171172
// TODO: what about example or examples from requestBody could be passed as exampleOverride
172173
initialValue = getSampleSchema(prop, false, {
173174
includeWriteOnly: true
174175
})
175176
}
177+
176178
if (typeof initialValue !== "string" && type === "object") {
177179
initialValue = stringify(initialValue)
178180
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
openapi: 3.0.3
2+
info:
3+
title: multipart/form-data schema object
4+
version: 0.0.1
5+
paths:
6+
/test:
7+
post:
8+
requestBody:
9+
content:
10+
multipart/form-data:
11+
schema:
12+
type: object
13+
properties:
14+
file:
15+
type: string
16+
format: binary
17+
parameters:
18+
"$ref": "#/components/schemas/TestBody"
19+
responses:
20+
200:
21+
description: ok
22+
components:
23+
schemas:
24+
TestBody:
25+
type: object
26+
properties:
27+
stuff:
28+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe("OAS3 default views", () => {
2+
describe("multipart/form-data", () => {
3+
it("should display calculated object string, when no examples provided (#7268)", () => {
4+
cy.visit(
5+
"/?url=/documents/features/request-body/multipart/default-views.yaml",
6+
)
7+
.get("#operations-default-post_test")
8+
.click()
9+
// Expand Try It Out
10+
.get(".try-out__btn")
11+
.click()
12+
.get(".parameters-col_description textarea")
13+
.should("contains.text", "\"stuff\": \"string\"")
14+
})
15+
})
16+
})

0 commit comments

Comments
 (0)