捕获的语法错误:无效的正则表达式:在使用go-swagger时缺少/。

huangapple go评论105阅读模式
英文:

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

问题

我正在尝试实现go-swagger,但是一直出现这个错误。我正在使用Windows机器。我非常感谢任何帮助。

我的实现代码:

  1. opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
  2. sh := middleware.Redoc(opts, nil)
  3. getRouter.Handle("/docs", sh)
  4. getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))

我的Swagger定义:

  1. // Product API的包分类。
  2. //
  3. // Product API的文档
  4. // Schemes: http
  5. // BasePath: /
  6. // version: 1.0.0
  7. //
  8. // Consumes:
  9. // - application/json
  10. //
  11. // Produces:
  12. // - application/json
  13. // swagger:meta

错误信息:

捕获的语法错误:无效的正则表达式:在使用go-swagger时缺少/。

英文:

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

My implementation:

  1. opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
  2. sh := middleware.Redoc(opts, nil)
  3. getRouter.Handle("/docs", sh)
  4. getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))

My swagger definition:

  1. // Package classification of Product API.
  2. //
  3. // Documentation for Product API
  4. // Schemes: http
  5. // BasePath: /
  6. // version: 1.0.0
  7. //
  8. // Consumes:
  9. // - application/json
  10. //
  11. // Produces:
  12. // - application/json
  13. // swagger:meta

Error message:

捕获的语法错误:无效的正则表达式:在使用go-swagger时缺少/。

答案1

得分: 0

Redoc的选项应该是SpecURL,而不是RedocURL

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

而不是

  1. opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
英文:

The option of Redoc must be

SpecURL

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

instead of RedocURL

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

huangapple
  • 本文由 发表于 2021年12月7日 17:04:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/70257369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定