Home > Net >  Uncaught SyntaxError: Invalid regular expression: missing / when using go-swagger
Uncaught SyntaxError: Invalid regular expression: missing / when using go-swagger

Time:12-10

I'm trying to implement go-swagger but this error keep flashing. I'm using windows machine. I appreciate any help.

My implementation:

opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
sh := middleware.Redoc(opts, nil)

getRouter.Handle("/docs", sh)
getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))

My swagger definition:

// Package classification of Product API.
//
// Documentation for Product API
// Schemes: http
// BasePath: /
// version: 1.0.0
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// swagger:meta

Error message:

enter image description here

CodePudding user response:

The option of Redoc must be

SpecURL

opts := middleware.RedocOpts{SpecURL: "/swagger.yaml"}

instead of RedocURL

opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
  • Related