type should not define nested (#212)

* nest type should not supported

* nest type should not supported

* nest type should not supported

* nest type should not supported

* new test

* new test
This commit is contained in:
kingxt
2020-11-17 18:08:55 +08:00
committed by GitHub
parent 9592639cb4
commit d6d8fc21d8
5 changed files with 88 additions and 29 deletions

View File

@@ -288,13 +288,16 @@ type Request {
Name string ` + "`" + `path:"name,options=you|me"` + "`" + `
}
type XXX {
}
type XXX {}
type (
Response {
Message string ` + "`" + `json:"message"` + "`" + `
}
A {}
B struct {}
)
service A-api {
@@ -303,6 +306,19 @@ service A-api {
}
`
const nestTypeApi = `
type Request {
Name string ` + "`" + `path:"name,options=you|me"` + "`" + `
XXX struct {
}
}
service A-api {
@handler GreetHandler
get /greet/from/:name(Request)
}
`
func TestParser(t *testing.T) {
filename := "greet.api"
err := ioutil.WriteFile(filename, []byte(testApiTemplate), os.ModePerm)
@@ -532,11 +548,21 @@ func TestNoStructApi(t *testing.T) {
spec, err := parser.Parse()
assert.Nil(t, err)
assert.Equal(t, len(spec.Types), 3)
assert.Equal(t, len(spec.Types), 5)
validate(t, filename)
}
func TestNestTypeApi(t *testing.T) {
filename := "greet.api"
err := ioutil.WriteFile(filename, []byte(nestTypeApi), os.ModePerm)
assert.Nil(t, err)
defer os.Remove(filename)
_, err = parser.NewParser(filename)
assert.NotNil(t, err)
}
func validate(t *testing.T, api string) {
dir := "_go"
os.RemoveAll(dir)