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:
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user