-
-
Notifications
You must be signed in to change notification settings - Fork 437
Improve implicit FormData detection. Add tests. #1539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -766,9 +766,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
+770
to
+776
|
||||||||||||||||||||||||||||||||
| // 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not so sure we want/need that.. Any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is regexp is needed here? Why we can not use data from swagger schema ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a more specific version of the string includes() that's there now