API input decorators
The Nest.js swagger module can produce a swagger document using the @Body
, @Param
, @Query
, and @Headers
decorators. However, depending on how you write your API controllers, the swagger document can contain very little information. The swagger module will use the types associated with the decorated parameters to describe the parameters an API expects within the swagger document. To depict this, we will modify the comment PUT API to use all four decorators and show how that affects the swagger document by reviewing the swagger UI application.
@
Controller
(
'entries/:entryId'
)
export
class
CommentController
{
@
Put
(
'comments/:commentId'
)
public
async
update
(
@
Body
()
body
:UpdateCommentRequest
,
@
Param
(
'commentId'
)
comment
:string
,
@
Query
(
'testQuery'
)
testQuery
:string
,
@
Headers
(
'testHeader'
)
testHeader
:string
)
{
}
}
From the example, we can see the header of this API card...