feat(oas31): display file upload input when contentMediaType or contentEncoding is present (#10412)

Refs #9278
This commit is contained in:
Oliwia Rogala
2025-04-11 15:38:35 +02:00
committed by GitHub
parent c29e7126c9
commit 26967308e9
3 changed files with 146 additions and 1 deletions

View File

@@ -1,12 +1,45 @@
/**
* @prettier
*/
import { Map } from "immutable"
import isPlainObject from "lodash/isPlainObject"
export const makeIsFileUploadIntended = (getSystem) => {
const isFileUploadIntended = (schema, mediaType = null) => {
const { fn } = getSystem()
return fn.isFileUploadIntendedOAS30(schema, mediaType)
/**
* Return `true` early if the media type indicates a file upload
* or if a combination of type: `string` and format: `binary/byte` is detected.
* This ensures support for empty Media Type Objects,
* as the schema check is performed later.
*/
const isFileUploadIntendedOAS30 = fn.isFileUploadIntendedOAS30(
schema,
mediaType
)
if (isFileUploadIntendedOAS30) {
return true
}
const isSchemaImmutable = Map.isMap(schema)
if (!isSchemaImmutable && !isPlainObject(schema)) {
return false
}
const contentMediaType = isSchemaImmutable
? schema.get("contentMediaType")
: schema.contentMediaType
const contentEncoding = isSchemaImmutable
? schema.get("contentEncoding")
: schema.contentEncoding
return (
(typeof contentMediaType === "string" && contentMediaType !== "") ||
(typeof contentEncoding === "string" && contentEncoding !== "")
)
}
return isFileUploadIntended