forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add document & comment for spec (zeromicro#703)
* Add document & comment for spec * remove duplicate field * use alias
- Loading branch information
anqiansong
authored
May 21, 2021
1 parent
f300408
commit 94417be
Showing
5 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package parser | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tal-tech/go-zero/tools/goctl/api/spec" | ||
) | ||
|
||
var testApi = "// syntax doc\nsyntax = \"v1\" // syntax comment\n\n// type doc\ntype Request {\n\tName string `path:\"name,options=you|me\"`\n}\n\ntype Response {\n\tMessage string `json:\"message\"`\n}\n\n// service doc\nservice greet-api {\n\t// handler doc\n\t@handler GreetHandler // handler comment\n\tget /from/:name(Request) returns (Response);\n}" | ||
|
||
func TestParseContent(t *testing.T) { | ||
sp, err := ParseContent(testApi) | ||
assert.Nil(t, err) | ||
assert.Equal(t, spec.Doc{`// syntax doc`}, sp.Syntax.Doc) | ||
assert.Equal(t, spec.Doc{`// syntax comment`}, sp.Syntax.Comment) | ||
for _, tp := range sp.Types { | ||
if tp.Name() == "Request" { | ||
assert.Equal(t, []string{`// type doc`}, tp.Documents()) | ||
} | ||
} | ||
for _, e := range sp.Service.Routes() { | ||
if e.Handler == "GreetHandler" { | ||
assert.Equal(t, spec.Doc{"// handler doc"}, e.HandlerDoc) | ||
assert.Equal(t, spec.Doc{"// handler comment"}, e.HandlerComment) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters