Skip to content

Commit

Permalink
feat: swagger annotations (ppetzold#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsamofal authored Aug 24, 2023
1 parent fe35757 commit 8eede4b
Show file tree
Hide file tree
Showing 10 changed files with 1,475 additions and 220 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,43 @@ is resolved to:

`WHERE ... AND (id = 5 OR id = 7) AND name = 'Milo' AND ...`

## Swagger

You can use two default decorators @ApiOkResponsePaginated and @ApiPagination to generate swagger documentation for your endpoints

`@ApiOkPaginatedResponse` is for response body, return http[](https://) status is 200

`@ApiPaginationQuery` is for query params


```typescript
@Get()
@ApiOkPaginatedResponse(
UserDto,
USER_PAGINATION_CONFIG,
)
@ApiPaginationQuery(USER_PAGINATION_CONFIG)
async findAll(
@Paginate()
query: PaginateQuery,
): Promise<Paginated<UserEntity>> {

}
```

There is also some syntax sugar for this, and you can use only one decorator `@PaginatedSwaggerDocs` for both response body and query params

```typescript
@Get()
@PaginatedSwaggerDocs(UserDto, USER_PAGINATION_CONFIG)
async findAll(
@Paginate()
query: PaginateQuery,
): Promise<Paginated<UserEntity>> {

}
```

## Troubleshooting

The package does not report error reasons in the response bodies. They are instead
Expand Down
Loading

0 comments on commit 8eede4b

Please sign in to comment.