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

Swagger throwing "indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: 2.0" issue #266

Open
mohanprasathsj opened this issue May 23, 2023 · 3 comments

Comments

@mohanprasathsj
Copy link

mohanprasathsj commented May 23, 2023

I a using the following code, when I did swag init and tried to view the swagger-ui, I am getting the following exception
"Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0)."
image

/ @title     Car Track Service 2.0 API
// @version         2.0
// @description     Car Track Service in Go using Gin framework.

// @contact.name  *****
// @contact.email  *******

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

// @BasePath  /api
func main() {
fmt.Println("Starting...")
date := strconv.Itoa(time.Now().Year()) + fmt.Sprintf("%02d", time.Now().Month()) + fmt.Sprintf("%02d", time.Now().Day()) + strconv.Itoa(time.Now().Hour()) + fmt.Sprintf("%02d", time.Now().Minute())
docs.SwaggerInfo.Version = "Ver: 1.0, date: " + date
docs.SwaggerInfo.Host = cfg.Api_Url
ginServ := server.New(cfg, loggr)
api := ginServ.Group("/api")
controllers.AddCarTrackController(api)
ginServ.GET("/swagger/*any", FixRequestUri)
srv := &http.Server{
    Addr:    ":" + strconv.Itoa(cfg.Port),
   Handler: ginServ,
}
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
   loggr.Fatal("Cannot Start the HTTP Listener", zap.Error(err))
}

I tried to do update all versions but I could not resolve the issue. Has anyone got such issue and how can I fix this issue? Generated file seems to be ok.

image

@worapolburaphan
Copy link

I also encountered this problem. However, I don't know how it happened. It didn't occur right from the start because it was working fine initially. As I kept writing code continuously without dealing with Swagger, it just happened on its own.

@worapolburaphan
Copy link

@mohanprasathsj I have solved it. Just debug your code to find the error that caused the issue with gin. It could possibly be a middleware problem.

@Etavioxy
Copy link

inspect the network response by F12

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

3 participants