1

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

BlackLotus
  • 318
  • 4
  • 12
  • I don't quite understand what you are trying to do exactly and your swagger definition is malformed – Vorsprung Dec 07 '21 at 09:28
  • That's go-swagger annotation: https://goswagger.io/use/spec/meta.html It will automatically generate `swagger.yaml` file. I'm trying to combine swagger and Redoc, Redoc require `swagger.yaml` so i need to create a handler to it using `FileServer` – BlackLotus Dec 07 '21 at 09:40
  • 1
    The file on the image seems to be named `inpage.js` (not `swagger.yaml`) so the browser tries to parse it as JavaScript and that's where the "Invalid regular expression" error comes from. Double-check the configs that control the output file name and routing. – Helen Dec 07 '21 at 09:48
  • Thank you for the suggestion. I'm checking on that. – BlackLotus Dec 07 '21 at 09:58

1 Answers1

0

The option of Redoc must be

SpecURL

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

instead of RedocURL

opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
BlackLotus
  • 318
  • 4
  • 12