Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeonjonghyeok opened this issue Jun 15, 2021 · 1 comment
Open

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

jeonjonghyeok opened this issue Jun 15, 2021 · 1 comment

Comments

@jeonjonghyeok
Copy link

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

}

@ubogdan
Copy link
Contributor

ubogdan commented Aug 11, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants