tsoa
tsoa copied to clipboard
@FormField - add validation for submitted multipart/form-data fields
Sorting
-
I'm submitting a ...
- [ ] bug report
- [x] feature request
- [ ] support request
-
I confirm that I
- [x] used the search to make sure that a similar issue hasn't already been submit
Expected Behavior
If I declare a @FormField('myField')
in a controller method such as :
/**
*
* @maxLength 40
*/
type StringWIthMaxLength = string;
// ...
public async create(
@FormField('presentation') presentation: StringWIthMaxLength,
): Promise<{}> {
or inline as tsdoc
s
public async create(
/**
*
* @maxLength 40
*/
@FormField('presentation') presentation: string,
): Promise<{}>
the generated OpenApi spec should contain information about those constraints, and those constraints should be enforced at runtime too.
I would expect something like this in the Open API yaml :
post:
operationId: Create
parameters: []
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
presentation:
type: string
maxLength: 40
Current Behavior
Annotation / constraints are ignored in the generated swagger file and at runtime.
post:
operationId: Create
parameters: []
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
presentation:
type: string
Possible Solution
The data submitted through FormField
should be documented and validated the same way as if they were a property of a submitted JSON paylog.
Steps to Reproduce
Context (Environment)
Version of the library: v3.6.1 Version of NodeJS: v14.16.0 (current LTS)
- Confirm you were using yarn not npm: [ ] - using
npm
here ...
Detailed Description
Breaking change?
This would be a change for people who are using tsoa
v3.6.0+ and are using something other than string
as the type of the argument annotated with @FormField
... but for those people I would consider that current behavior is unexpected anyway.
I'm not in the position to help implement this, but I also encountered a need for this feature today.
Have you tried jddoc at the method level? This is how you're supposed to annotate parameters generally speaking.
As in
/**
* @maxLenth presentation 40
*/
public async create(
@FormField('presentation') presentation: string,
): Promise<{}>