# swag
ð *[English](README.md) â [ç®ä½ä¸æ](README_zh-CN.md)*
<img align="right" width="180px" src="https://raw.githubusercontent.com/swaggo/swag/master/assets/swaggo.png">
[![Build Status](https://github.com/swaggo/swag/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/features/actions)
[![Coverage Status](https://img.shields.io/codecov/c/github/swaggo/swag/master.svg)](https://codecov.io/gh/swaggo/swag)
[![Go Report Card](https://goreportcard.com/badge/github.com/swaggo/swag)](https://goreportcard.com/report/github.com/swaggo/swag)
[![codebeat badge](https://codebeat.co/badges/71e2f5e5-9e6b-405d-baf9-7cc8b5037330)](https://codebeat.co/projects/github-com-swaggo-swag-master)
[![Go Doc](https://godoc.org/github.com/swaggo/swagg?status.svg)](https://godoc.org/github.com/swaggo/swag)
[![Backers on Open Collective](https://opencollective.com/swag/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/swag/sponsors/badge.svg)](#sponsors) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fswaggo%2Fswag.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fswaggo%2Fswag?ref=badge_shield)
[![Release](https://img.shields.io/github/release/swaggo/swag.svg?style=flat-square)](https://github.com/swaggo/swag/releases)
Swag converts Go annotations to Swagger Documentation 2.0. We've created a variety of plugins for popular [Go web frameworks](#supported-web-frameworks). This allows you to quickly integrate with an existing Go project (using Swagger UI).
## Contents
- [Getting started](#getting-started)
- [Supported Web Frameworks](#supported-web-frameworks)
- [How to use it with Gin](#how-to-use-it-with-gin)
- [The swag formatter](#the-swag-formatter)
- [Implementation Status](#implementation-status)
- [Declarative Comments Format](#declarative-comments-format)
- [General API Info](#general-api-info)
- [API Operation](#api-operation)
- [Security](#security)
- [Examples](#examples)
- [Descriptions over multiple lines](#descriptions-over-multiple-lines)
- [User defined structure with an array type](#user-defined-structure-with-an-array-type)
- [Function scoped struct declaration](#function-scoped-struct-declaration)
- [Model composition in response](#model-composition-in-response)
- [Add a headers in response](#add-a-headers-in-response)
- [Use multiple path params](#use-multiple-path-params)
- [Example value of struct](#example-value-of-struct)
- [SchemaExample of body](#schemaexample-of-body)
- [Description of struct](#description-of-struct)
- [Use swaggertype tag to supported custom type](#use-swaggertype-tag-to-supported-custom-type)
- [Use global overrides to support a custom type](#use-global-overrides-to-support-a-custom-type)
- [Use swaggerignore tag to exclude a field](#use-swaggerignore-tag-to-exclude-a-field)
- [Add extension info to struct field](#add-extension-info-to-struct-field)
- [Rename model to display](#rename-model-to-display)
- [How to use security annotations](#how-to-use-security-annotations)
- [Add a description for enum items](#add-a-description-for-enum-items)
- [Generate only specific docs file types](#generate-only-specific-docs-file-types)
- [About the Project](#about-the-project)
## Getting started
1. Add comments to your API source code, See [Declarative Comments Format](#declarative-comments-format).
2. Download swag by using:
```sh
$ go install github.com/swaggo/swag/cmd/swag@latest
```
To build from source you need [Go](https://golang.org/dl/) (1.16 or newer).
Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases).
3. Run `swag init` in the project's root folder which contains the `main.go` file. This will parse your comments and generate the required files (`docs` folder and `docs/docs.go`).
```sh
$ swag init
```
Make sure to import the generated `docs/docs.go` so that your specific configuration gets `init`'ed. If your General API annotations do not live in `main.go`, you can let swag know with `-g` flag.
```sh
swag init -g http/api.go
```
4. (optional) Use `swag fmt` format the SWAG comment. (Please upgrade to the latest version)
```sh
swag fmt
```
## swag cli
```sh
$ swag init -h
NAME:
swag init - Create docs.go
USAGE:
swag init [command options] [arguments...]
OPTIONS:
--generalInfo value, -g value Go file path in which 'swagger general API Info' is written (default: "main.go")
--dir value, -d value Directories you want to parse,comma separated and general-info file must be in the first one (default: "./")
--exclude value Exclude directories and files when searching, comma separated
--propertyStrategy value, -p value Property Naming Strategy like snakecase,camelcase,pascalcase (default: "camelcase")
--output value, -o value Output directory for all the generated files(swagger.json, swagger.yaml and docs.go) (default: "./docs")
--outputTypes value, --ot value Output types of generated files (docs.go, swagger.json, swagger.yaml) like go,json,yaml (default: "go,json,yaml")
--parseVendor Parse go files in 'vendor' folder, disabled by default (default: false)
--parseDependency, --pd Parse go files inside dependency folder, disabled by default (default: false)
--markdownFiles value, --md value Parse folder containing markdown files to use as description, disabled by default
--codeExampleFiles value, --cef value Parse folder containing code example files to use for the x-codeSamples extension, disabled by default
--parseInternal Parse go files in internal packages, disabled by default (default: false)
--generatedTime Generate timestamp at the top of docs.go, disabled by default (default: false)
--requiredByDefault Set validation required for all fields by default (default: false)
--parseDepth value Dependency parse depth (default: 100)
--instanceName value This parameter can be used to name different swagger document instances. It is optional.
--overridesFile value File to read global type overrides from. (default: ".swaggo")
--help, -h show help (default: false)
```
```bash
swag fmt -h
NAME:
swag fmt - format swag comments
USAGE:
swag fmt [command options] [arguments...]
OPTIONS:
--dir value, -d value Directories you want to parse,comma separated and general-info file must be in the first one (default: "./")
--exclude value Exclude directories and files when searching, comma separated
--generalInfo value, -g value Go file path in which 'swagger general API Info' is written (default: "main.go")
--help, -h show help (default: false)
```
## Supported Web Frameworks
- [gin](http://github.com/swaggo/gin-swagger)
- [echo](http://github.com/swaggo/echo-swagger)
- [buffalo](https://github.com/swaggo/buffalo-swagger)
- [net/http](https://github.com/swaggo/http-swagger)
- [gorilla/mux](https://github.com/swaggo/http-swagger)
- [go-chi/chi](https://github.com/swaggo/http-swagger)
- [flamingo](https://github.com/i-love-flamingo/swagger)
- [fiber](https://github.com/gofiber/swagger)
- [atreugo](https://github.com/Nerzal/atreugo-swagger)
## How to use it with Gin
Find the example source code [here](https://github.com/swaggo/swag/tree/master/example/celler).
1. After using `swag init` to generate Swagger 2.0 docs, import the following packages:
```go
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
import "github.com/swaggo/files" // swagger embed files
```
2. Add [General API](#general-api-info) annotations in `main.go` code:
```go
// @title Swagger Example API
// @version 1.0
// @description This is a sample server celle
没有合适的资源?快使用搜索试试~ 我知道了~
专为AI能力开发者打造的AI算法模型、引擎的通用服务化工具
共2000个文件
go:1837个
md:120个
sh:14个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 15 浏览量
2023-10-08
14:43:40
上传
评论
收藏 21.89MB ZIP 举报
温馨提示
专为AI能力开发者打造的AI算法模型、引擎的通用服务化工具。
资源推荐
资源详情
资源评论
收起资源包目录
专为AI能力开发者打造的AI算法模型、引擎的通用服务化工具 (2000个子文件)
api.go 1.58MB
defaults.go 708KB
tables13.0.0.go 278KB
tables12.0.0.go 273KB
tables11.0.0.go 271KB
tables10.0.0.go 267KB
tables9.0.0.go 263KB
avx_optabs.go 260KB
asmz.go 174KB
asm7.go 173KB
api.go 156KB
fast-path.generated.go 154KB
asm9.go 148KB
asm6.go 146KB
vm.go 134KB
vm.go 134KB
vm.go 134KB
vm.go 134KB
country_codes.go 91KB
assembler_amd64_go116.go 88KB
helper.go 86KB
assembler_amd64_go117.go 86KB
gen.go 85KB
asm5.go 78KB
baked_in.go 73KB
gjson.go 68KB
decode.go 67KB
commands.go 63KB
spec091.go 58KB
obj.go 56KB
asm0.go 54KB
profile_vtproto.pb.go 53KB
xsf.pb.go 50KB
node.go 50KB
v2.pb.go 48KB
channel.go 48KB
assembler_amd64_go116.go 47KB
assembler_amd64_go117.go 46KB
api.go 46KB
xml.go 45KB
schema.go 43KB
dwarf.go 43KB
parser.go 42KB
helper_unsafe.go 41KB
encode.go 40KB
generic_amd64_go116.go 39KB
generic_amd64_go117.go 38KB
profile.pb.go 38KB
cfg_parser.go 38KB
command.go 37KB
context.go 37KB
json.go 36KB
doc.go 35KB
sysRegEnc.go 35KB
marshal.go 35KB
simple_json_protocol.go 35KB
optype.go 35KB
conn.go 34KB
operation.go 34KB
obj6.go 33KB
xsfserver.go 33KB
session.go 33KB
loader.go 33KB
handler.go 32KB
cluster.go 32KB
conn.go 32KB
binc.go 32KB
cpuid.go 32KB
msgpack.go 31KB
conn.go 31KB
registry.go 31KB
obj9.go 31KB
loader.go 30KB
compiler.go 30KB
client.go 30KB
reflect_struct_decoder.go 29KB
unmarshaler.go 29KB
wasmobj.go 29KB
lex.go 29KB
obj0.go 29KB
trace.go 28KB
v4.go 28KB
process_linux.go 27KB
compiler.go 26KB
exec.go 26KB
inst.go 26KB
machine.go 25KB
text_parse.go 25KB
obj7.go 25KB
process_windows.go 25KB
colorable_windows.go 25KB
bindata.go 24KB
link.go 24KB
lexer.go 24KB
parser.go 24KB
summary.go 24KB
compress_generic.go 24KB
compiler.go 24KB
validator_instance.go 24KB
metrics.pb.go 23KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6718
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功