From 46a2b1893e2a9c3275fa5294a64fabbb688924e1 Mon Sep 17 00:00:00 2001 From: cq-bot Date: Thu, 4 Jan 2024 14:18:40 +0000 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` --- client.gen.go | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++ models.gen.go | 32 +++++++++ spec.json | 124 ++++++++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+) diff --git a/client.gen.go b/client.gen.go index b7db3c2..2b39b05 100644 --- a/client.gen.go +++ b/client.gen.go @@ -286,6 +286,11 @@ type ClientInterface interface { // DeleteTeamAPIKey request DeleteTeamAPIKey(ctx context.Context, teamName TeamName, aPIKeyID APIKeyID, reqEditors ...RequestEditorFn) (*http.Response, error) + // CreateTeamImagesWithBody request with any body + CreateTeamImagesWithBody(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateTeamImages(ctx context.Context, teamName TeamName, body CreateTeamImagesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // ListTeamInvitations request ListTeamInvitations(ctx context.Context, teamName TeamName, params *ListTeamInvitationsParams, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1282,6 +1287,30 @@ func (c *Client) DeleteTeamAPIKey(ctx context.Context, teamName TeamName, aPIKey return c.Client.Do(req) } +func (c *Client) CreateTeamImagesWithBody(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateTeamImagesRequestWithBody(c.Server, teamName, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateTeamImages(ctx context.Context, teamName TeamName, body CreateTeamImagesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateTeamImagesRequest(c.Server, teamName, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) ListTeamInvitations(ctx context.Context, teamName TeamName, params *ListTeamInvitationsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewListTeamInvitationsRequest(c.Server, teamName, params) if err != nil { @@ -5119,6 +5148,53 @@ func NewDeleteTeamAPIKeyRequest(server string, teamName TeamName, aPIKeyID APIKe return req, nil } +// NewCreateTeamImagesRequest calls the generic CreateTeamImages builder with application/json body +func NewCreateTeamImagesRequest(server string, teamName TeamName, body CreateTeamImagesJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateTeamImagesRequestWithBody(server, teamName, "application/json", bodyReader) +} + +// NewCreateTeamImagesRequestWithBody generates requests for CreateTeamImages with any type of body +func NewCreateTeamImagesRequestWithBody(server string, teamName TeamName, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "team_name", runtime.ParamLocationPath, teamName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/images", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewListTeamInvitationsRequest generates requests for ListTeamInvitations func NewListTeamInvitationsRequest(server string, teamName TeamName, params *ListTeamInvitationsParams) (*http.Request, error) { var err error @@ -7402,6 +7478,11 @@ type ClientWithResponsesInterface interface { // DeleteTeamAPIKeyWithResponse request DeleteTeamAPIKeyWithResponse(ctx context.Context, teamName TeamName, aPIKeyID APIKeyID, reqEditors ...RequestEditorFn) (*DeleteTeamAPIKeyResponse, error) + // CreateTeamImagesWithBodyWithResponse request with any body + CreateTeamImagesWithBodyWithResponse(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateTeamImagesResponse, error) + + CreateTeamImagesWithResponse(ctx context.Context, teamName TeamName, body CreateTeamImagesJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateTeamImagesResponse, error) + // ListTeamInvitationsWithResponse request ListTeamInvitationsWithResponse(ctx context.Context, teamName TeamName, params *ListTeamInvitationsParams, reqEditors ...RequestEditorFn) (*ListTeamInvitationsResponse, error) @@ -8955,6 +9036,35 @@ func (r DeleteTeamAPIKeyResponse) StatusCode() int { return 0 } +type CreateTeamImagesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *struct { + Items []TeamImage `json:"items"` + Metadata ListMetadata `json:"metadata"` + } + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r CreateTeamImagesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateTeamImagesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type ListTeamInvitationsResponse struct { Body []byte HTTPResponse *http.Response @@ -10577,6 +10687,23 @@ func (c *ClientWithResponses) DeleteTeamAPIKeyWithResponse(ctx context.Context, return ParseDeleteTeamAPIKeyResponse(rsp) } +// CreateTeamImagesWithBodyWithResponse request with arbitrary body returning *CreateTeamImagesResponse +func (c *ClientWithResponses) CreateTeamImagesWithBodyWithResponse(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateTeamImagesResponse, error) { + rsp, err := c.CreateTeamImagesWithBody(ctx, teamName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateTeamImagesResponse(rsp) +} + +func (c *ClientWithResponses) CreateTeamImagesWithResponse(ctx context.Context, teamName TeamName, body CreateTeamImagesJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateTeamImagesResponse, error) { + rsp, err := c.CreateTeamImages(ctx, teamName, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateTeamImagesResponse(rsp) +} + // ListTeamInvitationsWithResponse request returning *ListTeamInvitationsResponse func (c *ClientWithResponses) ListTeamInvitationsWithResponse(ctx context.Context, teamName TeamName, params *ListTeamInvitationsParams, reqEditors ...RequestEditorFn) (*ListTeamInvitationsResponse, error) { rsp, err := c.ListTeamInvitations(ctx, teamName, params, reqEditors...) @@ -13880,6 +14007,63 @@ func ParseDeleteTeamAPIKeyResponse(rsp *http.Response) (*DeleteTeamAPIKeyRespons return response, nil } +// ParseCreateTeamImagesResponse parses an HTTP response from a CreateTeamImagesWithResponse call +func ParseCreateTeamImagesResponse(rsp *http.Response) (*CreateTeamImagesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateTeamImagesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest struct { + Items []TeamImage `json:"items"` + Metadata ListMetadata `json:"metadata"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest RequiresAuthentication + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest Forbidden + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + // ParseListTeamInvitationsResponse parses an HTTP response from a ListTeamInvitationsWithResponse call func ParseListTeamInvitationsResponse(rsp *http.Response) (*ListTeamInvitationsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index 51ed1ce..d3c63f2 100644 --- a/models.gen.go +++ b/models.gen.go @@ -1131,6 +1131,30 @@ type Team struct { Plan *TeamPlan `json:"plan,omitempty"` } +// TeamImage defines model for TeamImage. +type TeamImage struct { + // Checksum SHA1 checksum of image + Checksum string `json:"checksum"` + + // Name Name of image + Name string `json:"name"` + + // UploadUrl URL to upload image + UploadUrl *string `json:"upload_url,omitempty"` + + // Url URL to download image + Url string `json:"url"` +} + +// TeamImageCreate defines model for TeamImageCreate. +type TeamImageCreate struct { + // Checksum SHA1 checksum of image + Checksum string `json:"checksum"` + + // Name Name of image + Name string `json:"name"` +} + // TeamName The unique name for the team. type TeamName = string @@ -1561,6 +1585,11 @@ type CreateTeamAPIKeyJSONBody struct { Name APIKeyName `json:"name"` } +// CreateTeamImagesJSONBody defines parameters for CreateTeamImages. +type CreateTeamImagesJSONBody struct { + Images []TeamImageCreate `json:"images"` +} + // ListTeamInvitationsParams defines parameters for ListTeamInvitations. type ListTeamInvitationsParams struct { // Page Page number of the results to fetch @@ -1807,6 +1836,9 @@ type CreateAddonOrderForTeamJSONRequestBody = AddonOrderCreate // CreateTeamAPIKeyJSONRequestBody defines body for CreateTeamAPIKey for application/json ContentType. type CreateTeamAPIKeyJSONRequestBody CreateTeamAPIKeyJSONBody +// CreateTeamImagesJSONRequestBody defines body for CreateTeamImages for application/json ContentType. +type CreateTeamImagesJSONRequestBody CreateTeamImagesJSONBody + // EmailTeamInvitationJSONRequestBody defines body for EmailTeamInvitation for application/json ContentType. type EmailTeamInvitationJSONRequestBody EmailTeamInvitationJSONBody diff --git a/spec.json b/spec.json index 7fb5698..91047fd 100644 --- a/spec.json +++ b/spec.json @@ -2517,6 +2517,82 @@ ] } }, + "/teams/{team_name}/images": { + "post": { + "description": "Get URLs to upload images for a given team", + "operationId": "CreateTeamImages", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "images" + ], + "properties": { + "images": { + "items": { + "$ref": "#/components/schemas/TeamImageCreate" + }, + "type": "array", + "minItems": 1 + } + } + } + } + } + }, + "responses": { + "201": { + "description": "Response", + "content": { + "application/json": { + "schema": { + "required": [ + "items", + "metadata" + ], + "properties": { + "items": { + "items": { + "$ref": "#/components/schemas/TeamImage" + }, + "type": "array" + }, + "metadata": { + "$ref": "#/components/schemas/ListMetadata" + } + } + } + } + } + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "teams", + "plugins", + "addons" + ] + } + }, "/teams/{team_name}/plugins": { "get": { "description": "List all plugins for the team.", @@ -6401,6 +6477,54 @@ "title": "Team", "type": "object" }, + "TeamImageCreate": { + "type": "object", + "title": "Create Team Image Request", + "additionalProperties": false, + "required": [ + "name", + "checksum" + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 64, + "description": "Name of image" + }, + "checksum": { + "type": "string", + "length": 40, + "pattern": "^[a-f0-9]+$", + "description": "SHA1 checksum of image" + } + } + }, + "TeamImage": { + "required": [ + "url", + "name", + "checksum" + ], + "properties": { + "name": { + "type": "string", + "description": "Name of image" + }, + "checksum": { + "type": "string", + "description": "SHA1 checksum of image" + }, + "url": { + "type": "string", + "description": "URL to download image" + }, + "upload_url": { + "type": "string", + "description": "URL to upload image" + } + } + }, "AddonOrderID": { "description": "ID of the addon order", "type": "string",