-
Notifications
You must be signed in to change notification settings - Fork 6
/
oas2.go
200 lines (181 loc) · 6.21 KB
/
oas2.go
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Code generated by kun; DO NOT EDIT.
// github.com/RussellLuo/kun
package apiv1
import (
"reflect"
"github.com/RussellLuo/kun/pkg/oas2"
)
var (
base = `swagger: "2.0"
info:
title: "OSTree Repository Management API"
version: "1.0.0"
description: "OSTree is used for managing ostree repositories.\nThis is the API documentation of OSTree.\n//"
license:
name: "MIT"
host: "example.com"
basePath: "/artifacts/ostree/api/v1"
schemes:
- "https"
consumes:
- "application/json"
produces:
- "application/json"
`
paths = `
paths:
/repository/remote:
post:
description: "Add a new remote to the OSTree repository."
operationId: "AddRemote"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/AddRemoteRequestBody"
%s
delete:
description: "Delete an existing remote to the OSTree repository."
operationId: "DeleteRemote"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/DeleteRemoteRequestBody"
%s
put:
description: "Updates a remote in the OSTree repository. If it doesn't exist it will be created."
operationId: "UpdateRemote"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/UpdateRemoteRequestBody"
%s
/repository:
post:
description: "Create an OSTree repository."
operationId: "CreateRepository"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/CreateRepositoryRequestBody"
%s
delete:
description: "Delete a OSTree repository."
operationId: "DeleteRepository"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/DeleteRepositoryRequestBody"
%s
/repository/sync:
get:
description: "Get OSTree repository sync status."
operationId: "GetRepositorySyncStatus"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/GetRepositorySyncStatusRequestBody"
%s
post:
description: "Sync an ostree repository with one of the configured remotes."
operationId: "SyncRepository"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/SyncRepositoryRequestBody"
%s
/repository/refs:
get:
description: "List OSTree repository refs (A.K.A. Branches)."
operationId: "ListRepositoryRefs"
tags:
- ostree
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/ListRepositoryRefsRequestBody"
%s
`
)
func getResponses(schema oas2.Schema) []oas2.OASResponses {
return []oas2.OASResponses{
oas2.GetOASResponses(schema, "AddRemote", 200, &AddRemoteResponse{}),
oas2.GetOASResponses(schema, "DeleteRemote", 200, &DeleteRemoteResponse{}),
oas2.GetOASResponses(schema, "UpdateRemote", 200, &UpdateRemoteResponse{}),
oas2.GetOASResponses(schema, "CreateRepository", 200, &CreateRepositoryResponse{}),
oas2.GetOASResponses(schema, "DeleteRepository", 202, &DeleteRepositoryResponse{}),
oas2.GetOASResponses(schema, "GetRepositorySyncStatus", 200, &GetRepositorySyncStatusResponse{}),
oas2.GetOASResponses(schema, "SyncRepository", 202, &SyncRepositoryResponse{}),
oas2.GetOASResponses(schema, "ListRepositoryRefs", 200, &ListRepositoryRefsResponse{}),
}
}
func getDefinitions(schema oas2.Schema) map[string]oas2.Definition {
defs := make(map[string]oas2.Definition)
oas2.AddDefinition(defs, "AddRemoteRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
Properties *OSTreeRemoteProperties `json:"properties"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "AddRemote", 200, (&AddRemoteResponse{}).Body())
oas2.AddDefinition(defs, "CreateRepositoryRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
Properties *OSTreeRepositoryProperties `json:"properties"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "CreateRepository", 200, (&CreateRepositoryResponse{}).Body())
oas2.AddDefinition(defs, "DeleteRemoteRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
RemoteName string `json:"remote_name"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "DeleteRemote", 200, (&DeleteRemoteResponse{}).Body())
oas2.AddDefinition(defs, "DeleteRepositoryRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "DeleteRepository", 202, (&DeleteRepositoryResponse{}).Body())
oas2.AddDefinition(defs, "GetRepositorySyncStatusRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "GetRepositorySyncStatus", 200, (&GetRepositorySyncStatusResponse{}).Body())
oas2.AddDefinition(defs, "ListRepositoryRefsRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "ListRepositoryRefs", 200, (&ListRepositoryRefsResponse{}).Body())
oas2.AddDefinition(defs, "SyncRepositoryRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
Properties *OSTreeRepositorySyncRequest `json:"properties"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "SyncRepository", 202, (&SyncRepositoryResponse{}).Body())
oas2.AddDefinition(defs, "UpdateRemoteRequestBody", reflect.ValueOf(&struct {
Repository string `json:"repository"`
RemoteName string `json:"remote_name"`
Properties *OSTreeRemoteProperties `json:"properties"`
}{}))
oas2.AddResponseDefinitions(defs, schema, "UpdateRemote", 200, (&UpdateRemoteResponse{}).Body())
return defs
}
func OASv2APIDoc(schema oas2.Schema) string {
resps := getResponses(schema)
paths := oas2.GenPaths(resps, paths)
defs := getDefinitions(schema)
definitions := oas2.GenDefinitions(defs)
return base + paths + definitions
}