Tsoa: Turn off request payloads validation

Created on 21 Dec 2017  路  6Comments  路  Source: lukeautry/tsoa

Hi, first of all thanks for really great library.

Is there any way to turn off request payload validation? I would like to have more control around this and handle validation by myself.

Best,
Jakub

Most helpful comment

Ahhh, I forgot to say something about my walk around.

  • In order to skip validation at all I added custom template for my express application
  • I'm throwing my custom schema validation errors
  • I added to express global error handler which maps different types of errors to suitable http statuses and responses

At this point I don't have errors well documented in swagger file but it is sufficient for me. I guess it could be done somehow with @DefaultResponse decorator.

@egandro you can achieve this with turning off validation and validate request body with Joi. You have to keep in sync Joi schemas with types of request objects - It's not perfect but in works.

All 6 comments

After short investigation I found that it should be possible by adding something like that:

{{#if !disableValidation}} ... {{/if}} to remove getValidatedArgs declaration and call
in
tsoa/src/routeGeneration/templates/express.ts
tsoa/src/routeGeneration/templates/hapi.ts
tsoa/src/routeGeneration/templates/koa.ts

@lukeautry, let me know what do you think about this.

I was thinking about this, too.

What you really want is s custom error when the problem occures.

E.g. maxLength 20 -> you want a custom error for this.

Maybe we can do this with jsdoc?

Maybe this can be handled with validators, but in your case @jakubzloczewski , it sounds like you should want to completely skip validation. I think that's a reasonable use case.

Ahhh, I forgot to say something about my walk around.

  • In order to skip validation at all I added custom template for my express application
  • I'm throwing my custom schema validation errors
  • I added to express global error handler which maps different types of errors to suitable http statuses and responses

At this point I don't have errors well documented in swagger file but it is sufficient for me. I guess it could be done somehow with @DefaultResponse decorator.

@egandro you can achieve this with turning off validation and validate request body with Joi. You have to keep in sync Joi schemas with types of request objects - It's not perfect but in works.

So what you want is not "no validation".

What you want are custom errors :) Thats's a whole different story!

Yes - I love this idea - but ... it should be possible to have internationalisation - and this is related to the JWT / Security system (which is application dependant).

So we should make this customizable.

@jakubzloczewski since your custom template is working for you, I'm going to close this issue. If someone else would like this feature, they're welcome to comment again and we can consider reopening the issue. But to be honest, having the validation is most of the reason why tsoa exists. So to turn off the validation seems rather strange.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ancizararenas picture ancizararenas  路  3Comments

lonix1 picture lonix1  路  5Comments

fahrradflucht picture fahrradflucht  路  4Comments

taicho picture taicho  路  5Comments

rustam-crunch picture rustam-crunch  路  5Comments