How to expose swagger.json with go-swagger server?

Viewed 1079

I'm using go-swagger to generate the API server. I noticed that the json generated from swagger.yml is being kept in restapi/embedded_spec.go.

What's the best way to expose that JSON spec so my ReactJS client can access it?

So far I've had to use swagger serve swagger.yml --port=50000 and point javacript client to localhost:50000/swagger.json. I'm looking for a way to serve that JSON straight from restapi/embedded_spec.go via my API.

1 Answers

Maybe this is from an old code point of view, but currently when running a server the swagger.json file is provided as well.

$ go run cmd/swagger-petstore-server/main.go --port=50000
2018/09/20 12:48:35 Serving swagger petstore at http://127.0.0.1:50000

$ curl http://127.0.0.1:50000/swagger.json
{
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
...
Related