rajr/go-swagger

By rajr

Updated over 6 years ago

go-swagger made into a container

Image
0

54

go-swagger made into a container

  • https://goswagger.io/ This container can be used generate server & client side code from a Swagger2.0 (OpenAPI2.0) model.
Dockerfile
FROM golang:1.10.3-alpine3.7
MAINTAINER RajR

RUN apk add bash
ADD https://github.com/go-swagger/go-swagger/releases/download/0.14.0/swagger_linux_amd64 /usr/bin/swagger
RUN chmod +x /usr/bin/swagger

WORKDIR /go/src
CMD ["swagger"]
How to Run
  • Server can be generated to a directory - say gen as follows
$ mkdir gen
$ docker run -it --rm -v $(pwd):/go/src/helloworld_app -w /go/src/helloworld_app rajr/go-swagger \
>  swagger generate server --exclude-main -A helloworld -t gen -f swagger.yaml


  • Client can be generated by running
$ mkdir gen
$ docker run -it --rm -v $(pwd):/go/src/helloworld_app -w /go/src/helloworld_app rajr/go-swagger \
> swagger generate client -A helloworld -t gen -f ./models/swagger/swagger.yaml


  • A complete run example

$ ls 
hello-world.yang  swagger.yaml
$ mkdir gen
$ docker run -it --rm -v $(pwd):/go/src/helloworld_app -w /go/src/helloworld_app rajr/go-swagger \
>  swagger generate server --exclude-main -A helloworld -t gen -f swagger.yaml
$ ls -R
.:
gen  hello-world.yang  swagger.yaml

./gen:
models  restapi

./gen/models:
get_helloworld_helloworld_o_k_body.go    patch_helloworld_helloworld_params_body.go  put_helloworld_helloworld_params_body.go
patch_helloworld_helloworld_o_k_body.go  put_helloworld_helloworld_o_k_body.go

./gen/restapi:
configure_helloworld.go  doc.go  embedded_spec.go  operations  server.go

./gen/restapi/operations:
helloworld  helloworld_api.go

./gen/restapi/operations/helloworld:
delete_helloworld_helloworld.go             get_helloworld_helloworld.go             patch_helloworld_helloworld.go             put_helloworld_helloworld.go
delete_helloworld_helloworld_parameters.go  get_helloworld_helloworld_parameters.go  patch_helloworld_helloworld_parameters.go  put_helloworld_helloworld_parameters.go
delete_helloworld_helloworld_responses.go   get_helloworld_helloworld_responses.go   patch_helloworld_helloworld_responses.go   put_helloworld_helloworld_responses.go
delete_helloworld_helloworld_urlbuilder.go  get_helloworld_helloworld_urlbuilder.go  patch_helloworld_helloworld_urlbuilder.go  put_helloworld_helloworld_urlbuilder.go
$ 

Docker Pull Command

docker pull rajr/go-swagger