Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying version of documents #1947

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/swag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
packagePrefixFlag = "packagePrefix"
stateFlag = "state"
parseFuncBodyFlag = "parseFuncBody"
versionFlag = "version"
)

var initFlags = []cli.Flag{
Expand Down Expand Up @@ -186,6 +187,11 @@ var initFlags = []cli.Flag{
// Value: false,
Usage: "Parse API info within body of functions in go files, disabled by default (default: false)",
},
&cli.StringFlag{
Name: versionFlag,
Value: "",
Usage: "Specify the version of the version of the API in the generated files",
},
}

func initAction(ctx *cli.Context) error {
Expand Down Expand Up @@ -268,6 +274,7 @@ func initAction(ctx *cli.Context) error {
PackagePrefix: ctx.String(packagePrefixFlag),
State: ctx.String(stateFlag),
ParseFuncBody: ctx.Bool(parseFuncBodyFlag),
Version: ctx.String(versionFlag),
})
}

Expand Down
6 changes: 6 additions & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Config struct {

// ParseFuncBody whether swag should parse api info inside of funcs
ParseFuncBody bool

// Version represents the version of the API in the generated swagger documents
Version string
}

// Build builds swagger json file for given searchDir and mainAPIFile. Returns json.
Expand Down Expand Up @@ -223,6 +226,9 @@ func (g *Gen) Build(config *Config) error {
}

swagger := p.GetSwagger()
if config.Version != "" {
swagger.Info.Version = config.Version
}

if err := os.MkdirAll(config.OutputDir, os.ModePerm); err != nil {
return err
Expand Down