This is my take on the at goswagger.com.
- Create initial swagger.yml file:
swagger init spec --title "Todo list" --description "Sample todo list app" --version 1.0.0 --scheme http --consumes application/com.thesaleem.examples.todo-list.v1+json --produces application/com.thesaleem.examples.todo.list.v1+json
-
Edit it as as instructed in the tutorial, or as you wish.
-
Create a go module:
go mod init com.thesaleem/examples/todo-list
- Generate swagger server:
swagger generate server -A todo-list -f ./swagger.yml
This should print out a lot of stuff, ending with two missing packages that you need to get.
- Get the missing packages, like this:
go get -u -f ./...
- Install the generated server:
go install ./cmd/todo-list-server/
This will generate a runnable todo-list-server
and put it in your $GOPATH/bin
folder. Verify it by doing ls -la $GOPATH/bin/todo-list-server
. You should not get a No such file or directory
- Run the server:
$GOPATH/bin/todo-list-server
This should launch the http server and show you something like this:
Serving todo list at http://127.0.0.1:54439
- Test your server:
curl http://127.0.0.1:54439
This should return "operation TodosGet has not yet been implemented"
. This is understandable, because we haven't written any implementation for our todo-list yet. However, the API documentation is being served.