forked from oapi-codegen/oapi-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.gen.go
415 lines (332 loc) · 14.3 KB
/
server.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
// Package server provides primitives to interact the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen DO NOT EDIT.
package server
import (
"fmt"
"net/http"
"time"
"github.com/deepmap/oapi-codegen/pkg/runtime"
openapi_types "github.com/deepmap/oapi-codegen/pkg/types"
"github.com/go-chi/chi"
)
// EveryTypeOptional defines model for EveryTypeOptional.
type EveryTypeOptional struct {
ArrayInlineField *[]int `json:"array_inline_field,omitempty"`
ArrayReferencedField *[]SomeObject `json:"array_referenced_field,omitempty"`
BoolField *bool `json:"bool_field,omitempty"`
ByteField *[]byte `json:"byte_field,omitempty"`
DateField *openapi_types.Date `json:"date_field,omitempty"`
DateTimeField *time.Time `json:"date_time_field,omitempty"`
DoubleField *float64 `json:"double_field,omitempty"`
FloatField *float32 `json:"float_field,omitempty"`
InlineObjectField *struct {
Name string `json:"name"`
Number int `json:"number"`
} `json:"inline_object_field,omitempty"`
Int32Field *int32 `json:"int32_field,omitempty"`
Int64Field *int64 `json:"int64_field,omitempty"`
IntField *int `json:"int_field,omitempty"`
NumberField *float32 `json:"number_field,omitempty"`
ReferencedField *SomeObject `json:"referenced_field,omitempty"`
StringField *string `json:"string_field,omitempty"`
}
// EveryTypeRequired defines model for EveryTypeRequired.
type EveryTypeRequired struct {
ArrayInlineField []int `json:"array_inline_field"`
ArrayReferencedField []SomeObject `json:"array_referenced_field"`
BoolField bool `json:"bool_field"`
ByteField []byte `json:"byte_field"`
DateField openapi_types.Date `json:"date_field"`
DateTimeField time.Time `json:"date_time_field"`
DoubleField float64 `json:"double_field"`
EmailField *openapi_types.Email `json:"email_field,omitempty"`
FloatField float32 `json:"float_field"`
InlineObjectField struct {
Name string `json:"name"`
Number int `json:"number"`
} `json:"inline_object_field"`
Int32Field int32 `json:"int32_field"`
Int64Field int64 `json:"int64_field"`
IntField int `json:"int_field"`
NumberField float32 `json:"number_field"`
ReferencedField SomeObject `json:"referenced_field"`
StringField string `json:"string_field"`
}
// ReservedKeyword defines model for ReservedKeyword.
type ReservedKeyword struct {
Channel *string `json:"channel,omitempty"`
}
// Resource defines model for Resource.
type Resource struct {
Name string `json:"name"`
Value float32 `json:"value"`
}
// SomeObject defines model for some_object.
type SomeObject struct {
Name string `json:"name"`
}
// Argument defines model for argument.
type Argument string
// ResponseWithReference defines model for ResponseWithReference.
type ResponseWithReference SomeObject
// SimpleResponse defines model for SimpleResponse.
type SimpleResponse struct {
Name string `json:"name"`
}
// GetWithArgsParams defines parameters for GetWithArgs.
type GetWithArgsParams struct {
// An optional query argument
OptionalArgument *int64 `json:"optional_argument,omitempty"`
// An optional query argument
RequiredArgument int64 `json:"required_argument"`
// An optional query argument
HeaderArgument *int32 `json:"header_argument,omitempty"`
}
// CreateResourceJSONBody defines parameters for CreateResource.
type CreateResourceJSONBody EveryTypeRequired
// CreateResource2JSONBody defines parameters for CreateResource2.
type CreateResource2JSONBody Resource
// CreateResource2Params defines parameters for CreateResource2.
type CreateResource2Params struct {
// Some query argument
InlineQueryArgument *int `json:"inline_query_argument,omitempty"`
}
// UpdateResource3JSONBody defines parameters for UpdateResource3.
type UpdateResource3JSONBody struct {
Id *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
}
// CreateResourceRequestBody defines body for CreateResource for application/json ContentType.
type CreateResourceJSONRequestBody CreateResourceJSONBody
// CreateResource2RequestBody defines body for CreateResource2 for application/json ContentType.
type CreateResource2JSONRequestBody CreateResource2JSONBody
// UpdateResource3RequestBody defines body for UpdateResource3 for application/json ContentType.
type UpdateResource3JSONRequestBody UpdateResource3JSONBody
// ServerInterface represents all server handlers.
type ServerInterface interface {
// get every type optional
// (GET /every-type-optional)
GetEveryTypeOptional(w http.ResponseWriter, r *http.Request)
// Get resource via simple path
// (GET /get-simple)
GetSimple(w http.ResponseWriter, r *http.Request)
// Getter with referenced parameter and referenced response
// (GET /get-with-args)
GetWithArgs(w http.ResponseWriter, r *http.Request, params GetWithArgsParams)
// Getter with referenced parameter and referenced response
// (GET /get-with-references/{global_argument}/{argument})
GetWithReferences(w http.ResponseWriter, r *http.Request, globalArgument int64, argument Argument)
// Get an object by ID
// (GET /get-with-type/{content_type})
GetWithContentType(w http.ResponseWriter, r *http.Request, contentType string)
// get with reserved keyword
// (GET /reserved-keyword)
GetReservedKeyword(w http.ResponseWriter, r *http.Request)
// Create a resource
// (POST /resource/{argument})
CreateResource(w http.ResponseWriter, r *http.Request, argument Argument)
// Create a resource with inline parameter
// (POST /resource2/{inline_argument})
CreateResource2(w http.ResponseWriter, r *http.Request, inlineArgument int, params CreateResource2Params)
// Update a resource with inline body. The parameter name is a reserved
// keyword, so make sure that gets prefixed to avoid syntax errors
// (PUT /resource3/{fallthrough})
UpdateResource3(w http.ResponseWriter, r *http.Request, pFallthrough int)
// get response with reference
// (GET /response-with-reference)
GetResponseWithReference(w http.ResponseWriter, r *http.Request)
}
// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
}
// GetEveryTypeOptional operation middleware
func (siw *ServerInterfaceWrapper) GetEveryTypeOptional(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
siw.Handler.GetEveryTypeOptional(w, r.WithContext(ctx))
}
// GetSimple operation middleware
func (siw *ServerInterfaceWrapper) GetSimple(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
siw.Handler.GetSimple(w, r.WithContext(ctx))
}
// GetWithArgs operation middleware
func (siw *ServerInterfaceWrapper) GetWithArgs(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// Parameter object where we will unmarshal all parameters from the context
var params GetWithArgsParams
// ------------- Optional query parameter "optional_argument" -------------
if paramValue := r.URL.Query().Get("optional_argument"); paramValue != "" {
}
err = runtime.BindQueryParameter("form", true, false, "optional_argument", r.URL.Query(), ¶ms.OptionalArgument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter optional_argument: %s", err), http.StatusBadRequest)
return
}
// ------------- Required query parameter "required_argument" -------------
if paramValue := r.URL.Query().Get("required_argument"); paramValue != "" {
} else {
http.Error(w, "Query argument required_argument is required, but not found", http.StatusBadRequest)
return
}
err = runtime.BindQueryParameter("form", true, true, "required_argument", r.URL.Query(), ¶ms.RequiredArgument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter required_argument: %s", err), http.StatusBadRequest)
return
}
headers := r.Header
// ------------- Optional header parameter "header_argument" -------------
if valueList, found := headers[http.CanonicalHeaderKey("header_argument")]; found {
var HeaderArgument int32
n := len(valueList)
if n != 1 {
http.Error(w, fmt.Sprintf("Expected one value for header_argument, got %d", n), http.StatusBadRequest)
return
}
err = runtime.BindStyledParameter("simple", false, "header_argument", valueList[0], &HeaderArgument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter header_argument: %s", err), http.StatusBadRequest)
return
}
params.HeaderArgument = &HeaderArgument
}
siw.Handler.GetWithArgs(w, r.WithContext(ctx), params)
}
// GetWithReferences operation middleware
func (siw *ServerInterfaceWrapper) GetWithReferences(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "global_argument" -------------
var globalArgument int64
err = runtime.BindStyledParameter("simple", false, "global_argument", chi.URLParam(r, "global_argument"), &globalArgument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter global_argument: %s", err), http.StatusBadRequest)
return
}
// ------------- Path parameter "argument" -------------
var argument Argument
err = runtime.BindStyledParameter("simple", false, "argument", chi.URLParam(r, "argument"), &argument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter argument: %s", err), http.StatusBadRequest)
return
}
siw.Handler.GetWithReferences(w, r.WithContext(ctx), globalArgument, argument)
}
// GetWithContentType operation middleware
func (siw *ServerInterfaceWrapper) GetWithContentType(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "content_type" -------------
var contentType string
err = runtime.BindStyledParameter("simple", false, "content_type", chi.URLParam(r, "content_type"), &contentType)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter content_type: %s", err), http.StatusBadRequest)
return
}
siw.Handler.GetWithContentType(w, r.WithContext(ctx), contentType)
}
// GetReservedKeyword operation middleware
func (siw *ServerInterfaceWrapper) GetReservedKeyword(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
siw.Handler.GetReservedKeyword(w, r.WithContext(ctx))
}
// CreateResource operation middleware
func (siw *ServerInterfaceWrapper) CreateResource(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "argument" -------------
var argument Argument
err = runtime.BindStyledParameter("simple", false, "argument", chi.URLParam(r, "argument"), &argument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter argument: %s", err), http.StatusBadRequest)
return
}
siw.Handler.CreateResource(w, r.WithContext(ctx), argument)
}
// CreateResource2 operation middleware
func (siw *ServerInterfaceWrapper) CreateResource2(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "inline_argument" -------------
var inlineArgument int
err = runtime.BindStyledParameter("simple", false, "inline_argument", chi.URLParam(r, "inline_argument"), &inlineArgument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter inline_argument: %s", err), http.StatusBadRequest)
return
}
// Parameter object where we will unmarshal all parameters from the context
var params CreateResource2Params
// ------------- Optional query parameter "inline_query_argument" -------------
if paramValue := r.URL.Query().Get("inline_query_argument"); paramValue != "" {
}
err = runtime.BindQueryParameter("form", true, false, "inline_query_argument", r.URL.Query(), ¶ms.InlineQueryArgument)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter inline_query_argument: %s", err), http.StatusBadRequest)
return
}
siw.Handler.CreateResource2(w, r.WithContext(ctx), inlineArgument, params)
}
// UpdateResource3 operation middleware
func (siw *ServerInterfaceWrapper) UpdateResource3(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "fallthrough" -------------
var pFallthrough int
err = runtime.BindStyledParameter("simple", false, "fallthrough", chi.URLParam(r, "fallthrough"), &pFallthrough)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter fallthrough: %s", err), http.StatusBadRequest)
return
}
siw.Handler.UpdateResource3(w, r.WithContext(ctx), pFallthrough)
}
// GetResponseWithReference operation middleware
func (siw *ServerInterfaceWrapper) GetResponseWithReference(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
siw.Handler.GetResponseWithReference(w, r.WithContext(ctx))
}
// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
return HandlerFromMux(si, chi.NewRouter())
}
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
return HandlerFromMuxWithBaseURL(si, r, "")
}
func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler {
wrapper := ServerInterfaceWrapper{
Handler: si,
}
r.Group(func(r chi.Router) {
r.Get(baseURL+"/every-type-optional", wrapper.GetEveryTypeOptional)
})
r.Group(func(r chi.Router) {
r.Get(baseURL+"/get-simple", wrapper.GetSimple)
})
r.Group(func(r chi.Router) {
r.Get(baseURL+"/get-with-args", wrapper.GetWithArgs)
})
r.Group(func(r chi.Router) {
r.Get(baseURL+"/get-with-references/{global_argument}/{argument}", wrapper.GetWithReferences)
})
r.Group(func(r chi.Router) {
r.Get(baseURL+"/get-with-type/{content_type}", wrapper.GetWithContentType)
})
r.Group(func(r chi.Router) {
r.Get(baseURL+"/reserved-keyword", wrapper.GetReservedKeyword)
})
r.Group(func(r chi.Router) {
r.Post(baseURL+"/resource/{argument}", wrapper.CreateResource)
})
r.Group(func(r chi.Router) {
r.Post(baseURL+"/resource2/{inline_argument}", wrapper.CreateResource2)
})
r.Group(func(r chi.Router) {
r.Put(baseURL+"/resource3/{fallthrough}", wrapper.UpdateResource3)
})
r.Group(func(r chi.Router) {
r.Get(baseURL+"/response-with-reference", wrapper.GetResponseWithReference)
})
return r
}