mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-16 19:28:18 +08:00
feat(goctl): Add api parser (#2585)
This commit is contained in:
167
tools/goctl/pkg/parser/api/parser/testdata/example.api
vendored
Normal file
167
tools/goctl/pkg/parser/api/parser/testdata/example.api
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
syntax = "v1"
|
||||
|
||||
import "example_base1.api"
|
||||
|
||||
import (
|
||||
"example_base2.api"
|
||||
)
|
||||
|
||||
info (
|
||||
title: "type title here"
|
||||
desc: "type desc here"
|
||||
author: "type author here"
|
||||
email: "type email here"
|
||||
version: "type version here"
|
||||
)
|
||||
|
||||
type GetFormReq {
|
||||
Name string `form:"name"`
|
||||
Age int `form:"age"`
|
||||
Hobbits []string `form:"hobbits"`
|
||||
}
|
||||
|
||||
type GetFormREsp {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Hobbits []string `json:"hobbits"`
|
||||
}
|
||||
|
||||
type (
|
||||
PostFormReq {
|
||||
Name string `form:"name"`
|
||||
Age int `form:"age"`
|
||||
Hobbits []string `form:"hobbits"`
|
||||
}
|
||||
PostFormResp {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Hobbits []string `json:"hobbits"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
PostJsonReq {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Hobbits []string `json:"hobbits"`
|
||||
}
|
||||
PostJsonResp {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Hobbits []string `json:"hobbits"`
|
||||
Extra map[string]string `json:"extra"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
PostPathReq {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
PostPathResp {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Hobbits []string `json:"hobbits"`
|
||||
Hobbits2 [2]string `json:"hobbits2"`
|
||||
Extra map[string]string `json:"extra"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
DemoOfArrayReq {
|
||||
In string `json:"in"`
|
||||
}
|
||||
DemoOfArrayResp {
|
||||
Out string `json:"out"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
Nest {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
NestDemoReq1 {
|
||||
Nest *Nest `json:"nest"`
|
||||
}
|
||||
NestDemoResp1 {
|
||||
Nest []*Nest `json:"nest"`
|
||||
}
|
||||
NestDemoReq2 {
|
||||
*Nest
|
||||
}
|
||||
NestDemoResp2 {
|
||||
*Nest `json:"nest"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: form
|
||||
timeout: 3s
|
||||
)
|
||||
service example {
|
||||
@handler getForm
|
||||
get /example/form (GetFormReq) returns (GetFormREsp)
|
||||
|
||||
@handler postForm
|
||||
post /example/form (PostFormReq) returns (PostFormResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: json
|
||||
jwt: Auth
|
||||
timeout: 3m
|
||||
)
|
||||
service example {
|
||||
@doc "json demo"
|
||||
@handler postJson
|
||||
post /example/json (PostJsonReq) returns (PostJsonResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: path
|
||||
middleware: Path
|
||||
prefix: /v1/v2
|
||||
timeout: 100ms
|
||||
)
|
||||
service example {
|
||||
@doc (
|
||||
desc: "path demo"
|
||||
)
|
||||
@handler postPath
|
||||
post /example/path (PostPathReq) returns (PostPathResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: array
|
||||
prefix: /array
|
||||
maxBytes: 1024
|
||||
)
|
||||
service example {
|
||||
@doc (
|
||||
desc: "array response demo"
|
||||
)
|
||||
@handler getArray
|
||||
post /example/array (DemoOfArrayReq) returns ([]DemoOfArrayResp)
|
||||
|
||||
@doc (
|
||||
desc: "array pointer response demo"
|
||||
)
|
||||
@handler getArrayPointer
|
||||
post /example/array/pointer (DemoOfArrayReq) returns ([]*DemoOfArrayResp)
|
||||
|
||||
@doc (
|
||||
desc: "array base response demo"
|
||||
)
|
||||
@handler getArrayBase
|
||||
post /example/array/base (DemoOfArrayReq) returns ([]string)
|
||||
}
|
||||
|
||||
service example {
|
||||
@handler nestDemo1
|
||||
post /example/nest (NestDemoReq1) returns (NestDemoResp1)
|
||||
|
||||
@handler nestDemo2
|
||||
post /example/nest2 (NestDemoReq2) returns (NestDemoResp2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user