forked from jsteenb2/mess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openapi_api.gen.go
161 lines (125 loc) · 4.51 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
// Package ports provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.8.2 DO NOT EDIT.
package ports
import (
"context"
"fmt"
"net/http"
"github.com/deepmap/oapi-codegen/pkg/runtime"
"github.com/go-chi/chi/v5"
)
// ServerInterface represents all server handlers.
type ServerInterface interface {
// (PUT /trainer/calendar/make-hour-unavailable)
MakeHourUnavailable(w http.ResponseWriter, r *http.Request)
}
// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
HandlerMiddlewares []MiddlewareFunc
}
type MiddlewareFunc func(http.HandlerFunc) http.HandlerFunc
// GetTrainerAvailableHours operation middleware
func (siw *ServerInterfaceWrapper) GetTrainerAvailableHours(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
// Parameter object where we will unmarshal all parameters from the context
var params GetTrainerAvailableHoursParams
// ------------- Required query parameter "dateFrom" -------------
if paramValue := r.URL.Query().Get("dateFrom"); paramValue != "" {
} else {
http.Error(w, "Query argument dateFrom is required, but not found", http.StatusBadRequest)
return
}
err = runtime.BindQueryParameter("form", true, true, "dateFrom", r.URL.Query(), ¶ms.DateFrom)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter dateFrom: %s", err), http.StatusBadRequest)
return
}
// ------------- Required query parameter "dateTo" -------------
if paramValue := r.URL.Query().Get("dateTo"); paramValue != "" {
} else {
http.Error(w, "Query argument dateTo is required, but not found", http.StatusBadRequest)
return
}
err = runtime.BindQueryParameter("form", true, true, "dateTo", r.URL.Query(), ¶ms.DateTo)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter dateTo: %s", err), http.StatusBadRequest)
return
}
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetTrainerAvailableHours(w, r, params)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// MakeHourAvailable operation middleware
func (siw *ServerInterfaceWrapper) MakeHourAvailable(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.MakeHourAvailable(w, r)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// MakeHourUnavailable operation middleware
func (siw *ServerInterfaceWrapper) MakeHourUnavailable(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, BearerAuthScopes, []string{""})
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.MakeHourUnavailable(w, r)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// 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
}
// 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()
}
wrapper := ServerInterfaceWrapper{
Handler: si,
HandlerMiddlewares: options.Middlewares,
}
r.Group(func(r chi.Router) {
r.Get(options.BaseURL+"/trainer/calendar", wrapper.GetTrainerAvailableHours)
})
r.Group(func(r chi.Router) {
r.Put(options.BaseURL+"/trainer/calendar/make-hour-available", wrapper.MakeHourAvailable)
})
r.Group(func(r chi.Router) {
r.Put(options.BaseURL+"/trainer/calendar/make-hour-unavailable", wrapper.MakeHourUnavailable)
})
return r
}