Skip to content

Commit

Permalink
Add --parseInternal flag to support internal underlying types (swaggo…
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpart committed Sep 4, 2019
1 parent 4f860d7 commit df54d45
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -74,6 +74,7 @@ OPTIONS:
--output value, -o value Output directory for al 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
```

## Supported Web Frameworks
Expand Down
7 changes: 7 additions & 0 deletions cmd/swag/main.go
Expand Up @@ -16,6 +16,7 @@ const propertyStrategyFlag = "propertyStrategy"
const outputFlag = "output"
const parseVendorFlag = "parseVendor"
const parseDependency = "parseDependency"
const parseInternal = "parseInternal"
const markdownFilesDirFlag = "markdownFiles"

func main() {
Expand All @@ -34,6 +35,7 @@ func main() {
outputDir := c.String(outputFlag)
parseVendor := c.Bool(parseVendorFlag)
parseDependency := c.Bool(parseDependency)
parseInternal := c.Bool(parseInternal)
markdownFilesDir := c.String(markdownFilesDirFlag)

switch strategy {
Expand All @@ -49,6 +51,7 @@ func main() {
OutputDir: outputDir,
ParseVendor: parseVendor,
ParseDependency: parseDependency,
ParseInternal: parseInternal,
MarkdownFilesDir: markdownFilesDir,
})
},
Expand Down Expand Up @@ -81,6 +84,10 @@ func main() {
Name: "parseDependency",
Usage: "Parse go files in outside dependency folder, disabled by default",
},
cli.BoolFlag{
Name: "parseInternal",
Usage: "Parse go files in internal packages, disabled by default",
},
cli.StringFlag{
Name: "markdownFiles, md",
Value: "",
Expand Down
4 changes: 4 additions & 0 deletions gen/gen.go
Expand Up @@ -47,6 +47,9 @@ type Config struct {
// ParseDependencies whether swag should be parse outside dependency folder
ParseDependency bool

// ParseInternal whether swag should parse internal packages
ParseInternal bool

// MarkdownFilesDir used to find markdownfiles, which can be used for tag descriptions
MarkdownFilesDir string
}
Expand All @@ -62,6 +65,7 @@ func (g *Gen) Build(config *Config) error {
p.PropNamingStrategy = config.PropNamingStrategy
p.ParseVendor = config.ParseVendor
p.ParseDependency = config.ParseDependency
p.ParseInternal = config.ParseInternal

if err := p.ParseAPI(config.SearchDir, config.MainAPIFile); err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion parser.go
Expand Up @@ -59,6 +59,9 @@ type Parser struct {
// ParseDependencies whether swag should be parse outside dependency folder
ParseDependency bool

// ParseInternal whether swag should parse internal packages
ParseInternal bool

// structStack stores full names of the structures that were already parsed or are being parsed now
structStack []string

Expand Down Expand Up @@ -112,6 +115,7 @@ func (parser *Parser) ParseAPI(searchDir string, mainAPIFile string) error {
}

var t depth.Tree
t.ResolveInternal = true

absMainAPIFilePath, err := filepath.Abs(filepath.Join(searchDir, mainAPIFile))
if err != nil {
Expand Down Expand Up @@ -1281,7 +1285,8 @@ func (parser *Parser) getAllGoFileInfo(searchDir string) error {
}

func (parser *Parser) getAllGoFileInfoFromDeps(pkg *depth.Pkg) error {
if pkg.Internal || !pkg.Resolved { // ignored internal and not resolved dependencies
ignoreInternal := pkg.Internal && !parser.ParseInternal
if ignoreInternal || !pkg.Resolved { // ignored internal and not resolved dependencies
return nil
}

Expand Down

0 comments on commit df54d45

Please sign in to comment.