Skip to content

Commit

Permalink
Merge branch 'master' into add-#109
Browse files Browse the repository at this point in the history
  • Loading branch information
pei0804 authored May 28, 2018
2 parents 7622a62 + dbf857a commit 345d9fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
12 changes: 12 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ func (operation *Operation) ParseAcceptComment(commentLine string) error {
operation.Consumes = append(operation.Consumes, "application/x-json-stream")
case "octet-stream", "application/octet-stream":
operation.Consumes = append(operation.Consumes, "application/octet-stream")
case "png", "image/png":
operation.Consumes = append(operation.Consumes, "image/png")
case "jpeg", "image/jpeg":
operation.Consumes = append(operation.Consumes, "image/jpeg")
case "gif", "image/gif":
operation.Consumes = append(operation.Consumes, "image/gif")
default:
return fmt.Errorf("%v accept type can't accepted", a)
}
Expand Down Expand Up @@ -338,6 +344,12 @@ func (operation *Operation) ParseProduceComment(commentLine string) error {
operation.Produces = append(operation.Produces, "application/x-json-stream")
case "octet-stream", "application/octet-stream":
operation.Produces = append(operation.Produces, "application/octet-stream")
case "png", "image/png":
operation.Produces = append(operation.Produces, "image/png")
case "jpeg", "image/jpeg":
operation.Produces = append(operation.Produces, "image/jpeg")
case "gif", "image/gif":
operation.Produces = append(operation.Produces, "image/gif")
default:
return fmt.Errorf("%v produce type can't accepted", a)
}
Expand Down
14 changes: 10 additions & 4 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ func TestParseAcceptComment(t *testing.T) {
"application/x-www-form-urlencoded",
"application/vnd.api+json",
"application/x-json-stream",
"application/octet-stream"
"application/octet-stream",
"image/png",
"image/jpeg",
"image/gif"
]
}`
comment := `/@Accept json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream`
comment := `/@Accept json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream,png,jpeg,gif`
operation := NewOperation()
err := operation.ParseComment(comment)
assert.NoError(t, err)
Expand All @@ -73,10 +76,13 @@ func TestParseProduceComment(t *testing.T) {
"application/x-www-form-urlencoded",
"application/vnd.api+json",
"application/x-json-stream",
"application/octet-stream"
"application/octet-stream",
"image/png",
"image/jpeg",
"image/gif"
]
}`
comment := `/@Produce json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream`
comment := `/@Produce json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream,png,jpeg,gif`
operation := new(Operation)
operation.ParseComment(comment)
b, _ := json.MarshalIndent(operation, "", " ")
Expand Down
2 changes: 2 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ func (parser *Parser) getAllGoFileInfo(searchDir string) {
//exclude vendor folder
if ext := filepath.Ext(path); ext == ".go" &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+"vendor"+string(os.PathSeparator)) &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".history"+string(os.PathSeparator)) &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".idea"+string(os.PathSeparator)) &&
!strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".git"+string(os.PathSeparator)) {
fset := token.NewFileSet() // positions are relative to fset
astFile, err := goparser.ParseFile(fset, path, nil, goparser.ParseComments)
Expand Down

0 comments on commit 345d9fc

Please sign in to comment.