github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/jobmaster/dm/openapi/gen.server.go (about) 1 // Package openapi provides primitives to interact with the openapi HTTP API. 2 // 3 // Code generated by github.com/deepmap/oapi-codegen version v1.9.0 DO NOT EDIT. 4 package openapi 5 6 import ( 7 "bytes" 8 "compress/gzip" 9 "encoding/base64" 10 "fmt" 11 "net/http" 12 "net/url" 13 "path" 14 "strings" 15 16 "github.com/deepmap/oapi-codegen/pkg/runtime" 17 "github.com/getkin/kin-openapi/openapi3" 18 "github.com/gin-gonic/gin" 19 ) 20 21 // ServerInterface represents all server handlers. 22 type ServerInterface interface { 23 // delete binlog operator 24 // (DELETE /binlog/tasks/{task-name}) 25 DMAPIDeleteBinlogOperator(c *gin.Context, taskName string, params DMAPIDeleteBinlogOperatorParams) 26 // get binlog operator 27 // (GET /binlog/tasks/{task-name}) 28 DMAPIGetBinlogOperator(c *gin.Context, taskName string, params DMAPIGetBinlogOperatorParams) 29 // set binlog operator 30 // (POST /binlog/tasks/{task-name}) 31 DMAPISetBinlogOperator(c *gin.Context, taskName string) 32 // get job config 33 // (GET /config) 34 DMAPIGetJobConfig(c *gin.Context) 35 // update job config 36 // (PUT /config) 37 DMAPIUpdateJobConfig(c *gin.Context) 38 // get schema 39 // (GET /schema/tasks/{task-name}) 40 DMAPIGetSchema(c *gin.Context, taskName string, params DMAPIGetSchemaParams) 41 // set schema 42 // (PUT /schema/tasks/{task-name}) 43 DMAPISetSchema(c *gin.Context, taskName string) 44 // get the current status of the job 45 // (GET /status) 46 DMAPIGetJobStatus(c *gin.Context, params DMAPIGetJobStatusParams) 47 // operate the stage of the job 48 // (PUT /status) 49 DMAPIOperateJob(c *gin.Context) 50 } 51 52 // ServerInterfaceWrapper converts contexts to parameters. 53 type ServerInterfaceWrapper struct { 54 Handler ServerInterface 55 HandlerMiddlewares []MiddlewareFunc 56 } 57 58 type MiddlewareFunc func(c *gin.Context) 59 60 // DMAPIDeleteBinlogOperator operation middleware 61 func (siw *ServerInterfaceWrapper) DMAPIDeleteBinlogOperator(c *gin.Context) { 62 var err error 63 64 // ------------- Path parameter "task-name" ------------- 65 var taskName string 66 67 err = runtime.BindStyledParameter("simple", false, "task-name", c.Param("task-name"), &taskName) 68 if err != nil { 69 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter task-name: %s", err)}) 70 return 71 } 72 73 // Parameter object where we will unmarshal all parameters from the context 74 var params DMAPIDeleteBinlogOperatorParams 75 76 // ------------- Optional query parameter "binlog_pos" ------------- 77 if paramValue := c.Query("binlog_pos"); paramValue != "" { 78 } 79 80 err = runtime.BindQueryParameter("form", true, false, "binlog_pos", c.Request.URL.Query(), ¶ms.BinlogPos) 81 if err != nil { 82 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter binlog_pos: %s", err)}) 83 return 84 } 85 86 for _, middleware := range siw.HandlerMiddlewares { 87 middleware(c) 88 } 89 90 siw.Handler.DMAPIDeleteBinlogOperator(c, taskName, params) 91 } 92 93 // DMAPIGetBinlogOperator operation middleware 94 func (siw *ServerInterfaceWrapper) DMAPIGetBinlogOperator(c *gin.Context) { 95 var err error 96 97 // ------------- Path parameter "task-name" ------------- 98 var taskName string 99 100 err = runtime.BindStyledParameter("simple", false, "task-name", c.Param("task-name"), &taskName) 101 if err != nil { 102 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter task-name: %s", err)}) 103 return 104 } 105 106 // Parameter object where we will unmarshal all parameters from the context 107 var params DMAPIGetBinlogOperatorParams 108 109 // ------------- Optional query parameter "binlog_pos" ------------- 110 if paramValue := c.Query("binlog_pos"); paramValue != "" { 111 } 112 113 err = runtime.BindQueryParameter("form", true, false, "binlog_pos", c.Request.URL.Query(), ¶ms.BinlogPos) 114 if err != nil { 115 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter binlog_pos: %s", err)}) 116 return 117 } 118 119 for _, middleware := range siw.HandlerMiddlewares { 120 middleware(c) 121 } 122 123 siw.Handler.DMAPIGetBinlogOperator(c, taskName, params) 124 } 125 126 // DMAPISetBinlogOperator operation middleware 127 func (siw *ServerInterfaceWrapper) DMAPISetBinlogOperator(c *gin.Context) { 128 var err error 129 130 // ------------- Path parameter "task-name" ------------- 131 var taskName string 132 133 err = runtime.BindStyledParameter("simple", false, "task-name", c.Param("task-name"), &taskName) 134 if err != nil { 135 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter task-name: %s", err)}) 136 return 137 } 138 139 for _, middleware := range siw.HandlerMiddlewares { 140 middleware(c) 141 } 142 143 siw.Handler.DMAPISetBinlogOperator(c, taskName) 144 } 145 146 // DMAPIGetJobConfig operation middleware 147 func (siw *ServerInterfaceWrapper) DMAPIGetJobConfig(c *gin.Context) { 148 for _, middleware := range siw.HandlerMiddlewares { 149 middleware(c) 150 } 151 152 siw.Handler.DMAPIGetJobConfig(c) 153 } 154 155 // DMAPIUpdateJobConfig operation middleware 156 func (siw *ServerInterfaceWrapper) DMAPIUpdateJobConfig(c *gin.Context) { 157 for _, middleware := range siw.HandlerMiddlewares { 158 middleware(c) 159 } 160 161 siw.Handler.DMAPIUpdateJobConfig(c) 162 } 163 164 // DMAPIGetSchema operation middleware 165 func (siw *ServerInterfaceWrapper) DMAPIGetSchema(c *gin.Context) { 166 var err error 167 168 // ------------- Path parameter "task-name" ------------- 169 var taskName string 170 171 err = runtime.BindStyledParameter("simple", false, "task-name", c.Param("task-name"), &taskName) 172 if err != nil { 173 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter task-name: %s", err)}) 174 return 175 } 176 177 // Parameter object where we will unmarshal all parameters from the context 178 var params DMAPIGetSchemaParams 179 180 // ------------- Optional query parameter "database" ------------- 181 if paramValue := c.Query("database"); paramValue != "" { 182 } 183 184 err = runtime.BindQueryParameter("form", true, false, "database", c.Request.URL.Query(), ¶ms.Database) 185 if err != nil { 186 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter database: %s", err)}) 187 return 188 } 189 190 // ------------- Optional query parameter "table" ------------- 191 if paramValue := c.Query("table"); paramValue != "" { 192 } 193 194 err = runtime.BindQueryParameter("form", true, false, "table", c.Request.URL.Query(), ¶ms.Table) 195 if err != nil { 196 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter table: %s", err)}) 197 return 198 } 199 200 // ------------- Optional query parameter "target" ------------- 201 if paramValue := c.Query("target"); paramValue != "" { 202 } 203 204 err = runtime.BindQueryParameter("form", true, false, "target", c.Request.URL.Query(), ¶ms.Target) 205 if err != nil { 206 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter target: %s", err)}) 207 return 208 } 209 210 for _, middleware := range siw.HandlerMiddlewares { 211 middleware(c) 212 } 213 214 siw.Handler.DMAPIGetSchema(c, taskName, params) 215 } 216 217 // DMAPISetSchema operation middleware 218 func (siw *ServerInterfaceWrapper) DMAPISetSchema(c *gin.Context) { 219 var err error 220 221 // ------------- Path parameter "task-name" ------------- 222 var taskName string 223 224 err = runtime.BindStyledParameter("simple", false, "task-name", c.Param("task-name"), &taskName) 225 if err != nil { 226 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter task-name: %s", err)}) 227 return 228 } 229 230 for _, middleware := range siw.HandlerMiddlewares { 231 middleware(c) 232 } 233 234 siw.Handler.DMAPISetSchema(c, taskName) 235 } 236 237 // DMAPIGetJobStatus operation middleware 238 func (siw *ServerInterfaceWrapper) DMAPIGetJobStatus(c *gin.Context) { 239 var err error 240 241 // Parameter object where we will unmarshal all parameters from the context 242 var params DMAPIGetJobStatusParams 243 244 // ------------- Optional query parameter "tasks" ------------- 245 if paramValue := c.Query("tasks"); paramValue != "" { 246 } 247 248 err = runtime.BindQueryParameter("form", true, false, "tasks", c.Request.URL.Query(), ¶ms.Tasks) 249 if err != nil { 250 c.JSON(http.StatusBadRequest, gin.H{"msg": fmt.Sprintf("Invalid format for parameter tasks: %s", err)}) 251 return 252 } 253 254 for _, middleware := range siw.HandlerMiddlewares { 255 middleware(c) 256 } 257 258 siw.Handler.DMAPIGetJobStatus(c, params) 259 } 260 261 // DMAPIOperateJob operation middleware 262 func (siw *ServerInterfaceWrapper) DMAPIOperateJob(c *gin.Context) { 263 for _, middleware := range siw.HandlerMiddlewares { 264 middleware(c) 265 } 266 267 siw.Handler.DMAPIOperateJob(c) 268 } 269 270 // GinServerOptions provides options for the Gin server. 271 type GinServerOptions struct { 272 BaseURL string 273 Middlewares []MiddlewareFunc 274 } 275 276 // RegisterHandlers creates http.Handler with routing matching OpenAPI spec. 277 func RegisterHandlers(router *gin.Engine, si ServerInterface) *gin.Engine { 278 return RegisterHandlersWithOptions(router, si, GinServerOptions{}) 279 } 280 281 // RegisterHandlersWithOptions creates http.Handler with additional options 282 func RegisterHandlersWithOptions(router *gin.Engine, si ServerInterface, options GinServerOptions) *gin.Engine { 283 wrapper := ServerInterfaceWrapper{ 284 Handler: si, 285 HandlerMiddlewares: options.Middlewares, 286 } 287 288 router.DELETE(options.BaseURL+"/binlog/tasks/:task-name", wrapper.DMAPIDeleteBinlogOperator) 289 290 router.GET(options.BaseURL+"/binlog/tasks/:task-name", wrapper.DMAPIGetBinlogOperator) 291 292 router.POST(options.BaseURL+"/binlog/tasks/:task-name", wrapper.DMAPISetBinlogOperator) 293 294 router.GET(options.BaseURL+"/config", wrapper.DMAPIGetJobConfig) 295 296 router.PUT(options.BaseURL+"/config", wrapper.DMAPIUpdateJobConfig) 297 298 router.GET(options.BaseURL+"/schema/tasks/:task-name", wrapper.DMAPIGetSchema) 299 300 router.PUT(options.BaseURL+"/schema/tasks/:task-name", wrapper.DMAPISetSchema) 301 302 router.GET(options.BaseURL+"/status", wrapper.DMAPIGetJobStatus) 303 304 router.PUT(options.BaseURL+"/status", wrapper.DMAPIOperateJob) 305 306 return router 307 } 308 309 // Base64 encoded, gzipped, json marshaled Swagger object 310 var swaggerSpec = []string{ 311 "H4sIAAAAAAAC/+RYS4/bNhD+K8S0RyU22px0a5qiSIGgRRdFD4ERUNJIS4ciaT4OhqH/XpCUZMumtDZQ", 312 "J4vdS+Ilh9+8vnnYByhlq6RAYQ3kBzDlI7Y0fPxNa6n/ZfbxExpDG/RnFZpSM2WZFJCDVKip/0zQy0IG", 313 "SvszyzAglLJKvAqyJNxlYPcKIQcmLDaoocugQksZD++ZxTZ86KWM1Uw0Xqg/oFrTvf+7nTMxKhuus3Ok", 314 "LgONO8c0VpB/ht6oQXwzystii6X1mv4MPuMfsvgbdw6N9Tqnbkvl/0XhWo+p0bjWoyrqzCnmiTfUfL3J", 315 "4TOzpUqa+oD2PRNcNtFmqWctLoLYFyXTyqcOma9MgTdAcVp6x5gIGlOemR2/p2MPga2zblXU0oIaTCqu", 316 "tWy/GOl02dOmpo5byGvKDY5KCyk5UjE+sFQ3aK97YHY87TIteMqmM+dH64cXETEVkH9UFTn5qxQ1a2YD", 317 "Uobrp1X3cpeqvCATtYRcOM49M1BQxSCHn9+u364Dy+1j0LWKpFoFcq8O/r83grbYxeBxtBiLpe8hHyvI", 318 "4cOnX/76+CFcTqkbkDVt0aI2kH8+r3MPTzx84CPkwQ7IIBzF6zf99dFRqx1mfctLBuUQsXYO9f4IdlIt", 319 "S683XpVRUpgY/J/W7y77k3Flicb4JL5br/scWRQheVQpzsoQndXWePnDib4fNdaQww+rYwdf9e17ddG7", 320 "Q+amqmvKOFYh98a1LdV7yPvEkOgikcfoW9r4uIdIwqbLoC+DRP5+P+87l8l7tim6LQU9XrhIRPi5JbdB", 321 "e01mlTRzqX14OrXfoC43URiNfS+r/f8W19l5mYhvr58U3oDuddHIXEOjLoPVcdwsNotxbsF947iVRYxh", 322 "og9HU4mQltTSiVTlbGVBysHOwVuPGWrGzTl4NpvhPtyd2QC66WT3hTVD1udNORfcW0qB51tUk944FhkY", 323 "98jvtWNMtQxr30TT2Xg7WQ1vQA5b5BLsuGbegun3YTK8TKOGlTkBO+7Kr3EQm4Fzl/PXLYzf70jVe4/d", 324 "6be561vXS56zSZaYod9Zap25Zr4+RMknWNNwWVDO98QJtnNIfJsh8SvyctvwJp0y5+qv+6+w7u0jktJp", 325 "jcKSmEAi63DqB9ktm8Xxp6g7LRWXv3W9lH0iRhND2I2lDS7loOvGk0NipRzrIO6XqVY8rRXoNt1/AQAA", 326 "//9aG6NCeBUAAA==", 327 } 328 329 // GetSwagger returns the content of the embedded swagger specification file 330 // or error if failed to decode 331 func decodeSpec() ([]byte, error) { 332 zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, "")) 333 if err != nil { 334 return nil, fmt.Errorf("error base64 decoding spec: %s", err) 335 } 336 zr, err := gzip.NewReader(bytes.NewReader(zipped)) 337 if err != nil { 338 return nil, fmt.Errorf("error decompressing spec: %s", err) 339 } 340 var buf bytes.Buffer 341 _, err = buf.ReadFrom(zr) 342 if err != nil { 343 return nil, fmt.Errorf("error decompressing spec: %s", err) 344 } 345 346 return buf.Bytes(), nil 347 } 348 349 var rawSpec = decodeSpecCached() 350 351 // a naive cached of a decoded swagger spec 352 func decodeSpecCached() func() ([]byte, error) { 353 data, err := decodeSpec() 354 return func() ([]byte, error) { 355 return data, err 356 } 357 } 358 359 // Constructs a synthetic filesystem for resolving external references when loading openapi specifications. 360 func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) { 361 res := make(map[string]func() ([]byte, error)) 362 if len(pathToFile) > 0 { 363 res[pathToFile] = rawSpec 364 } 365 366 return res 367 } 368 369 // GetSwagger returns the Swagger specification corresponding to the generated code 370 // in this file. The external references of Swagger specification are resolved. 371 // The logic of resolving external references is tightly connected to "import-mapping" feature. 372 // Externally referenced files must be embedded in the corresponding golang packages. 373 // Urls can be supported but this task was out of the scope. 374 func GetSwagger() (swagger *openapi3.T, err error) { 375 resolvePath := PathToRawSpec("") 376 377 loader := openapi3.NewLoader() 378 loader.IsExternalRefsAllowed = true 379 loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) { 380 pathToFile := url.String() 381 pathToFile = path.Clean(pathToFile) 382 getSpec, ok := resolvePath[pathToFile] 383 if !ok { 384 err1 := fmt.Errorf("path not found: %s", pathToFile) 385 return nil, err1 386 } 387 return getSpec() 388 } 389 var specData []byte 390 specData, err = rawSpec() 391 if err != nil { 392 return 393 } 394 swagger, err = loader.LoadFromData(specData) 395 if err != nil { 396 return 397 } 398 return 399 }