-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Fix/10017 parse file pipe builder #10025
Fix/10017 parse file pipe builder #10025
Conversation
ensure ParseFilePipe returns undefined when file is optional
ensure a route with ParseFilePipe and fileIsOptional set to true does not throw when no file is provided
ensure ParseFilePipe throws an error when a file is required but was not passed
ensure ParseFilePipe throws an error if isFileOptional was not explicitly provided and there is no file
ensure sample 29 controller throws an error when a file is required but none is given
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.
Some minor fixes I'll work on soon
Pull Request Test Coverage Report for Build 0a52d60b-a134-4623-891a-69fd95493980
💛 - Coveralls |
* Defines if file parameter is optional. Default is false. | ||
*/ |
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.
* Defines if file parameter is optional. Default is false. | |
*/ | |
* Defines if file parameter is optional. | |
* @default false | |
*/ |
/** | ||
* Defines if file parameter is optional. Default is false. | ||
*/ | ||
fileIsOptional?: boolean; |
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.
what about
fileIsOptional?: boolean; | |
required?: boolean; |
and then the default will be true
.
@@ -25,13 +27,20 @@ export class ParseFilePipe implements PipeTransform<any> { | |||
exceptionFactory, | |||
errorHttpStatusCode = HttpStatus.BAD_REQUEST, | |||
validators = [], | |||
fileIsRequired, |
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.
changed to required
semantic, but I maintained the full word fileIsRequired
to be explicit here. In the consumer side, when creating a ParseFilePipe, I think it's worth it to specify what is required:
const parseFilePipe = new ParseFilePipe({
validators: [],
fileIsRequired: false,
});
change ParseFilePipe option to use fileIsRequired instead of fileIsOptional
b273064
to
79041c1
Compare
@kamilmysliwiec waiting for your review here. If this is accepted, I suppose we'll have to update the docs as well |
lgtm |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #10017
What is the new behavior?
Now we can specify if a given
file
parameter is required in theParseFilePipeBuilder
or in theParseFilePipe
:With that, when a file is explicitly set to be optional, the ParseFileValidator won't throw an error. On the other hand, when the file is required (default behavior), it will now throw a 400 error.
Does this PR introduce a breaking change?
Other information