Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sample-gen): oas3 form-data object should generate example #7355

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\"")
})
})
})