Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahlusar1989/swagger-ui
Swagger Server POC
https://github.com/ahlusar1989/swagger-ui
golang open-api open-api-specification swagger swagger-codegen swagger-specification swagger-ui
Last synced: about 1 month ago
JSON representation
Swagger Server POC
- Host: GitHub
- URL: https://github.com/ahlusar1989/swagger-ui
- Owner: ahlusar1989
- Created: 2018-07-28T19:03:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-29T13:49:17.000Z (over 6 years ago)
- Last Synced: 2024-10-01T00:05:05.121Z (about 2 months ago)
- Topics: golang, open-api, open-api-specification, swagger, swagger-codegen, swagger-specification, swagger-ui
- Language: Go
- Size: 14.1 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swagger Server POC
Step 1: Install go-swagger
* `
brew tap go-swagger/go-swagger &&
brew install go-swagger
`Step 2: Install dependencies using Glide (install using `brew install glide`)
`glide install`
Step 3:
`go build main.go`
Step 4:
`go run main.go`
# Generating a Server
## Resources used to create Swagger YAML that includes definitions and operations:
* [Swagger Toolbox](https://swagger-toolbox.firebaseapp.com/) - YAML --> JSONIn order to generate a server:
`swagger generate server -f ./swagger/swagger.yml`
This command will spill out the actions it takes as it generates your new REST server. Do not follow the advice at the end of the output. There’s an alternate mechanism to do so. Just use glide to update dependencies: `glide up -v`.
# Generating the UI
## Downloading SwaggerUI files
SwaggerUI can be downloaded from their GitHub Repo. Once downloaded, place the content of dist folder somewhere in your Go project. Then generate the spec:
`swagger generate spec -o ./swagger/swagger.json --scan-models`
After that, move swagger.json file to swaggerui folder, and inside index.html change url to ./swagger.json (url: "./swagger.json").
The `main.go` has two go routines that spin up two goroutines - one for each server.
The Swagger UI dist is served using the following logic and handler function:
```
fs := http.FileServer(http.Dir("./swaggerui"))
http.Handle("/swaggerui/", http.StripPrefix("/swaggerui/", fs))
```