/
authconfigs.gen.go
237 lines (196 loc) · 7.13 KB
/
authconfigs.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
// Package authconfigs provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.8.3 DO NOT EDIT.
package authconfigs
import (
"bytes"
"compress/gzip"
"encoding/base64"
"fmt"
"net/http"
"net/url"
"path"
"strings"
externalRef0 "github.com/cam-inc/viron/packages/golang/routes/components"
"github.com/getkin/kin-openapi/openapi3"
"github.com/go-chi/chi/v5"
)
// Defines values for VironAuthConfigType.
const (
VironAuthConfigTypeEmail VironAuthConfigType = "email"
VironAuthConfigTypeOauth VironAuthConfigType = "oauth"
VironAuthConfigTypeSignout VironAuthConfigType = "signout"
)
// VironAuthConfig defines model for VironAuthConfig.
type VironAuthConfig struct {
// クライアントからリクエストする際のパラメータ
DefaultParametersValue *map[string]interface{} `json:"defaultParametersValue,omitempty"`
// クライアントからリクエストする際のリクエストボディ
DefaultRequestBodyValue *map[string]interface{} `json:"defaultRequestBodyValue,omitempty"`
// 認証プロバイダ
Provider string `json:"provider"`
// 認証方式
Type VironAuthConfigType `json:"type"`
}
// 認証方式
type VironAuthConfigType string
// VironAuthConfigList defines model for VironAuthConfigList.
type VironAuthConfigList []VironAuthConfig
// VironAuthConfigListWithOas defines model for VironAuthConfigListWithOas.
type VironAuthConfigListWithOas struct {
List VironAuthConfigList `json:"list"`
Oas VironAuthOas `json:"oas"`
}
// VironAuthOas defines model for VironAuthOas.
type VironAuthOas struct {
// oas components
Components *map[string]interface{} `json:"components,omitempty"`
// oas info
Info *map[string]interface{} `json:"info,omitempty"`
// oas paths
Paths *map[string]interface{} `json:"paths,omitempty"`
}
// ServerInterface represents all server handlers.
type ServerInterface interface {
// list auth configs
// (GET /viron/authconfigs)
ListVironAuthconfigs(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
// ListVironAuthconfigs operation middleware
func (siw *ServerInterfaceWrapper) ListVironAuthconfigs(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ListVironAuthconfigs(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+"/viron/authconfigs", wrapper.ListVironAuthconfigs)
})
return r
}
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/6xUzW4TPRR9leh+33KUhLKbFT8rBFIRi7KosnAnNxlXM7ZreyKiaCQ6XgCqUIFFKwob",
"fhalUsuCVaUKHsYKKm+B7EmaZDJBgNiNfOxzzr333BlBxFPBGTKtIByBimJMif/coJKzm5mOb3PWo313",
"JCQXKDVFf6GLPZIl+j6RJEWNUm2QJMMSUZGkQlPOIARbfLbmky0+2uK9NV+seWp392zxzJoTBxXHtjj3",
"h69tsffj6I3dPbPmpXti3llzYYtvEIAeCoQQ+NY2RhryYKr+AHcyVPoW7w7/pfwiZN5a88QWH+p8CMkH",
"tItyWfjy5Pnl8YU1h9acWvPCOTCPIQB8RFKROJY+5/0EZ6xKS8r6jrU8qGf8fnA+vth3RCxLIdwETAlN",
"IABOMh1DAIr2Gc80dOa1pmBFKg9A4k5GJXYd1VU1k4sBCKLj9bLaTk35lZTco0o731Rj6kPyv8QehPBf",
"a5az1iRkrWrCruoGIiUZrqB/SHW8XkZ0MY/JRPsPJL3d3HXu98067WrbvHRJ88sm1fpe3MDFiXOiGnN4",
"DTdlPV7/ziN1iSU6XiFVQktv8uWTlcouZpFvrmoQQRtKYER7NCIO99xU+0DeGLiutBK61Zh7AwEMUKqS",
"q91sN6/5+QhkRFAI4Xqz3VyDuSJaJc08RTiCPupV63N5fDo+O7LFq/H+wfjrYbn34DWkN3mnCyG4ZFyN",
"beZNohKcqXJwa+12OT+mkXk9IkQyKbW1rZzo9Jf6F8GcBt03e7GS9bt+KCpLUyKHEPoA+jY2Zl41cb3Y",
"hEFlzTqecIKOgJHUjaN6K+/kPwMAAP//BhRrhB0GAAA=",
}
// GetSwagger returns the content of the embedded swagger specification file
// or error if failed to decode
func decodeSpec() ([]byte, error) {
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
if err != nil {
return nil, fmt.Errorf("error base64 decoding spec: %s", err)
}
zr, err := gzip.NewReader(bytes.NewReader(zipped))
if err != nil {
return nil, fmt.Errorf("error decompressing spec: %s", err)
}
var buf bytes.Buffer
_, err = buf.ReadFrom(zr)
if err != nil {
return nil, fmt.Errorf("error decompressing spec: %s", err)
}
return buf.Bytes(), nil
}
var rawSpec = decodeSpecCached()
// a naive cached of a decoded swagger spec
func decodeSpecCached() func() ([]byte, error) {
data, err := decodeSpec()
return func() ([]byte, error) {
return data, err
}
}
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
var res = make(map[string]func() ([]byte, error))
if len(pathToFile) > 0 {
res[pathToFile] = rawSpec
}
pathPrefix := path.Dir(pathToFile)
for rawPath, rawFunc := range externalRef0.PathToRawSpec(path.Join(pathPrefix, "./components.yaml")) {
if _, ok := res[rawPath]; ok {
// it is not possible to compare functions in golang, so always overwrite the old value
}
res[rawPath] = rawFunc
}
return res
}
// GetSwagger returns the Swagger specification corresponding to the generated code
// in this file. The external references of Swagger specification are resolved.
// The logic of resolving external references is tightly connected to "import-mapping" feature.
// Externally referenced files must be embedded in the corresponding golang packages.
// Urls can be supported but this task was out of the scope.
func GetSwagger() (swagger *openapi3.T, err error) {
var resolvePath = PathToRawSpec("")
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
var pathToFile = url.String()
pathToFile = path.Clean(pathToFile)
getSpec, ok := resolvePath[pathToFile]
if !ok {
err1 := fmt.Errorf("path not found: %s", pathToFile)
return nil, err1
}
return getSpec()
}
var specData []byte
specData, err = rawSpec()
if err != nil {
return
}
swagger, err = loader.LoadFromData(specData)
if err != nil {
return
}
return
}