Skip to content

Commit

Permalink
refactor(swag): flat package instead of multi package
Browse files Browse the repository at this point in the history
  • Loading branch information
easonlin404 committed Aug 2, 2017
1 parent 4309752 commit eb7f3ca
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 26 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/simple/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2017-07-20 00:19:59.756080528 +0800 CST
// 2017-08-03 00:44:10.090091728 +0800 CST

package docs

Expand Down
4 changes: 2 additions & 2 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func New() *Gen {
return &Gen{}
}

func (g *Gen) Build(searchDir, mainApiFile string) {
//TODO: not use log.Println
func (g *Gen) Build(searchDir, mainApiFile string) error {
log.Println("Generate swagger docs....")
p := parser.New()
p.ParseApi(searchDir, mainApiFile)
Expand All @@ -40,6 +39,7 @@ func (g *Gen) Build(searchDir, mainApiFile string) {
})

log.Printf("create docs.go at %+v", docs.Name())
return nil
}

var packageTemplate = template.Must(template.New("").Parse(`// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
Expand Down
2 changes: 1 addition & 1 deletion parser/operation.go → operation.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package parser
package swag

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion parser/operation_test.go → operation_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package parser
package swag

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.go → parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package parser
package swag

import (
"go/ast"
Expand Down
14 changes: 7 additions & 7 deletions parser/parser_test.go → parser_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package parser
package swag

import (
"encoding/json"
Expand Down Expand Up @@ -54,18 +54,18 @@ func TestParser_ParseGeneralApiInfoFailed(t *testing.T) {
}

func TestGetAllGoFileInfo(t *testing.T) {
searchDir := "../example/simple"
searchDir := "example/simple"

p := New()
p.getAllGoFileInfo(searchDir)

assert.NotEmpty(t, p.files["../example/simple/main.go"])
assert.NotEmpty(t, p.files["../example/simple/web/handler.go"])
assert.NotEmpty(t, p.files["example/simple/main.go"])
assert.NotEmpty(t, p.files["example/simple/web/handler.go"])
assert.Equal(t, 4, len(p.files))
}

func TestParser_ParseType(t *testing.T) {
searchDir := "../example/simple/"
searchDir := "example/simple/"

p := New()
p.getAllGoFileInfo(searchDir)
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestParseSimpleApi(t *testing.T) {
}
}
}`
searchDir := "../example/simple"
searchDir := "example/simple"
mainApiFile := "main.go"
p := New()
p.ParseApi(searchDir, mainApiFile)
Expand All @@ -261,7 +261,7 @@ func TestParseSimpleApi(t *testing.T) {
}

func TestParsePetApi(t *testing.T) {
searchDir := "../example/pet"
searchDir := "example/pet"
mainApiFile := "main.go"
p := New()
p.ParseApi(searchDir, mainApiFile)
Expand Down
2 changes: 1 addition & 1 deletion parser/property.go → property.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package parser
package swag

import (
"go/ast"
Expand Down
12 changes: 0 additions & 12 deletions test.sh

This file was deleted.

File renamed without changes.

0 comments on commit eb7f3ca

Please sign in to comment.