Files
go-zero/tools/goctl/pkg/parser/api/parser/testdata/example.api
2024-01-11 15:50:53 +00:00

191 lines
3.2 KiB
Plaintext

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"`
}
RootReq{
}
RootResp{
}
)
@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)
@handler root
post / (RootReq) returns (RootResp)
}
@server (
group: path2
middleware: Path
prefix: /v1/v3
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)
}