Swagger docs for "Adding routes"
See original GitHub issueI have this model
class User {
name: string;
friends: User[];
}
And I have created a crud controller to manage and get user without friends property. To get friends of a user, I have added an “adding route” :
@Get(':id/friends')
@UseInterceptors(CrudRequestInterceptor)
async getFriends(@ParsedRequest() req: CrudRequest) {
return this.userService.getFriends(req);
}
All works fine, but there is not swagger documentation for this route. To generate it, I have to add :
import { SerializeHelper } from '@nestjsx/crud/lib/crud/serialize.helper';
[...]
@Get(':id/friends')
@UseInterceptors(CrudRequestInterceptor)
@ApiOperation({ summary: 'Get friends of a user' })
@ApiParam({
name: 'id',
description: 'The id of the user',
type: 'string',
})
@ApiOkResponse({
schema: {
oneOf: [
{ $ref: getSchemaPath(SerializeHelper.createGetManyDto(User, User.name)) },
{
type: 'array',
items: { $ref: getSchemaPath(User) },
},
],
},
})
async getFriends(@ParsedRequest() req: CrudRequest) {
return this.userService.getFriends(req);
}
Do you think we can simplify this declaration by exporting a helper to generate the GetManyDto
reponse ?
Or, by adding a new @GetManyResponse
decorator that ony generates the response swagger documentation :
@Get(':id/friends')
@UseInterceptors(CrudRequestInterceptor)
@ApiOperation({ summary: 'Get friends of a user' })
@ApiParam({
name: 'id',
description: 'The id of the user',
type: 'string',
})
@GetManyResponse({type: User})
async getFriends(@ParsedRequest() req: CrudRequest) {
return this.userService.getFriends(req);
}
Or, by adding a new @GetMany
decorator that generates the swagger documentation and the CrudRequestInterceptor
interceptor :
@Get(':id/friends')
@GetMany({type: User})
async getFriends(@ParsedRequest() req: CrudRequest) {
return this.userService.getFriends(req);
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Paths and Operations - Swagger
API paths and operations are defined in the global paths section of the API specification. ... All paths are relative to the API...
Read more >Adding custom baucis routes to its generated swagger api
I would like to add my "/myroute/:id' to the generated swagger api. PUT /Users/myroute/{id} description. Does anyone know how to do about this?...
Read more >swagger:route · GitBook - Goswagger.Io
A swagger:route annotation links a path to a method. This operation gets a unique id, which is used in various places as method...
Read more >swagger-routes-express - npm
Connect Express route controllers to restful paths using a Swagger 2 or OpenAPI 3 definition file. Latest version: 3.3.2, last published: 5 ...
Read more >Documenting Express.js API with Swagger - LogRocket Blog
You can customize Swagger UI by implementing a custom CSS into Swagger integration. To do that, add customCssUrl option into swaggerUi.setup :
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 Free
Top 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
+1 It would be grateful to create a custom GET route and have already generated swagger documentation with the filters, sorting, selecting, etc. Waiting for the update!
+1 This would be great to have the swagger doc for custom routes when we used CrudRequest in it !