https://github.com/mikunalpha/mswagger
Generate swagger 2.0 json file using golang.
https://github.com/mikunalpha/mswagger
golang swagger
Last synced: 3 months ago
JSON representation
Generate swagger 2.0 json file using golang.
- Host: GitHub
- URL: https://github.com/mikunalpha/mswagger
- Owner: mikunalpha
- License: other
- Created: 2016-08-03T07:36:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-24T09:32:34.000Z (about 7 years ago)
- Last Synced: 2025-01-30T00:41:21.512Z (5 months ago)
- Topics: golang, swagger
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Maybe you can try [github.com/mikunalpha/goas](https://github.com/mikunalpha/goas)
# mswagger
Based on [yvasiyarov/swagger](https://github.com/yvasiyarov/swagger) repository.## Todo
1. ~~Support to parse vendor folder.~~
2. ~~Generate swagger 2.0 json file.~~
3. ~~Fix mappings of some field type with swagger-ui.~~## Usage
Comments in main.go
```go
// @Version 1.0.0
// @Title Backend API
// @Description API usually works as expected. But sometimes its not true.
// @BasePath /
// @Schemes http,https
// @ContactName Abcd
// @ContactEmail [email protected]
// @ContactURL http://someurl.oxox
// @TermsOfServiceUrl http://someurl.oxox
// @LicenseName MIT
// @LicenseURL https://en.wikipedia.org/wiki/MIT_License
```
Comments for API handleFunc
```go
type User struct {
Id uint64 `json:"id"`
Name string `json:"name"`
}type UsersResponse struct {
Data []Users `json:"users"`
}type Error struct {
Code string `json:"code"`
Msg string `json:"msg"`
}type ErrorResponse struct {
ErrorInfo Error `json:"error"`
}// @Title Get user list of a group.
// @Resource users "Normal user of this system"
// @Description Get users related to a specific group.
// @Param group_id path int true "Id of a specific group."
// @Success 200 {object} UsersResponse "UsersResponse JSON"
// @Failure 400 {object} ErrorResponse "ErrorResponse JSON"
// @Produce json
// @Router /api/group/{group_id}/users [get]
func GetGroupUsers() {
// ...
}// @Title Get user list of a group.
// @Resource users
// @Description Create a new user.
// @Param user body User true "Info of a user."
// @Success 200 {object} User "UsersResponse JSON"
// @Failure 400 {object} ErrorResponse "ErrorResponse JSON"
// @Produce json
// @Router /api/user [post]
func PostUser() {
// ...
}
```
Code in main.go
```go
import "github.com/mikunalpha/mswagger"// ...
params := mswagger.Params{
ApiPackage: "your/pacakge/name",
MainApiFile: "your/pacakge/name/main.go",
OutputPath: "./swagger.json",
}if err := mswagger.Run(params); err != nil {
fmt.Println(err)
}
// ...
```