ApiReponse with type is an Advanced Types
See original GitHub issueHi,
I have an generic class who is return on all my request
import { ApiModelProperty } from '@nestjs/swagger';
export class ServerApiResponse<T> {
@ApiModelProperty()
value: T;
@ApiModelProperty({ type: Number })
pages: number;
@ApiModelProperty({ type: Number })
page: number;
@ApiModelProperty({ type: Number })
maxByPage: number;
@ApiModelProperty({ type: Number })
count: number;
@ApiModelProperty({ type: Object })
error: any;
}
And on my endpoint i have add
@ApiResponse({
status: 200,
description: '',
type: ServerApiResponse<PatientCaretrackPopulatedOutput[]>
})
But i have this error Error TS2348: Value of type 'ServerApiResponse' is not callable.
So i tried this
@ApiResponse({
status: 200,
description: '',
type: new ServerApiResponse<PatientCaretrackPopulatedOutput[]>()
})
But when i launch swagger i have no description of response returned.
It’s possible to do this ?
Thx
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Operations - OpenAPI - A progressive Node.js framework
Advanced: Generic ApiResponse #. With the ability to provide Raw Definitions, we can define Generic schema for Swagger UI. Assume we have the...
Read more >Advanced Typescript by Example: API Service Manager
This article will take you through the implementation of an API service manager written in Typescript to efficiently handle web services, ...
Read more >OpenAPI for your REST APIs in NestJS - notiz.dev
Annotate your REST endpoints with the custom @ApiResponse() specifying the status code and the response type or choose a short-hand API ...
Read more >Playground Example - Discriminate Types - TypeScript
A discriminated type union is where you use code flow analysis to reduce a ... www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions ...
Read more >TypeScript: advanced and esoteric | Konstantin Lebedev blog
If you already know how to use the aforementioned advanced types, ... type ApiResponse = { data: Array<{ firstName: string lastName: string ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s not possible for the same reason as Array<T> or T[] (look at the issue Microsoft/TypeScript/issues/10576). You could try the following:
Cross posting this, does that mean a generic controller wouldn’t be able to expose the proper endpoints? For example, something like this (taken from https://github.com/nestjs/nest/issues/228):