Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/schema-routes/schema-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,15 @@ export class SchemaRoutes {
// It needed for cases when swagger schema is not declared request body type as form data
// but request body data type contains form data types like File
if (
this.FORM_DATA_TYPES.some((dataType) =>
content.includes(`: ${dataType}`),
)
this.FORM_DATA_TYPES.some((dataType) => {
// Match e.g. ": File" followed by word boundary, array brackets, or union/nullable syntax
// This prevents false positives like ": FileType" or ": SomeFile"
// Escape special regex characters (getSchemaType can theoretically return complex types like "File | null" or "UtilRequiredKeys<File, ...>")
const escapedType = dataType.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(`:\\s*${escapedType}(?:\\[\\]|\\s*\\||\\b|$)`).test(
content,
);
Comment on lines +583 to +589
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex only matches : File followed by []/|/word-boundary, but it won’t match array types produced as : (File)[] (or : (File | null)[]) because of the leading (. If request bodies can contain arrays of file/binary, the workaround will miss them and keep contentKind as JSON. Consider allowing optional parentheses around the matched type (e.g., match :\s*\(?${type}\)? before handling []/unions), or add a dedicated branch to handle the (...)[] form.

Suggested change
// Match e.g. ": File" followed by word boundary, array brackets, or union/nullable syntax
// This prevents false positives like ": FileType" or ": SomeFile"
// Escape special regex characters (getSchemaType can theoretically return complex types like "File | null" or "UtilRequiredKeys<File, ...>")
const escapedType = dataType.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(`:\\s*${escapedType}(?:\\[\\]|\\s*\\||\\b|$)`).test(
content,
);
// Match e.g. ": File" or ": (File)" (optionally with unions like "(File | null)")
// followed by word boundary, array brackets, or union/nullable syntax.
// This prevents false positives like ": FileType" or ": SomeFile".
// Escape special regex characters (getSchemaType can theoretically return complex types like "File | null" or "UtilRequiredKeys<File, ...>")
const escapedType = dataType.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// Allow either a bare type or a parenthesized form that may contain unions, e.g. "(File | null)".
const pattern = `:\\s*(?:\\(\\s*${escapedType}(?:\\s*\\|[^)]*)?\\)|${escapedType})(?:\\[\\]|\\s*\\||\\b|$)`;
return new RegExp(pattern).test(content);

Copilot uses AI. Check for mistakes.
})
) {
contentKind = CONTENT_KIND.FORM_DATA;
}
Expand Down
Loading
Loading