0

Hi dear NSwag community!

I'd like to extend the TS generation templates for NSwag to include validation of the response. So for example, if my (exported) DTO looks like this:

export interface GetListResultOfResourceDto {
    Items?: ResourceDto[] | undefined;
    MaxMatches: number;
    Skip: number;
    Take: number;
}

Can NSwag supply me with all the properties I need to extend the template to output some code like this?

const response = ... // Shortend example
if (response.Items === undefined || !Array.isArray(response.Items))
    throw new Error("Invalid property Items");
if (response.MaxMatches === undefined)
    throw new Error("Invalid property MaxMatches");
// And so on...

Writing the template wouldn't be a problem for be but I can't figure out where to get all these properties (in terms of templating) from.

FabianTe
  • 516
  • 4
  • 22
  • You need to check the model classes in njsonschema but we might have to extend them so that validation info is exposed – Rico Suter Oct 30 '18 at 23:15

1 Answers1

0

Out of the box there is no configuration option which enables this.

This might be possible by heavily manipulating the TS templates but I am still unsure if NSwags model classes supply all the information to the template to implement this.

FabianTe
  • 516
  • 4
  • 22