Skip to content

Commit 5c7face

Browse files
committed
Fix validating param object when type is any or an interface (reflected as Object)
1 parent d3005c0 commit 5c7face

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/ActionParameterHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ export class ActionParameterHandler {
177177
* Perform class-validation if enabled.
178178
*/
179179
protected validateValue(value: any, paramMetadata: ParamMetadata): Promise<any>|any {
180-
if (paramMetadata.validate || (this.driver.enableValidation && paramMetadata.validate !== false)) {
180+
const isValidationEnabled = (paramMetadata.validate instanceof Object || paramMetadata.validate === true)
181+
|| (this.driver.enableValidation === true && paramMetadata.validate !== false);
182+
const shouldValidate = paramMetadata.targetType
183+
&& (paramMetadata.targetType !== Object)
184+
&& (value instanceof paramMetadata.targetType);
185+
186+
if (isValidationEnabled && shouldValidate) {
181187
const options = paramMetadata.validate instanceof Object ? paramMetadata.validate : this.driver.validationOptions;
182188
return validate(value, options)
183189
.then(() => value)

test/functional/action-params.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ describe("action parameters", () => {
687687
};
688688

689689
assertRequest([3001, 3002], "post", "files", undefined, requestOptions, response => {
690-
// expect(uploadedFileName).to.be.eql("hello-world.txt");
690+
expect(uploadedFileName).to.be.eql("hello-world.txt");
691691
expect(response).to.be.status(200);
692692
expect(response).to.have.header("content-type", "text/html; charset=utf-8");
693693
expect(response.body).to.be.equal("<html><body>hello-world.txt</body></html>");

0 commit comments

Comments
 (0)