github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/pkg/store-client/generated/client.gen.go (about) 1 // Package generated provides primitives to interact with the openapi HTTP API. 2 // 3 // Code generated by github.com/deepmap/oapi-codegen DO NOT EDIT. 4 package generated 5 6 import ( 7 "context" 8 "encoding/json" 9 "fmt" 10 "io" 11 "net/http" 12 "net/url" 13 "strings" 14 15 "github.com/deepmap/oapi-codegen/pkg/runtime" 16 ) 17 18 // RequestEditorFn is the function signature for the RequestEditor callback function 19 type RequestEditorFn func(ctx context.Context, req *http.Request) error 20 21 // Doer performs HTTP requests. 22 // 23 // The standard http.Client implements this interface. 24 type HttpRequestDoer interface { 25 Do(req *http.Request) (*http.Response, error) 26 } 27 28 // Client which conforms to the OpenAPI3 specification for this service. 29 type Client struct { 30 // The endpoint of the server conforming to this interface, with scheme, 31 // https://api.deepmap.com for example. This can contain a path relative 32 // to the server, such as https://api.deepmap.com/dev-test, and all the 33 // paths in the swagger spec will be appended to the server. 34 Server string 35 36 // Doer for performing requests, typically a *http.Client with any 37 // customized settings, such as certificate chains. 38 Client HttpRequestDoer 39 40 // A list of callbacks for modifying requests which are generated before sending over 41 // the network. 42 RequestEditors []RequestEditorFn 43 } 44 45 // ClientOption allows setting custom parameters during construction 46 type ClientOption func(*Client) error 47 48 // Creates a new Client, with reasonable defaults 49 func NewClient(server string, opts ...ClientOption) (*Client, error) { 50 // create a client with sane default values 51 client := Client{ 52 Server: server, 53 } 54 // mutate client and add all optional params 55 for _, o := range opts { 56 if err := o(&client); err != nil { 57 return nil, err 58 } 59 } 60 // ensure the server URL always has a trailing slash 61 if !strings.HasSuffix(client.Server, "/") { 62 client.Server += "/" 63 } 64 // create httpClient, if not already present 65 if client.Client == nil { 66 client.Client = &http.Client{} 67 } 68 return &client, nil 69 } 70 71 // WithHTTPClient allows overriding the default Doer, which is 72 // automatically created using http.Client. This is useful for tests. 73 func WithHTTPClient(doer HttpRequestDoer) ClientOption { 74 return func(c *Client) error { 75 c.Client = doer 76 return nil 77 } 78 } 79 80 // WithRequestEditorFn allows setting up a callback function, which will be 81 // called right before sending the request. This can be used to mutate the request. 82 func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 83 return func(c *Client) error { 84 c.RequestEditors = append(c.RequestEditors, fn) 85 return nil 86 } 87 } 88 89 // The interface specification for the client above. 90 type ClientInterface interface { 91 // GetHealth request 92 GetHealth(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 93 94 // GetProjectArtifact request 95 GetProjectArtifact(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*http.Response, error) 96 97 // ProjectArtifactExists request 98 ProjectArtifactExists(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*http.Response, error) 99 100 // GetProjectArtifacts request 101 GetProjectArtifacts(ctx context.Context, projectName string, reqEditors ...RequestEditorFn) (*http.Response, error) 102 103 // UploadArtifact request with any body 104 UploadArtifactWithBody(ctx context.Context, projectName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 105 } 106 107 func (c *Client) GetHealth(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 108 req, err := NewGetHealthRequest(c.Server) 109 if err != nil { 110 return nil, err 111 } 112 req = req.WithContext(ctx) 113 if err := c.applyEditors(ctx, req, reqEditors); err != nil { 114 return nil, err 115 } 116 return c.Client.Do(req) 117 } 118 119 func (c *Client) GetProjectArtifact(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*http.Response, error) { 120 req, err := NewGetProjectArtifactRequest(c.Server, projectName, artifactId) 121 if err != nil { 122 return nil, err 123 } 124 req = req.WithContext(ctx) 125 if err := c.applyEditors(ctx, req, reqEditors); err != nil { 126 return nil, err 127 } 128 return c.Client.Do(req) 129 } 130 131 func (c *Client) ProjectArtifactExists(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*http.Response, error) { 132 req, err := NewProjectArtifactExistsRequest(c.Server, projectName, artifactId) 133 if err != nil { 134 return nil, err 135 } 136 req = req.WithContext(ctx) 137 if err := c.applyEditors(ctx, req, reqEditors); err != nil { 138 return nil, err 139 } 140 return c.Client.Do(req) 141 } 142 143 func (c *Client) GetProjectArtifacts(ctx context.Context, projectName string, reqEditors ...RequestEditorFn) (*http.Response, error) { 144 req, err := NewGetProjectArtifactsRequest(c.Server, projectName) 145 if err != nil { 146 return nil, err 147 } 148 req = req.WithContext(ctx) 149 if err := c.applyEditors(ctx, req, reqEditors); err != nil { 150 return nil, err 151 } 152 return c.Client.Do(req) 153 } 154 155 func (c *Client) UploadArtifactWithBody(ctx context.Context, projectName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 156 req, err := NewUploadArtifactRequestWithBody(c.Server, projectName, contentType, body) 157 if err != nil { 158 return nil, err 159 } 160 req = req.WithContext(ctx) 161 if err := c.applyEditors(ctx, req, reqEditors); err != nil { 162 return nil, err 163 } 164 return c.Client.Do(req) 165 } 166 167 // NewGetHealthRequest generates requests for GetHealth 168 func NewGetHealthRequest(server string) (*http.Request, error) { 169 var err error 170 171 serverURL, err := url.Parse(server) 172 if err != nil { 173 return nil, err 174 } 175 176 operationPath := fmt.Sprintf("/api/health") 177 if operationPath[0] == '/' { 178 operationPath = operationPath[1:] 179 } 180 operationURL := url.URL{ 181 Path: operationPath, 182 } 183 184 queryURL := serverURL.ResolveReference(&operationURL) 185 186 req, err := http.NewRequest("GET", queryURL.String(), nil) 187 if err != nil { 188 return nil, err 189 } 190 191 return req, nil 192 } 193 194 // NewGetProjectArtifactRequest generates requests for GetProjectArtifact 195 func NewGetProjectArtifactRequest(server string, projectName string, artifactId string) (*http.Request, error) { 196 var err error 197 198 var pathParam0 string 199 200 pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectName", runtime.ParamLocationPath, projectName) 201 if err != nil { 202 return nil, err 203 } 204 205 var pathParam1 string 206 207 pathParam1, err = runtime.StyleParamWithLocation("simple", false, "artifactId", runtime.ParamLocationPath, artifactId) 208 if err != nil { 209 return nil, err 210 } 211 212 serverURL, err := url.Parse(server) 213 if err != nil { 214 return nil, err 215 } 216 217 operationPath := fmt.Sprintf("/api/project/%s/artifact/%s", pathParam0, pathParam1) 218 if operationPath[0] == '/' { 219 operationPath = operationPath[1:] 220 } 221 operationURL := url.URL{ 222 Path: operationPath, 223 } 224 225 queryURL := serverURL.ResolveReference(&operationURL) 226 227 req, err := http.NewRequest("GET", queryURL.String(), nil) 228 if err != nil { 229 return nil, err 230 } 231 232 return req, nil 233 } 234 235 // NewProjectArtifactExistsRequest generates requests for ProjectArtifactExists 236 func NewProjectArtifactExistsRequest(server string, projectName string, artifactId string) (*http.Request, error) { 237 var err error 238 239 var pathParam0 string 240 241 pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectName", runtime.ParamLocationPath, projectName) 242 if err != nil { 243 return nil, err 244 } 245 246 var pathParam1 string 247 248 pathParam1, err = runtime.StyleParamWithLocation("simple", false, "artifactId", runtime.ParamLocationPath, artifactId) 249 if err != nil { 250 return nil, err 251 } 252 253 serverURL, err := url.Parse(server) 254 if err != nil { 255 return nil, err 256 } 257 258 operationPath := fmt.Sprintf("/api/project/%s/artifact/%s", pathParam0, pathParam1) 259 if operationPath[0] == '/' { 260 operationPath = operationPath[1:] 261 } 262 operationURL := url.URL{ 263 Path: operationPath, 264 } 265 266 queryURL := serverURL.ResolveReference(&operationURL) 267 268 req, err := http.NewRequest("HEAD", queryURL.String(), nil) 269 if err != nil { 270 return nil, err 271 } 272 273 return req, nil 274 } 275 276 // NewGetProjectArtifactsRequest generates requests for GetProjectArtifacts 277 func NewGetProjectArtifactsRequest(server string, projectName string) (*http.Request, error) { 278 var err error 279 280 var pathParam0 string 281 282 pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectName", runtime.ParamLocationPath, projectName) 283 if err != nil { 284 return nil, err 285 } 286 287 serverURL, err := url.Parse(server) 288 if err != nil { 289 return nil, err 290 } 291 292 operationPath := fmt.Sprintf("/api/project/%s/artifacts", pathParam0) 293 if operationPath[0] == '/' { 294 operationPath = operationPath[1:] 295 } 296 operationURL := url.URL{ 297 Path: operationPath, 298 } 299 300 queryURL := serverURL.ResolveReference(&operationURL) 301 302 req, err := http.NewRequest("GET", queryURL.String(), nil) 303 if err != nil { 304 return nil, err 305 } 306 307 return req, nil 308 } 309 310 // NewUploadArtifactRequestWithBody generates requests for UploadArtifact with any type of body 311 func NewUploadArtifactRequestWithBody(server string, projectName string, contentType string, body io.Reader) (*http.Request, error) { 312 var err error 313 314 var pathParam0 string 315 316 pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectName", runtime.ParamLocationPath, projectName) 317 if err != nil { 318 return nil, err 319 } 320 321 serverURL, err := url.Parse(server) 322 if err != nil { 323 return nil, err 324 } 325 326 operationPath := fmt.Sprintf("/api/project/%s/artifacts", pathParam0) 327 if operationPath[0] == '/' { 328 operationPath = operationPath[1:] 329 } 330 operationURL := url.URL{ 331 Path: operationPath, 332 } 333 334 queryURL := serverURL.ResolveReference(&operationURL) 335 336 req, err := http.NewRequest("POST", queryURL.String(), body) 337 if err != nil { 338 return nil, err 339 } 340 341 req.Header.Add("Content-Type", contentType) 342 343 return req, nil 344 } 345 346 func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 347 for _, r := range c.RequestEditors { 348 if err := r(ctx, req); err != nil { 349 return err 350 } 351 } 352 for _, r := range additionalEditors { 353 if err := r(ctx, req); err != nil { 354 return err 355 } 356 } 357 return nil 358 } 359 360 // ClientWithResponses builds on ClientInterface to offer response payloads 361 type ClientWithResponses struct { 362 ClientInterface 363 } 364 365 // NewClientWithResponses creates a new ClientWithResponses, which wraps 366 // Client with return type handling 367 func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 368 client, err := NewClient(server, opts...) 369 if err != nil { 370 return nil, err 371 } 372 return &ClientWithResponses{client}, nil 373 } 374 375 // WithBaseURL overrides the baseURL. 376 func WithBaseURL(baseURL string) ClientOption { 377 return func(c *Client) error { 378 newBaseURL, err := url.Parse(baseURL) 379 if err != nil { 380 return err 381 } 382 c.Server = newBaseURL.String() 383 return nil 384 } 385 } 386 387 // ClientWithResponsesInterface is the interface specification for the client with responses above. 388 type ClientWithResponsesInterface interface { 389 // GetHealth request 390 GetHealthWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetHealthResponse, error) 391 392 // GetProjectArtifact request 393 GetProjectArtifactWithResponse(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*GetProjectArtifactResponse, error) 394 395 // ProjectArtifactExists request 396 ProjectArtifactExistsWithResponse(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*ProjectArtifactExistsResponse, error) 397 398 // GetProjectArtifacts request 399 GetProjectArtifactsWithResponse(ctx context.Context, projectName string, reqEditors ...RequestEditorFn) (*GetProjectArtifactsResponse, error) 400 401 // UploadArtifact request with any body 402 UploadArtifactWithBodyWithResponse(ctx context.Context, projectName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadArtifactResponse, error) 403 } 404 405 type GetHealthResponse struct { 406 Body []byte 407 HTTPResponse *http.Response 408 JSON200 *Success 409 JSONDefault *Error 410 } 411 412 // Status returns HTTPResponse.Status 413 func (r GetHealthResponse) Status() string { 414 if r.HTTPResponse != nil { 415 return r.HTTPResponse.Status 416 } 417 return http.StatusText(0) 418 } 419 420 // StatusCode returns HTTPResponse.StatusCode 421 func (r GetHealthResponse) StatusCode() int { 422 if r.HTTPResponse != nil { 423 return r.HTTPResponse.StatusCode 424 } 425 return 0 426 } 427 428 type GetProjectArtifactResponse struct { 429 Body []byte 430 HTTPResponse *http.Response 431 JSON200 *Artifact 432 } 433 434 // Status returns HTTPResponse.Status 435 func (r GetProjectArtifactResponse) Status() string { 436 if r.HTTPResponse != nil { 437 return r.HTTPResponse.Status 438 } 439 return http.StatusText(0) 440 } 441 442 // StatusCode returns HTTPResponse.StatusCode 443 func (r GetProjectArtifactResponse) StatusCode() int { 444 if r.HTTPResponse != nil { 445 return r.HTTPResponse.StatusCode 446 } 447 return 0 448 } 449 450 type ProjectArtifactExistsResponse struct { 451 Body []byte 452 HTTPResponse *http.Response 453 } 454 455 // Status returns HTTPResponse.Status 456 func (r ProjectArtifactExistsResponse) Status() string { 457 if r.HTTPResponse != nil { 458 return r.HTTPResponse.Status 459 } 460 return http.StatusText(0) 461 } 462 463 // StatusCode returns HTTPResponse.StatusCode 464 func (r ProjectArtifactExistsResponse) StatusCode() int { 465 if r.HTTPResponse != nil { 466 return r.HTTPResponse.StatusCode 467 } 468 return 0 469 } 470 471 type GetProjectArtifactsResponse struct { 472 Body []byte 473 HTTPResponse *http.Response 474 JSON200 *ArtifactIds 475 } 476 477 // Status returns HTTPResponse.Status 478 func (r GetProjectArtifactsResponse) Status() string { 479 if r.HTTPResponse != nil { 480 return r.HTTPResponse.Status 481 } 482 return http.StatusText(0) 483 } 484 485 // StatusCode returns HTTPResponse.StatusCode 486 func (r GetProjectArtifactsResponse) StatusCode() int { 487 if r.HTTPResponse != nil { 488 return r.HTTPResponse.StatusCode 489 } 490 return 0 491 } 492 493 type UploadArtifactResponse struct { 494 Body []byte 495 HTTPResponse *http.Response 496 } 497 498 // Status returns HTTPResponse.Status 499 func (r UploadArtifactResponse) Status() string { 500 if r.HTTPResponse != nil { 501 return r.HTTPResponse.Status 502 } 503 return http.StatusText(0) 504 } 505 506 // StatusCode returns HTTPResponse.StatusCode 507 func (r UploadArtifactResponse) StatusCode() int { 508 if r.HTTPResponse != nil { 509 return r.HTTPResponse.StatusCode 510 } 511 return 0 512 } 513 514 // GetHealthWithResponse request returning *GetHealthResponse 515 func (c *ClientWithResponses) GetHealthWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetHealthResponse, error) { 516 rsp, err := c.GetHealth(ctx, reqEditors...) 517 if err != nil { 518 return nil, err 519 } 520 return ParseGetHealthResponse(rsp) 521 } 522 523 // GetProjectArtifactWithResponse request returning *GetProjectArtifactResponse 524 func (c *ClientWithResponses) GetProjectArtifactWithResponse(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*GetProjectArtifactResponse, error) { 525 rsp, err := c.GetProjectArtifact(ctx, projectName, artifactId, reqEditors...) 526 if err != nil { 527 return nil, err 528 } 529 return ParseGetProjectArtifactResponse(rsp) 530 } 531 532 // ProjectArtifactExistsWithResponse request returning *ProjectArtifactExistsResponse 533 func (c *ClientWithResponses) ProjectArtifactExistsWithResponse(ctx context.Context, projectName string, artifactId string, reqEditors ...RequestEditorFn) (*ProjectArtifactExistsResponse, error) { 534 rsp, err := c.ProjectArtifactExists(ctx, projectName, artifactId, reqEditors...) 535 if err != nil { 536 return nil, err 537 } 538 return ParseProjectArtifactExistsResponse(rsp) 539 } 540 541 // GetProjectArtifactsWithResponse request returning *GetProjectArtifactsResponse 542 func (c *ClientWithResponses) GetProjectArtifactsWithResponse(ctx context.Context, projectName string, reqEditors ...RequestEditorFn) (*GetProjectArtifactsResponse, error) { 543 rsp, err := c.GetProjectArtifacts(ctx, projectName, reqEditors...) 544 if err != nil { 545 return nil, err 546 } 547 return ParseGetProjectArtifactsResponse(rsp) 548 } 549 550 // UploadArtifactWithBodyWithResponse request with arbitrary body returning *UploadArtifactResponse 551 func (c *ClientWithResponses) UploadArtifactWithBodyWithResponse(ctx context.Context, projectName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadArtifactResponse, error) { 552 rsp, err := c.UploadArtifactWithBody(ctx, projectName, contentType, body, reqEditors...) 553 if err != nil { 554 return nil, err 555 } 556 return ParseUploadArtifactResponse(rsp) 557 } 558 559 // ParseGetHealthResponse parses an HTTP response from a GetHealthWithResponse call 560 func ParseGetHealthResponse(rsp *http.Response) (*GetHealthResponse, error) { 561 bodyBytes, err := io.ReadAll(rsp.Body) 562 defer rsp.Body.Close() 563 if err != nil { 564 return nil, err 565 } 566 567 response := &GetHealthResponse{ 568 Body: bodyBytes, 569 HTTPResponse: rsp, 570 } 571 572 switch { 573 case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 574 var dest Success 575 if err := json.Unmarshal(bodyBytes, &dest); err != nil { 576 return nil, err 577 } 578 response.JSON200 = &dest 579 580 case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: 581 var dest Error 582 if err := json.Unmarshal(bodyBytes, &dest); err != nil { 583 return nil, err 584 } 585 response.JSONDefault = &dest 586 587 } 588 589 return response, nil 590 } 591 592 // ParseGetProjectArtifactResponse parses an HTTP response from a GetProjectArtifactWithResponse call 593 func ParseGetProjectArtifactResponse(rsp *http.Response) (*GetProjectArtifactResponse, error) { 594 bodyBytes, err := io.ReadAll(rsp.Body) 595 defer rsp.Body.Close() 596 if err != nil { 597 return nil, err 598 } 599 600 response := &GetProjectArtifactResponse{ 601 Body: bodyBytes, 602 HTTPResponse: rsp, 603 } 604 605 switch { 606 case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 607 var dest Artifact 608 if err := json.Unmarshal(bodyBytes, &dest); err != nil { 609 return nil, err 610 } 611 response.JSON200 = &dest 612 613 } 614 615 return response, nil 616 } 617 618 // ParseProjectArtifactExistsResponse parses an HTTP response from a ProjectArtifactExistsWithResponse call 619 func ParseProjectArtifactExistsResponse(rsp *http.Response) (*ProjectArtifactExistsResponse, error) { 620 bodyBytes, err := io.ReadAll(rsp.Body) 621 defer rsp.Body.Close() 622 if err != nil { 623 return nil, err 624 } 625 626 response := &ProjectArtifactExistsResponse{ 627 Body: bodyBytes, 628 HTTPResponse: rsp, 629 } 630 631 switch { 632 } 633 634 return response, nil 635 } 636 637 // ParseGetProjectArtifactsResponse parses an HTTP response from a GetProjectArtifactsWithResponse call 638 func ParseGetProjectArtifactsResponse(rsp *http.Response) (*GetProjectArtifactsResponse, error) { 639 bodyBytes, err := io.ReadAll(rsp.Body) 640 defer rsp.Body.Close() 641 if err != nil { 642 return nil, err 643 } 644 645 response := &GetProjectArtifactsResponse{ 646 Body: bodyBytes, 647 HTTPResponse: rsp, 648 } 649 650 switch { 651 case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 652 var dest ArtifactIds 653 if err := json.Unmarshal(bodyBytes, &dest); err != nil { 654 return nil, err 655 } 656 response.JSON200 = &dest 657 658 } 659 660 return response, nil 661 } 662 663 // ParseUploadArtifactResponse parses an HTTP response from a UploadArtifactWithResponse call 664 func ParseUploadArtifactResponse(rsp *http.Response) (*UploadArtifactResponse, error) { 665 bodyBytes, err := io.ReadAll(rsp.Body) 666 defer rsp.Body.Close() 667 if err != nil { 668 return nil, err 669 } 670 671 response := &UploadArtifactResponse{ 672 Body: bodyBytes, 673 HTTPResponse: rsp, 674 } 675 676 switch { 677 } 678 679 return response, nil 680 }