http-swagger icon indicating copy to clipboard operation
http-swagger copied to clipboard

The api doesn't appear. Annotations don't make sense

Open jeonjonghyeok opened this issue 4 years ago • 1 comments

image


package api

import ( "net/http"

"github.com/gorilla/mux"
httpSwagger "github.com/swaggo/http-swagger"
_ "github.com/swaggo/http-swagger/example/gorilla/docs"

)

// @title Swagger Coinss API // @version 1.0 // @description This is Coinss API // @termsOfService http://swagger.io/terms/

// @contact.name API Support // @contact.url http://www.swagger.io/support // @contact.email [email protected]

// @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host petstore.swagger.io // @BasePath /v2 func API() http.Handler {

router := mux.NewRouter()
router.PathPrefix("/swagger/").Handler(httpSwagger.Handler(
	httpSwagger.URL("http://localhost:5000/swagger/doc.json"), //The url pointing to API definition
	httpSwagger.DeepLinking(true),
	httpSwagger.DocExpansion("none"),
	httpSwagger.DomID("#swagger-ui"),
))

//user
router.HandleFunc("/signup", signup).Methods(http.MethodPost, http.MethodOptions)
router.HandleFunc("/signin", signin).Methods(http.MethodPost, http.MethodOptions)

router.Use(handlePanic)

router.Use(func(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Access-Control-Allow-Origin", "*")
		next.ServeHTTP(w, r)
	})
})
router.Use(mux.CORSMethodMiddleware(router))

return router

}

jeonjonghyeok avatar Jun 15 '21 14:06 jeonjonghyeok

This is happening because you didn't add any annotation for the route functions.

// Signup godoc
// @Summary signup route
// @Accept  json
// @Produce  json
// @Param id path int true "Account ID"
// @Success 200 {object} model.User
// @Router /signup [post]
router.HandleFunc("/signup", signup).Methods(http.MethodPost, http.MethodOptions)

ubogdan avatar Aug 11 '21 18:08 ubogdan