Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #278 from go-dummy/feat/parse-openapi-format
Browse files Browse the repository at this point in the history
feat(parse): add openapi parse case
  • Loading branch information
sashamelentyev authored Jan 25, 2022
2 parents 015730d + a18daf7 commit 2b9763d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ func GetSpecType(path string) (SpecType, error) {

switch splitPath[1] {
case "yml", "yaml":
if err := yaml.Unmarshal(file, &openapi.OpenAPI{}); err == nil {
return OpenAPI, nil
}
var openapi openapi.OpenAPI

return Unknown, &SpecTypeError{
Path: path,
err := yaml.Unmarshal(file, &openapi)
if err != nil || len(openapi.OpenAPI) == 0 {
return Unknown, &SpecTypeError{
Path: path,
}
}

return OpenAPI, nil
case "graphql":
return GraphQL, nil
default:
Expand Down
28 changes: 28 additions & 0 deletions internal/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ func TestParse(t *testing.T) {
Path: "./testdata/openapi",
},
},
{
name: "graphql",
path: "./testdata/schema.graphql",
want: api.API{},
err: nil,
},
{
name: "",
path: "./testdata/empty-openapi.yml",
want: api.API{},
err: &parse.SpecTypeError{
Path: "./testdata/empty-openapi.yml",
},
},
{
name: "",
path: "./testdata/openapi.yml",
want: api.API{},
err: nil,
},
{
name: "unknown format",
path: "./testdata/api.raml",
want: api.API{},
err: &parse.SpecTypeError{
Path: "./testdata/api.raml",
},
},
}

for _, tc := range tests {
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions internal/parse/testdata/openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
openapi: 3.0.3
info:
title: Users dummy API
version: 0.1.0

0 comments on commit 2b9763d

Please sign in to comment.