handle docs route at the router level

This commit is contained in:
Ruidy Nemausat 2020-07-19 09:16:18 +02:00
parent 13a6e80ce2
commit 270de58204
3 changed files with 11 additions and 3 deletions

View file

@ -32,7 +32,7 @@ type productResponse struct {
Body models.Product
}
// swagger:parameters deleteProduct updateProduct
// swagger:parameters deleteProduct updateProduct getProduct
type productIDParameter struct {
// The ID of a product in the database
// in: path

View file

@ -28,6 +28,6 @@ func (p *Products) RegisterRoutes(m *mux.Router, path string) {
// swagger docs
opts := middleware.RedocOpts{SpecURL: "/swagger.yaml"}
swaggerHandler := middleware.Redoc(opts, nil)
getRouter.Handle("/docs", swaggerHandler)
getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))
m.Handle("/docs", swaggerHandler).Methods(http.MethodGet)
m.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))
}

View file

@ -109,6 +109,14 @@ paths:
get:
description: Return a list of products from the database
operationId: getProduct
parameters:
- description: The ID of a product in the database
format: int64
in: path
name: id
required: true
type: integer
x-go-name: ID
responses:
"200":
$ref: '#/responses/productResponse'