Skip to content

Commit

Permalink
fix(sample-gen): oas3 form-data object should generate example (#7355)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-lai authored Jun 18, 2021
1 parent 89146ba commit 87ded99
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,16 @@ const RequestBody = ({
const useInitialValue = useInitialValFromSchemaSamples || useInitialValFromEnum

let initialValue = ""
if(type === "array" && !useInitialValue) {
if (type === "array" && !useInitialValue) {
initialValue = []
} else if (useInitialValue) {
}
if (type === "object" || useInitialValue) {
// TODO: what about example or examples from requestBody could be passed as exampleOverride
initialValue = getSampleSchema(prop, false, {
includeWriteOnly: true
})
}

if (typeof initialValue !== "string" && type === "object") {
initialValue = stringify(initialValue)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.3
info:
title: multipart/form-data schema object
version: 0.0.1
paths:
/test:
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
parameters:
"$ref": "#/components/schemas/TestBody"
responses:
200:
description: ok
components:
schemas:
TestBody:
type: object
properties:
stuff:
type: string
16 changes: 16 additions & 0 deletions test/e2e-cypress/tests/features/oas3-request-body-default-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe("OAS3 default views", () => {
describe("multipart/form-data", () => {
it("should display calculated object string, when no examples provided (#7268)", () => {
cy.visit(
"/?url=/documents/features/request-body/multipart/default-views.yaml",
)
.get("#operations-default-post_test")
.click()
// Expand Try It Out
.get(".try-out__btn")
.click()
.get(".parameters-col_description textarea")
.should("contains.text", "\"stuff\": \"string\"")
})
})
})

0 comments on commit 87ded99

Please sign in to comment.