-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.api
134 lines (113 loc) · 3.04 KB
/
example.api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
syntax = "v1"
info (
title: "api 文件示例"
desc: "给出尽可能复杂的场景 测试本项目功能"
author: "Lin Zhiwen"
email: "zhiwenlin1116@gmail.com"
date: "2024年03月25日"
version: "v1"
servers: "http://localhost/v1,https://localhost/v2"
externalDocs: "https://github.com/jayvynl/goctl-openapi"
tags: "foo,bar"
)
type ResourceID {
ID int `path:"id" validate:"required"`
}
type PageQuery {
Page uint `form:"page,optional" validate:"min=1,lt=10000"`
PageSize uint `form:"page_size,default=20" validate:"min=1,max=100"`
}
type BaseFilter {
ResourceID
PageQuery
Token string `header:"WWW-Authenticate"`
Name string `form:"name,options=[foo,bar]" validate:"omitempty,len=10"`
}
type BaseFilterWithBody {
BaseFilter
Names []string `json:"names,optional" validate:"max=5,dive,len=10"`
}
type BookFilter {
BaseFilter
PublishDateGt int32 `form:"publish_date_gt,optional"`
PublishDateLte int32 `form:"publish_date_lte,optional"`
AuthorID int64 `form:"author_id,optional" validate:"omitempty,gt=1"`
}
type BookFilterWithBody {
BookFilter
AuthorIDS []int64 `json:"author_ids,optional" validate:"max=10,dive,gt=1"`
}
type StoryBookFilter {
BookFilter
Type string `form:"type,optional" validate:"omitempty,oneof='foo0x2Cbar' 'spam0x7Cegg'"`
}
type StoryBookFilterWithBody {
StoryBookFilter
Name string `json:"name"` // same name but json, should keep both
Type string `form:"type" validate:"oneof=foo bar spam egg"` // same name and same location, should overwrite
Types [2]string `json:"types,optional" validate:"dive,oneof='foo0x2Cbar' 'spam0x7Cegg'"`
}
type UpdateStoryBooksRequest {
StoryBookFilter
StoryBook
Complicate map[string][]map[int][]*Author `json:"complicate" validate:"len=3,dive,keys,len=5,endkeys,max=100,dive,len=3,dive,min=2"`
}
type BaseModel {
ID int `json:"id" gorm:"primaryKey"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
type Base {
BaseModel
Name string `json:"name"`
Meta map[string][]string `json:"meta"`
}
type Author {
Base
Birthday int32 `json:"birthday"`
Books []*Book `json:"books"`
}
type Book {
Base
PublishDate int32 `json:"publish_date"`
Author Author `json:"author"`
}
type StoryBook {
Book
Type string `json:"type"`
}
@server (
prefix: /base
group: base
)
service Example {
@handler Health
get /health
}
@server (
jwt: Auth
prefix: /book
group: book
)
service Example {
@doc (
summary: "Update story book"
descripton: "Update one or multiple story books"
externalDocs: "https://github.com/jayvynl/goctl-openapi"
servers: "http://another,https://another"
)
@handler UpdateStoryBooks
post /story/:id (UpdateStoryBooksRequest)
@doc (
tags: "bar"
)
@handler ListStoryBook1
get /story1/:id (StoryBookFilter) returns ([]StoryBook)
@handler ListStoryBook2
post /story2/:id (StoryBookFilter) returns ([]StoryBook)
@doc (
tags: "foo"
)
@handler ListStoryBook3
post /story3/:id (StoryBookFilterWithBody) returns ([]StoryBook)
}