Skip to content

Commit e12e441

Browse files
committed
Improve implicit form data detection. Add tests.
1 parent cb2ad8b commit e12e441

File tree

4 files changed

+771
-3
lines changed

4 files changed

+771
-3
lines changed

src/schema-routes/schema-routes.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,13 @@ export class SchemaRoutes {
590590
// It needed for cases when swagger schema is not declared request body type as form data
591591
// but request body data type contains form data types like File
592592
if (
593-
this.FORM_DATA_TYPES.some((dataType) =>
594-
content.includes(`: ${dataType}`),
595-
)
593+
this.FORM_DATA_TYPES.some((dataType) => {
594+
// Match e.g. ": File" followed by word boundary, array brackets, or union/nullable syntax
595+
// This prevents false positives like ": FileType" or ": SomeFile"
596+
// Escape special regex characters (getSchemaType can theoretically return complex types like "File | null" or "UtilRequiredKeys<File, ...>")
597+
const escapedType = dataType.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
598+
return new RegExp(`:\\s*${escapedType}(?:\\[\\]|\\s*\\||\\b|$)`).test(content);
599+
})
596600
) {
597601
contentKind = CONTENT_KIND.FORM_DATA;
598602
}

0 commit comments

Comments
 (0)