Skip to content

Commit

Permalink
refactor(swag): flat project package
Browse files Browse the repository at this point in the history
  • Loading branch information
easonlin404 committed Aug 3, 2017
1 parent d1a8e20 commit 69b53ce
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ before_install:

script:
- go test -race -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion cmd/swag/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"os"

"github.com/swaggo/swag/gen"
"github.com/urfave/cli"
"os"
)

func main() {
Expand Down
4 changes: 1 addition & 3 deletions example/pet/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package main


// @title Swagger Petstore
// @version 1.0
// @description This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
// @description This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key 'special-key' to test the authorization filters.
// @termsOfService http://swagger.io/terms/

// @contact.email [email protected]
Expand All @@ -16,5 +15,4 @@ package main
// @schemes http https
func main() {


}
3 changes: 0 additions & 3 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package swag

import (
"encoding/json"
"fmt"
"go/ast"
"testing"

Expand Down Expand Up @@ -113,7 +112,6 @@ func TestParseResponseCommentWithArrayType(t *testing.T) {
err := operation.ParseComment(comment)
assert.NoError(t, err)
response := operation.Responses.StatusCodeResponses[200]
fmt.Printf("%+v\n", operation)
assert.Equal(t, `Error message, if code != 200`, response.Description)
assert.Equal(t, spec.StringOrArray{"array"}, response.Schema.Type)

Expand Down Expand Up @@ -141,7 +139,6 @@ func TestParseResponseCommentWithBasicType(t *testing.T) {
operation := NewOperation()
operation.ParseComment(comment)
b, _ := json.MarshalIndent(operation, "", " ")
fmt.Printf("%+v", string(b))

expected := `{
"responses": {
Expand Down
5 changes: 2 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ func (parser *Parser) ParseGeneralApiInfo(mainApiFile string) {
}
}


func GetSchemes(commentLine string)[]string {
func GetSchemes(commentLine string) []string {
attribute := strings.ToLower(strings.Split(commentLine, " ")[0])
return strings.Split(strings.TrimSpace(commentLine[len(attribute):])," ")
return strings.Split(strings.TrimSpace(commentLine[len(attribute):]), " ")
}

// parseRouterApiInfo parses router api info for gived astFile
Expand Down
33 changes: 28 additions & 5 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"fmt"
)

func TestNew(t *testing.T) {
Expand Down Expand Up @@ -80,7 +79,8 @@ func TestParser_ParseType(t *testing.T) {
}

func TestGetSchemes(t *testing.T) {
fmt.Println(GetSchemes("@schemes http https"))
//TODO:
//fmt.Println(GetSchemes("@schemes http https"))

}
func TestParseSimpleApi(t *testing.T) {
Expand Down Expand Up @@ -261,12 +261,35 @@ func TestParseSimpleApi(t *testing.T) {
}

func TestParsePetApi(t *testing.T) {
expected:=`{
"schemes": [
"http",
"https"
],
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key 'special-key' to test the authorization filters.",
"title": "Swagger Petstore",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "petstore.swagger.io",
"basePath": "/v2",
"paths": {}
}`
searchDir := "example/pet"
mainApiFile := "main.go"
p := New()
p.ParseApi(searchDir, mainApiFile)

b, _ := json.MarshalIndent(p.swagger, "", " ")
//assert.Equal(t, expected, string(b))
fmt.Println(string(b))
}
assert.Equal(t, expected, string(b))
//fmt.Println(string(b))
}
2 changes: 1 addition & 1 deletion swagger/swagger.go → swagger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package swagger
package swag

import (
"errors"
Expand Down
5 changes: 3 additions & 2 deletions swagger/swagger_test.go → swagger_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package swagger
package swag

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

var doc = `{
Expand Down

0 comments on commit 69b53ce

Please sign in to comment.