how to serve go-swagger locally?

Viewed 945

I have a swagger file both in yaml format and json. I can view the yaml file on swaggers online viewer https://editor.swagger.io/ but when I try to serve the file locally I get the error:

webbrowser: tried to open "http://localhost:40335/docs", no screen found

After using the command:

swagger serve -F=swagger swagger.yaml

To recreate this scenario you can clone this repo: https://github.com/go-swagger/go-swagger/tree/master/fixtures/goparsing/petstore

Then run the following commands (MAC-OS) to generate the yaml file:

Note: you may have to run these commands in the root of the project using sudo -s

Instructions for windows installation can be found here https://goswagger.io/install.html

Download go-swagger

  1. docker pull quay.io/goswagger/swagger
  2. alias swagger="docker run --rm -it --user $(id -u):$(id -g) -e GOPATH=$HOME/go:/go -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger"
  3. swagger version to verify installation

Generate swagger Yaml 4.swagger generate spec -o ./swagger.yaml --scan-models

The swagger file should now be generated but for some reason using the command swagger serve -F=swagger swagger.yaml gives the error described above.

1 Answers

Since you are running it inside a docker container and there's no browser in it you are getting the no screen found error.

This can be fixed by passing the --no-open option to swagger serve ....
Also, specify a fixed port by passing the --port option.

Source: https://goswagger.io/usage/serve_ui.html

Related