[API] Increase swagger documentation coverage (#89)

Add documentation coverage for endpoints related to VAAs.
This commit is contained in:
agodnic 2023-01-24 17:58:04 -03:00 committed by GitHub
parent 2f11affc53
commit cc1f1b440f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 7 deletions

View File

@ -21,7 +21,17 @@ func NewController(serv *Service, logger *zap.Logger) *Controller {
return &Controller{srv: serv, logger: logger.With(zap.String("module", "VaaController"))}
}
// FindAll handler for the endpoint /vaas/.
// FindAll godoc
// @Description Returns all VAAs. Output is paginated and can also be be sorted.
// @Tags Wormscan
// @ID find-all-vaas
// @Param page query integer false "Page number."
// @Param pageSize query integer false "Number of elements per page."
// @Param sortOrder query string false "Sort results in ascending or descending order." Enums(ASC, DESC)
// @Success 200 {object} response.Response[[]VaaDoc]
// @Failure 400
// @Failure 500
// @Router /api/v1/vaas/ [get]
func (c *Controller) FindAll(ctx *fiber.Ctx) error {
p := middleware.GetPaginationFromContext(ctx)
vaas, err := c.srv.FindAll(ctx.Context(), p)
@ -31,7 +41,18 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error {
return ctx.JSON(vaas)
}
// FindByChain handler for the endpoint /vaas/:chain.
// FindByChain godoc
// @Description Returns all the VAAs generated in specific blockchain.
// @Tags Wormscan
// @ID find-vaas-by-chain
// @Param chain_id path integer true "id of the blockchain"
// @Param page query integer false "Page number."
// @Param pageSize query integer false "Number of elements per page."
// @Param sortOrder query string false "Sort results in ascending or descending order." Enums(ASC, DESC)
// @Success 200 {object} response.Response[[]VaaDoc]
// @Failure 400
// @Failure 500
// @Router /api/v1/vaas/{chain_id} [get]
func (c *Controller) FindByChain(ctx *fiber.Ctx) error {
p := middleware.GetPaginationFromContext(ctx)
chainID, err := middleware.ExtractChainID(ctx, c.logger)
@ -45,7 +66,19 @@ func (c *Controller) FindByChain(ctx *fiber.Ctx) error {
return ctx.JSON(vaas)
}
// FindByEmitter handler for the endpoint /vaas/:chain/:emitter.
// FindByEmitter godoc
// @Description Returns all all the VAAs generated by a specific emitter address.
// @Tags Wormscan
// @ID find-vaas-by-emitter
// @Param chain_id path integer true "id of the blockchain"
// @Param emitter path string true "address of the emitter"
// @Param page query integer false "Page number."
// @Param pageSize query integer false "Number of elements per page."
// @Param sortOrder query string false "Sort results in ascending or descending order." Enums(ASC, DESC)
// @Success 200 {object} response.Response[[]VaaDoc]
// @Failure 400
// @Failure 500
// @Router /api/v1/vaas/{chain_id}/{emitter} [get]
func (c *Controller) FindByEmitter(ctx *fiber.Ctx) error {
p := middleware.GetPaginationFromContext(ctx)
chainID, emitter, err := middleware.ExtractVAAChainIDEmitter(ctx, c.logger)
@ -59,7 +92,19 @@ func (c *Controller) FindByEmitter(ctx *fiber.Ctx) error {
return ctx.JSON(vaas)
}
// FindById handler for the endpoint /vaas/:chain/:emitter/:sequence/:signer/:hash.
// FindById godoc
// @Description Find a VAA by ID.
// @Tags Wormscan
// @ID find-vaa-by-id
// @Param chain_id path integer true "id of the blockchain"
// @Param emitter path string true "address of the emitter"
// @Param seq path integer true "sequence of the VAA"
// @Param signer path string true "Signer address"
// @Param hash path string true "VAA hash"
// @Success 200 {object} response.Response[[]VaaDoc]
// @Failure 400
// @Failure 500
// @Router /api/v1/vaas/{chain_id}/{emitter}/{seq}/{signer}/{hash} [get]
func (c *Controller) FindById(ctx *fiber.Ctx) error {
chainID, emitter, seq, err := middleware.ExtractVAAParams(ctx, c.logger)
if err != nil {
@ -79,7 +124,7 @@ func (c *Controller) FindById(ctx *fiber.Ctx) error {
// @ID guardians-find-signed-vaa
// @Param chain_id path integer true "id of the blockchain"
// @Param emitter path string true "address of the emitter"
// @Param seq path integer true "sequence of the vaa"
// @Param seq path integer true "sequence of the VAA"
// @Success 200 {object} object{vaaBytes=[]byte}
// @Failure 400
// @Failure 500
@ -114,7 +159,7 @@ func (c *Controller) FindSignedVAAByID(ctx *fiber.Ctx) error {
// @ID guardians-find-signed-batch-vaa
// @Param chain_id path integer true "id of the blockchain"
// @Param emitter path string true "address of the emitter"
// @Param seq path integer true "sequence of the vaa"
// @Param seq path integer true "sequence of the VAA"
// @Success 200 {object} object{vaaBytes=[]byte}
// @Failure 400
// @Failure 500
@ -123,7 +168,14 @@ func (c *Controller) FindSignedBatchVAAByID(ctx *fiber.Ctx) error {
return response.NewApiError(ctx, fiber.StatusNotImplemented, response.Unimplemented, "not yet implemented", nil)
}
// GetVaaCount handler for the endpoint /vaas/vaa-counts.
// GetVaaCount godoc
// @Description Returns the total number of VAAs emitted for each blockchain.
// @Tags Wormscan
// @ID get-vaa-counts
// @Success 200 {object} response.Response[[]VaaStats]
// @Failure 400
// @Failure 500
// @Router /api/v1/vaas/vaa-counts [get]
func (c *Controller) GetVaaCount(ctx *fiber.Ctx) error {
p := middleware.GetPaginationFromContext(ctx)
vaas, err := c.srv.GetVaaCount(ctx.Context(), p)