feat(oas3): Show file upload for schema binary format (#7325)

* fix(ux): display actual content type instead of hard-coded application/octet-stream

* feat(ux): show file upload when schema has "format: binary", fixes #5636

* feat(ux): show file upload when schema has "format: base64"

According to
https://github.com/swagger-api/swagger-ui/pull/7325#issuecomment-861684260
the uploaded file should be converted to base64 automatically.

* feat(ux): add cypress tests for displaying an upload button
This commit is contained in:
Andreas Grub
2021-06-23 00:33:57 +02:00
committed by GitHub
parent 1032d927a5
commit 13c110a6fe
3 changed files with 225 additions and 2 deletions

View File

@@ -107,18 +107,22 @@ const RequestBody = ({
}
const isObjectContent = mediaTypeValue.getIn(["schema", "type"]) === "object"
const isBinaryFormat = mediaTypeValue.getIn(["schema", "format"]) === "binary"
const isBase64Format = mediaTypeValue.getIn(["schema", "format"]) === "base64"
if(
contentType === "application/octet-stream"
|| contentType.indexOf("image/") === 0
|| contentType.indexOf("audio/") === 0
|| contentType.indexOf("video/") === 0
|| isBinaryFormat
|| isBase64Format
) {
const Input = getComponent("Input")
if(!isExecute) {
return <i>
Example values are not available for <code>application/octet-stream</code> media types.
Example values are not available for <code>{contentType}</code> media types.
</i>
}
@@ -163,7 +167,7 @@ const RequestBody = ({
|| prop.hasIn(["items", "default"])
const useInitialValFromEnum = prop.has("enum") && (prop.get("enum").size === 1 || required)
const useInitialValue = useInitialValFromSchemaSamples || useInitialValFromEnum
let initialValue = ""
if (type === "array" && !useInitialValue) {
initialValue = []