diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index a37c64b22f1..38d9c671ea8 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -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, @@ -83,15 +83,19 @@ const RequestBody = ({ let initialValue = prop.get("default") || prop.get("example") || "" - if(initialValue === "" && type === "object") { + if (initialValue === "" && type === "object") { initialValue = getSampleSchema(prop, false, { includeWriteOnly: true }) } + if (typeof initialValue !== "string" && type === "object") { + initialValue = stringify(initialValue) + } + const isFile = type === "string" && (format === "binary" || format === "base64") - return + return
{ key } diff --git a/test/e2e-cypress/static/documents/bugs/5164.yaml b/test/e2e-cypress/static/documents/bugs/5164.yaml new file mode 100644 index 00000000000..69bb76f1855 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/5164.yaml @@ -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" \ No newline at end of file diff --git a/test/e2e-cypress/tests/bugs/5164.js b/test/e2e-cypress/tests/bugs/5164.js new file mode 100644 index 00000000000..e8900d89528 --- /dev/null +++ b/test/e2e-cypress/tests/bugs/5164.js @@ -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") + }) +})