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

fix x-logo vendor extension & parse x-codeSamples from files #760

Merged
merged 36 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f251cf0
fix x-logo vendor extension
Jul 24, 2020
6fc3823
parse x-codeSamples from files
Jul 24, 2020
d3b7a3f
update swag init -h section in readme
Jul 24, 2020
52df97f
add atreugo to list of supported web frameworks
Jul 24, 2020
12fe750
update readme
Jul 24, 2020
690e4ed
update readme
Jul 24, 2020
c1754f2
Merge branch 'master' into vendor-extensions
easonlin404 Aug 3, 2020
b28be34
fix x-logo vendor extension
Jul 24, 2020
0fbd5fd
parse x-codeSamples from files
Jul 24, 2020
277826e
update swag init -h section in readme
Jul 24, 2020
b30fdae
add atreugo to list of supported web frameworks
Jul 24, 2020
e4e06c6
update readme
Jul 24, 2020
7675b2a
update readme
Jul 24, 2020
f08813c
fix linter errors
Aug 4, 2020
beb7622
Merge branch 'vendor-extensions' of github.com:Nerzal/swag into vendo…
Aug 4, 2020
cc26054
fix errors introduced by auto merge
Aug 4, 2020
42a0c89
Merge remote-tracking branch 'origin/master' into vendor-extensions
Aug 11, 2020
45fd0d5
go fmt'd
Aug 11, 2020
9480b7b
fix merge errors
Aug 11, 2020
a27a8c8
Merge remote-tracking branch 'origin/master' into vendor-extensions
Aug 12, 2020
280d30a
fix merge errors
Aug 12, 2020
84a3d81
setCodeExampleDirectory when instanciating a NewOperation
Aug 12, 2020
0fc262a
fix lint error
Aug 12, 2020
e6a10cc
Merge branch 'master' into vendor-extensions
Aug 19, 2020
b7843ef
fix linter warning and update dependencies
Aug 20, 2020
9f47519
add some error checks in tests
Aug 20, 2020
a9260b1
vendor extensions won't be saved with toLower names anymore
Aug 24, 2020
e1ecc4d
validate json when loading code samples from file
Aug 24, 2020
2118dec
remove unused method
Aug 24, 2020
519d484
add negative test for markdown files to make codecov happy
Aug 24, 2020
b0d0cec
Merge branch 'master' into vendor-extensions
easonlin404 Aug 29, 2020
69abb5a
fix tests
Aug 29, 2020
8f84ba8
Merge branch 'master' into vendor-extensions
easonlin404 Oct 4, 2020
748fe12
Merge remote-tracking branch 'origin/master' into vendor-extensions
Oct 4, 2020
0d45116
go mod tidied
Oct 4, 2020
a4fa218
Merge remote-tracking branch 'fork/vendor-extensions' into vendor-ext…
Oct 4, 2020
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
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ 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 Directory you want to parse (default: "./")
--exclude value Exclude directories and files, 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 doc.go) (default: "./docs")
--parseVendor Parse go files in 'vendor' folder, disabled by default
--parseDependency Parse go files in outside dependency folder, disabled by default
--parseInternal Parse go files in internal packages, disabled by default
--parseDepth Dependency parse depth (default: 100)
--generalInfo value, -g value Go file path in which 'swagger general API Info' is written (default: "main.go")
--dir value, -d value Directory you want to parse (default: "./")
--exclude value Exclude directories and files, 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 doc.go) (default: "./docs")
--parseVendor Parse go files in 'vendor' folder, disabled by default (default: false)
--parseDependency Parse go files in outside 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, true by default (default: false)
--parseDepth Dependency parse depth (default: 100)
--help, -h show help (default: false)
```

## Supported Web Frameworks
Expand All @@ -92,6 +96,7 @@ OPTIONS:
- [net/http](https://github.com/swaggo/http-swagger)
- [flamingo](https://github.com/i-love-flamingo/swagger)
- [fiber](https://github.com/arsmn/fiber-swagger)
- [atreugo](https://github.com/Nerzal/atreugo-swagger)

## How to use it with Gin

Expand Down Expand Up @@ -375,6 +380,7 @@ When a short string in your documentation is insufficient, or you need images, c
| header | Header in response that separated by spaces. `return code`,`{param type}`,`data type`,`comment` |
| router | Path definition that separated by spaces. `path`,`[httpMethod]` |
| x-name | The extension key, must be start by x- and take only json value. |
| x-codeSample | Optional Markdown usage. take `file` as parameter. This will then search for a file named like the summary in the given folder. |
| deprecated | Mark endpoint as deprecated. |


Expand Down
30 changes: 19 additions & 11 deletions cmd/swag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
parseVendorFlag = "parseVendor"
parseDependencyFlag = "parseDependency"
markdownFilesFlag = "markdownFiles"
codeExampleFilesFlag = "codeExampleFiles"
parseInternalFlag = "parseInternal"
generatedTimeFlag = "generatedTime"
parseDepthFlag = "parseDepth"
Expand Down Expand Up @@ -67,6 +68,12 @@ var initFlags = []cli.Flag{
Value: "",
Usage: "Parse folder containing markdown files to use as description, disabled by default",
},
&cli.StringFlag{
Name: codeExampleFilesFlag,
Aliases: []string{"cef"},
Value: "",
Usage: "Parse folder containing code example files to use for the x-codeSamples extension, disabled by default",
},
&cli.BoolFlag{
Name: parseInternalFlag,
Usage: "Parse go files in internal packages, disabled by default",
Expand All @@ -92,17 +99,18 @@ func initAction(c *cli.Context) error {
}

return gen.New().Build(&gen.Config{
SearchDir: c.String(searchDirFlag),
Excludes: c.String(excludeFlag),
MainAPIFile: c.String(generalInfoFlag),
PropNamingStrategy: strategy,
OutputDir: c.String(outputFlag),
ParseVendor: c.Bool(parseVendorFlag),
ParseDependency: c.Bool(parseDependencyFlag),
MarkdownFilesDir: c.String(markdownFilesFlag),
ParseInternal: c.Bool(parseInternalFlag),
GeneratedTime: c.Bool(generatedTimeFlag),
ParseDepth: c.Int(parseDepthFlag),
SearchDir: c.String(searchDirFlag),
Excludes: c.String(excludeFlag),
MainAPIFile: c.String(generalInfoFlag),
PropNamingStrategy: strategy,
OutputDir: c.String(outputFlag),
ParseVendor: c.Bool(parseVendorFlag),
ParseDependency: c.Bool(parseDependencyFlag),
MarkdownFilesDir: c.String(markdownFilesFlag),
ParseInternal: c.Bool(parseInternalFlag),
GeneratedTime: c.Bool(generatedTimeFlag),
CodeExampleFilesDir: c.String(codeExampleFilesFlag),
ParseDepth: c.Int(parseDepthFlag),
})
}

Expand Down
1 change: 0 additions & 1 deletion example/celler/controller/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
// @Router /examples/ping [get]
func (c *Controller) PingExample(ctx *gin.Context) {
ctx.String(http.StatusOK, "pong")
return
}

// CalcExample godoc
Expand Down
6 changes: 3 additions & 3 deletions example/markdown/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (

// User example
type User struct {
Id int64
ID int64
Email string
Password string
}

// UsersCollection example
type UsersCollection []User

// APIError example
type APIError struct {
// Error example
type Error struct {
ErrorCode int
ErrorMessage string
CreatedAt time.Time
Expand Down
6 changes: 5 additions & 1 deletion gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Config struct {
// GeneratedTime whether swag should generate the timestamp at the top of docs.go
GeneratedTime bool

// CodeExampleFilesDir used to find code example files, which can be used for x-codeSamples
CodeExampleFilesDir string

// ParseDepth dependency parse depth
ParseDepth int
}
Expand All @@ -78,7 +81,8 @@ func (g *Gen) Build(config *Config) error {

log.Println("Generate swagger docs....")
p := swag.New(swag.SetMarkdownFileDirectory(config.MarkdownFilesDir),
swag.SetExcludedDirsAndFiles(config.Excludes))
swag.SetExcludedDirsAndFiles(config.Excludes),
swag.SetCodeExamplesDirectory(config.CodeExampleFilesDir))
p.PropNamingStrategy = config.PropNamingStrategy
p.ParseVendor = config.ParseVendor
p.ParseDependency = config.ParseDependency
Expand Down
12 changes: 5 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ require (
github.com/KyleBanks/depth v1.2.1
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/ghodss/yaml v1.0.0
github.com/gin-gonic/gin v1.4.0
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/spec v0.19.4
github.com/gin-gonic/gin v1.6.3
github.com/go-openapi/spec v0.19.9
github.com/gofrs/uuid v3.3.0+incompatible
github.com/shopspring/decimal v1.2.0
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.6.1
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
github.com/swaggo/gin-swagger v1.2.0
github.com/urfave/cli/v2 v2.1.1
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59
github.com/urfave/cli/v2 v2.2.0
golang.org/x/tools v0.0.0-20200820010801-b793a1359eac
)

go 1.13
Loading