Skip to content

Commit

Permalink
Show ModelExample for multipart/form-data
Browse files Browse the repository at this point in the history
  • Loading branch information
BreakBB committed Oct 11, 2024
1 parent 3d6ccf2 commit 1658571
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ const RequestBody = ({

const isFile = type === "string" && (format === "binary" || format === "base64")

const schemaPartForKey = mediaTypeValue
.get("schema")
.update("properties", (properties) => properties.filter((v, k) => k === key))

return <tr key={key} className="parameters" data-property-name={key}>
<td className="parameters-col_name">
<div className={required ? "parameter__name required" : "parameter__name"}>
Expand Down Expand Up @@ -228,6 +232,23 @@ const RequestBody = ({
/>
)}
</div> : null}
{!isExecute && isContentTypeMultipart && type === "object" ? (
<ModelExample
getComponent={getComponent}
getConfigs={getConfigs}
specSelectors={specSelectors}
expandDepth={1}
isExecute={false}
schema={schemaPartForKey}
specPath={specPath.push("content", contentType)}
example={
<HighlightCode className="body-param__example" language={"json"}>
{initialValue}
</HighlightCode>
}
includeWriteOnly={true}
/>
) : null}
</td>
</tr>
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,29 @@ describe("OAS3 default views", () => {
.get(".parameters-col_description textarea")
.should("contains.text", "\"stuff\": \"string\"")
})

it("should display calculated object string as example (#4581, #5169, #9756)", () => {
cy.visit(
"/?url=/documents/features/request-body/multipart/default-views.yaml",
)
.get("#operations-default-post_test")
.click()
// Show example
.get(".parameters-col_description code")
.should("contains.text", "\"stuff\": \"string\"")
// Switch to schema
.get(".parameters-col_description")
.contains("Schema")
.click()
.get(".parameters-col_description")
.should("contains.text", "parameters")
.should("not.contain.text", "file")
.should("contains.text", "TestBody")
// Expand Try It Out to hide example
.get(".try-out__btn")
.click()
.get(".parameters-col_description textarea")
.should("contains.text", "\"stuff\": \"string\"")
})
})
})

0 comments on commit 1658571

Please sign in to comment.