From bcf1462886b934c9cdb4754c37f45e48b1ba9d5d Mon Sep 17 00:00:00 2001 From: CloudQuery Bot <102256036+cq-bot@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:24:11 +0200 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` (#110) This PR was created by a scheduled workflow to generate the CloudQuery Go API Client from `spec.json` --- client.gen.go | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++ models.gen.go | 12 ++++ spec.json | 69 +++++++++++++++++- 3 files changed, 272 insertions(+), 1 deletion(-) diff --git a/client.gen.go b/client.gen.go index 6f566ee..fbe2726 100644 --- a/client.gen.go +++ b/client.gen.go @@ -388,6 +388,11 @@ type ClientInterface interface { UpdateSyncRun(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body UpdateSyncRunJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // CreateSyncRunProgressWithBody request with any body + CreateSyncRunProgressWithBody(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateSyncRunProgress(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body CreateSyncRunProgressJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // ListTeamPluginUsage request ListTeamPluginUsage(ctx context.Context, teamName TeamName, params *ListTeamPluginUsageParams, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1731,6 +1736,30 @@ func (c *Client) UpdateSyncRun(ctx context.Context, teamName TeamName, syncName return c.Client.Do(req) } +func (c *Client) CreateSyncRunProgressWithBody(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateSyncRunProgressRequestWithBody(c.Server, teamName, syncName, syncRunId, 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) CreateSyncRunProgress(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body CreateSyncRunProgressJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateSyncRunProgressRequest(c.Server, teamName, syncName, syncRunId, 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) ListTeamPluginUsage(ctx context.Context, teamName TeamName, params *ListTeamPluginUsageParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewListTeamPluginUsageRequest(c.Server, teamName, params) if err != nil { @@ -6734,6 +6763,67 @@ func NewUpdateSyncRunRequestWithBody(server string, teamName TeamName, syncName return req, nil } +// NewCreateSyncRunProgressRequest calls the generic CreateSyncRunProgress builder with application/json body +func NewCreateSyncRunProgressRequest(server string, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body CreateSyncRunProgressJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateSyncRunProgressRequestWithBody(server, teamName, syncName, syncRunId, "application/json", bodyReader) +} + +// NewCreateSyncRunProgressRequestWithBody generates requests for CreateSyncRunProgress with any type of body +func NewCreateSyncRunProgressRequestWithBody(server string, teamName TeamName, syncName SyncName, syncRunId SyncRunId, 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 + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "sync_name", runtime.ParamLocationPath, syncName) + if err != nil { + return nil, err + } + + var pathParam2 string + + pathParam2, err = runtime.StyleParamWithLocation("simple", false, "sync_run_id", runtime.ParamLocationPath, syncRunId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/syncs/%s/runs/%s/progress", pathParam0, pathParam1, pathParam2) + 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 +} + // NewListTeamPluginUsageRequest generates requests for ListTeamPluginUsage func NewListTeamPluginUsageRequest(server string, teamName TeamName, params *ListTeamPluginUsageParams) (*http.Request, error) { var err error @@ -7580,6 +7670,11 @@ type ClientWithResponsesInterface interface { UpdateSyncRunWithResponse(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body UpdateSyncRunJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateSyncRunResponse, error) + // CreateSyncRunProgressWithBodyWithResponse request with any body + CreateSyncRunProgressWithBodyWithResponse(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSyncRunProgressResponse, error) + + CreateSyncRunProgressWithResponse(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body CreateSyncRunProgressJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSyncRunProgressResponse, error) + // ListTeamPluginUsageWithResponse request ListTeamPluginUsageWithResponse(ctx context.Context, teamName TeamName, params *ListTeamPluginUsageParams, reqEditors ...RequestEditorFn) (*ListTeamPluginUsageResponse, error) @@ -9791,6 +9886,32 @@ func (r UpdateSyncRunResponse) StatusCode() int { return 0 } +type CreateSyncRunProgressResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON404 *NotFound + JSON422 *UnprocessableEntity + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r CreateSyncRunProgressResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateSyncRunProgressResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type ListTeamPluginUsageResponse struct { Body []byte HTTPResponse *http.Response @@ -11012,6 +11133,23 @@ func (c *ClientWithResponses) UpdateSyncRunWithResponse(ctx context.Context, tea return ParseUpdateSyncRunResponse(rsp) } +// CreateSyncRunProgressWithBodyWithResponse request with arbitrary body returning *CreateSyncRunProgressResponse +func (c *ClientWithResponses) CreateSyncRunProgressWithBodyWithResponse(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSyncRunProgressResponse, error) { + rsp, err := c.CreateSyncRunProgressWithBody(ctx, teamName, syncName, syncRunId, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateSyncRunProgressResponse(rsp) +} + +func (c *ClientWithResponses) CreateSyncRunProgressWithResponse(ctx context.Context, teamName TeamName, syncName SyncName, syncRunId SyncRunId, body CreateSyncRunProgressJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSyncRunProgressResponse, error) { + rsp, err := c.CreateSyncRunProgress(ctx, teamName, syncName, syncRunId, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateSyncRunProgressResponse(rsp) +} + // ListTeamPluginUsageWithResponse request returning *ListTeamPluginUsageResponse func (c *ClientWithResponses) ListTeamPluginUsageWithResponse(ctx context.Context, teamName TeamName, params *ListTeamPluginUsageParams, reqEditors ...RequestEditorFn) (*ListTeamPluginUsageResponse, error) { rsp, err := c.ListTeamPluginUsage(ctx, teamName, params, reqEditors...) @@ -15547,6 +15685,60 @@ func ParseUpdateSyncRunResponse(rsp *http.Response) (*UpdateSyncRunResponse, err return response, nil } +// ParseCreateSyncRunProgressResponse parses an HTTP response from a CreateSyncRunProgressWithResponse call +func ParseCreateSyncRunProgressResponse(rsp *http.Response) (*CreateSyncRunProgressResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateSyncRunProgressResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &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 == 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 == 422: + var dest UnprocessableEntity + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON422 = &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 +} + // ParseListTeamPluginUsageResponse parses an HTTP response from a ListTeamPluginUsageWithResponse call func ParseListTeamPluginUsageResponse(rsp *http.Response) (*ListTeamPluginUsageResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index e7f9cc0..8f3ed55 100644 --- a/models.gen.go +++ b/models.gen.go @@ -1159,6 +1159,9 @@ type SyncRun struct { // SyncName Name of the sync SyncName string `json:"sync_name"` + + // TotalRows Total number of rows in the sync + TotalRows int64 `json:"total_rows"` } // SyncRunID ID of the SyncRun @@ -1781,6 +1784,12 @@ type UpdateSyncRunJSONBody struct { Status *SyncRunStatus `json:"status,omitempty"` } +// CreateSyncRunProgressJSONBody defines parameters for CreateSyncRunProgress. +type CreateSyncRunProgressJSONBody struct { + // Rows Number of rows synced so far + Rows int64 `json:"rows"` +} + // ListTeamPluginUsageParams defines parameters for ListTeamPluginUsage. type ListTeamPluginUsageParams struct { // Page Page number of the results to fetch @@ -1907,6 +1916,9 @@ type UpdateSyncJSONRequestBody UpdateSyncJSONBody // UpdateSyncRunJSONRequestBody defines body for UpdateSyncRun for application/json ContentType. type UpdateSyncRunJSONRequestBody UpdateSyncRunJSONBody +// CreateSyncRunProgressJSONRequestBody defines body for CreateSyncRunProgress for application/json ContentType. +type CreateSyncRunProgressJSONRequestBody CreateSyncRunProgressJSONBody + // IncreaseTeamPluginUsageJSONRequestBody defines body for IncreaseTeamPluginUsage for application/json ContentType. type IncreaseTeamPluginUsageJSONRequestBody = UsageIncrease diff --git a/spec.json b/spec.json index cc9b6b9..b23c871 100644 --- a/spec.json +++ b/spec.json @@ -5042,6 +5042,67 @@ } } } + }, + "/teams/{team_name}/syncs/{sync_name}/runs/{sync_run_id}/progress": { + "post": { + "description": "Create a new sync run progress update.", + "operationId": "CreateSyncRunProgress", + "x-internal": true, + "tags": [ + "syncs" + ], + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + }, + { + "$ref": "#/components/parameters/sync_name" + }, + { + "$ref": "#/components/parameters/sync_run_id" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "rows" + ], + "properties": { + "rows": { + "type": "integer", + "format": "int64", + "description": "Number of rows synced so far" + } + } + } + } + } + }, + "responses": { + "204": { + "description": "Progress was reported successfully" + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "422": { + "$ref": "#/components/responses/UnprocessableEntity" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + } + } } }, "components": { @@ -7258,7 +7319,8 @@ "sync_name", "id", "status", - "started_at" + "started_at", + "total_rows" ], "properties": { "sync_name": { @@ -7287,6 +7349,11 @@ "format": "date-time", "type": "string", "description": "Cron schedule for the sync" + }, + "total_rows": { + "type": "integer", + "format": "int64", + "description": "Total number of rows in the sync" } } },