-
Notifications
You must be signed in to change notification settings - Fork 0
/
openapi_api.gen.go
360 lines (274 loc) · 10.6 KB
/
openapi_api.gen.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// Package ports provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
package ports
import (
"context"
"fmt"
"net/http"
"github.com/deepmap/oapi-codegen/pkg/runtime"
openapi_types "github.com/deepmap/oapi-codegen/pkg/types"
"github.com/go-chi/chi/v5"
)
// ServerInterface represents all server handlers.
type ServerInterface interface {
// (GET /trainings)
GetTrainings(w http.ResponseWriter, r *http.Request)
// (POST /trainings)
CreateTraining(w http.ResponseWriter, r *http.Request)
// (DELETE /trainings/{trainingUUID})
CancelTraining(w http.ResponseWriter, r *http.Request, trainingUUID openapi_types.UUID)
// (PUT /trainings/{trainingUUID}/approve-reschedule)
ApproveRescheduleTraining(w http.ResponseWriter, r *http.Request, trainingUUID openapi_types.UUID)
// (PUT /trainings/{trainingUUID}/reject-reschedule)
RejectRescheduleTraining(w http.ResponseWriter, r *http.Request, trainingUUID openapi_types.UUID)
// (PUT /trainings/{trainingUUID}/request-reschedule)
RequestRescheduleTraining(w http.ResponseWriter, r *http.Request, trainingUUID openapi_types.UUID)
// (PUT /trainings/{trainingUUID}/reschedule)
RescheduleTraining(w http.ResponseWriter, r *http.Request, trainingUUID openapi_types.UUID)
}
// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
HandlerMiddlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
type MiddlewareFunc func(http.Handler) http.Handler
// GetTrainings operation middleware
func (siw *ServerInterfaceWrapper) GetTrainings(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetTrainings(w, r)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// CreateTraining operation middleware
func (siw *ServerInterfaceWrapper) CreateTraining(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.CreateTraining(w, r)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// CancelTraining operation middleware
func (siw *ServerInterfaceWrapper) CancelTraining(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "trainingUUID" -------------
var trainingUUID openapi_types.UUID
err = runtime.BindStyledParameterWithLocation("simple", false, "trainingUUID", runtime.ParamLocationPath, chi.URLParam(r, "trainingUUID"), &trainingUUID)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "trainingUUID", Err: err})
return
}
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.CancelTraining(w, r, trainingUUID)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// ApproveRescheduleTraining operation middleware
func (siw *ServerInterfaceWrapper) ApproveRescheduleTraining(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "trainingUUID" -------------
var trainingUUID openapi_types.UUID
err = runtime.BindStyledParameterWithLocation("simple", false, "trainingUUID", runtime.ParamLocationPath, chi.URLParam(r, "trainingUUID"), &trainingUUID)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "trainingUUID", Err: err})
return
}
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ApproveRescheduleTraining(w, r, trainingUUID)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// RejectRescheduleTraining operation middleware
func (siw *ServerInterfaceWrapper) RejectRescheduleTraining(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "trainingUUID" -------------
var trainingUUID openapi_types.UUID
err = runtime.BindStyledParameterWithLocation("simple", false, "trainingUUID", runtime.ParamLocationPath, chi.URLParam(r, "trainingUUID"), &trainingUUID)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "trainingUUID", Err: err})
return
}
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.RejectRescheduleTraining(w, r, trainingUUID)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// RequestRescheduleTraining operation middleware
func (siw *ServerInterfaceWrapper) RequestRescheduleTraining(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "trainingUUID" -------------
var trainingUUID openapi_types.UUID
err = runtime.BindStyledParameterWithLocation("simple", false, "trainingUUID", runtime.ParamLocationPath, chi.URLParam(r, "trainingUUID"), &trainingUUID)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "trainingUUID", Err: err})
return
}
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.RequestRescheduleTraining(w, r, trainingUUID)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// RescheduleTraining operation middleware
func (siw *ServerInterfaceWrapper) RescheduleTraining(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "trainingUUID" -------------
var trainingUUID openapi_types.UUID
err = runtime.BindStyledParameterWithLocation("simple", false, "trainingUUID", runtime.ParamLocationPath, chi.URLParam(r, "trainingUUID"), &trainingUUID)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "trainingUUID", Err: err})
return
}
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.RescheduleTraining(w, r, trainingUUID)
})
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
type UnescapedCookieParamError struct {
ParamName string
Err error
}
func (e *UnescapedCookieParamError) Error() string {
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
}
func (e *UnescapedCookieParamError) Unwrap() error {
return e.Err
}
type UnmarshallingParamError struct {
ParamName string
Err error
}
func (e *UnmarshallingParamError) Error() string {
return fmt.Sprintf("Error unmarshalling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
}
func (e *UnmarshallingParamError) Unwrap() error {
return e.Err
}
type RequiredParamError struct {
ParamName string
}
func (e *RequiredParamError) Error() string {
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
}
type RequiredHeaderError struct {
ParamName string
Err error
}
func (e *RequiredHeaderError) Error() string {
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
}
func (e *RequiredHeaderError) Unwrap() error {
return e.Err
}
type InvalidParamFormatError struct {
ParamName string
Err error
}
func (e *InvalidParamFormatError) Error() string {
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
}
func (e *InvalidParamFormatError) Unwrap() error {
return e.Err
}
type TooManyValuesForParamError struct {
ParamName string
Count int
}
func (e *TooManyValuesForParamError) Error() string {
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
}
// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
return HandlerWithOptions(si, ChiServerOptions{})
}
type ChiServerOptions struct {
BaseURL string
BaseRouter chi.Router
Middlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
return HandlerWithOptions(si, ChiServerOptions{
BaseRouter: r,
})
}
func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler {
return HandlerWithOptions(si, ChiServerOptions{
BaseURL: baseURL,
BaseRouter: r,
})
}
// HandlerWithOptions creates http.Handler with additional options
func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler {
r := options.BaseRouter
if r == nil {
r = chi.NewRouter()
}
if options.ErrorHandlerFunc == nil {
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
wrapper := ServerInterfaceWrapper{
Handler: si,
HandlerMiddlewares: options.Middlewares,
ErrorHandlerFunc: options.ErrorHandlerFunc,
}
r.Group(func(r chi.Router) {
r.Get(options.BaseURL+"/trainings", wrapper.GetTrainings)
})
r.Group(func(r chi.Router) {
r.Post(options.BaseURL+"/trainings", wrapper.CreateTraining)
})
r.Group(func(r chi.Router) {
r.Delete(options.BaseURL+"/trainings/{trainingUUID}", wrapper.CancelTraining)
})
r.Group(func(r chi.Router) {
r.Put(options.BaseURL+"/trainings/{trainingUUID}/approve-reschedule", wrapper.ApproveRescheduleTraining)
})
r.Group(func(r chi.Router) {
r.Put(options.BaseURL+"/trainings/{trainingUUID}/reject-reschedule", wrapper.RejectRescheduleTraining)
})
r.Group(func(r chi.Router) {
r.Put(options.BaseURL+"/trainings/{trainingUUID}/request-reschedule", wrapper.RequestRescheduleTraining)
})
r.Group(func(r chi.Router) {
r.Put(options.BaseURL+"/trainings/{trainingUUID}/reschedule", wrapper.RescheduleTraining)
})
return r
}