Skip to content

Commit 4a39905

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

File tree

4 files changed

+771
-3
lines changed

4 files changed

+771
-3
lines changed

src/schema-routes/schema-routes.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,15 @@ 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(
599+
content,
600+
);
601+
})
596602
) {
597603
contentKind = CONTENT_KIND.FORM_DATA;
598604
}

0 commit comments

Comments
 (0)