Open ivan-sennov opened 7 months ago
+1
When I discovered it wasn't possible to manually set a $ref
for a header param via @ApiHeader
, I was hoping I could get around it manually using @ApiOperation
. Only to find params don't work at all in @ApiOperation
.
same here :(
Is there an existing issue for this?
Current behavior
When
@ApiOperation
decorator is used, such options as "parameters", "tags" and "responses" are ignored and doesn't affect the resulting swagger json. You have to use @ApiResponse and other corresponding decorators to reach needed effect.Code
Result
Minimum reproduction code
See example above
Steps to reproduce
No response
Expected behavior
When
@ApiOperation
decorator is used, all used options have the appropriate effect. If there are more specific decorators are used, such as@ApiResponse
, they have a higher priority.Package version
7.2.0
NestJS version
10.3.1
Node.js version
18.19.0
In which operating systems have you tested?
Other
Sometimes there is no properly typed models or interfaces are used and you need to manually describe the entire endpoint, including the query parameters and response types. In such case it may be inconvenient to use the different decorators and I would like to use the mentioned one to cover all properties of operation. Moreover, the type
ApiOperationOptions
which@ApiOperation
accepts as an options allows passing such things in it but never applies them, which can be misleading.During my investigation, I found the next code in the
SwaggerExplorer
class:https://github.com/nestjs/swagger/blob/6633c3639f7f278c294f13504dcaa2d3bfb5b17f/lib/swagger-explorer.ts#L95-L104
Explorers are processed sequentially and, as a result,
parameters
and other mentioned fields which comes fromApiOperationExplorer
are being overwritten by the next explorers here https://github.com/nestjs/swagger/blob/6633c3639f7f278c294f13504dcaa2d3bfb5b17f/lib/swagger-explorer.ts#L182Thus, we can not manually set such properties with
@ApiOperation
decorator.