From 32f8353a685ea2359ebd0f867e8629fdf5fa35e4 Mon Sep 17 00:00:00 2001 From: cq-bot Date: Thu, 23 Nov 2023 14:29:06 +0000 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` --- client.gen.go | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++ models.gen.go | 37 ++++++++--- spec.json | 114 ++++++++++++++++++++++++++++++--- 3 files changed, 305 insertions(+), 18 deletions(-) diff --git a/client.gen.go b/client.gen.go index 09f2250..b733f93 100644 --- a/client.gen.go +++ b/client.gen.go @@ -227,6 +227,9 @@ type ClientInterface interface { CreateAddonOrderForTeam(ctx context.Context, teamName TeamName, body CreateAddonOrderForTeamJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetAddonOrderByTeam request + GetAddonOrderByTeam(ctx context.Context, teamName TeamName, addonOrderID AddonOrderID, reqEditors ...RequestEditorFn) (*http.Response, error) + // DeleteAddonsByTeam request DeleteAddonsByTeam(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -938,6 +941,18 @@ func (c *Client) CreateAddonOrderForTeam(ctx context.Context, teamName TeamName, return c.Client.Do(req) } +func (c *Client) GetAddonOrderByTeam(ctx context.Context, teamName TeamName, addonOrderID AddonOrderID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetAddonOrderByTeamRequest(c.Server, teamName, addonOrderID) + 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) DeleteAddonsByTeam(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewDeleteAddonsByTeamRequest(c.Server, teamName) if err != nil { @@ -3648,6 +3663,47 @@ func NewCreateAddonOrderForTeamRequestWithBody(server string, teamName TeamName, return req, nil } +// NewGetAddonOrderByTeamRequest generates requests for GetAddonOrderByTeam +func NewGetAddonOrderByTeamRequest(server string, teamName TeamName, addonOrderID AddonOrderID) (*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, "addon_order_id", runtime.ParamLocationPath, addonOrderID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/addon-orders/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewDeleteAddonsByTeamRequest generates requests for DeleteAddonsByTeam func NewDeleteAddonsByTeamRequest(server string, teamName TeamName) (*http.Request, error) { var err error @@ -5440,6 +5496,9 @@ type ClientWithResponsesInterface interface { CreateAddonOrderForTeamWithResponse(ctx context.Context, teamName TeamName, body CreateAddonOrderForTeamJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateAddonOrderForTeamResponse, error) + // GetAddonOrderByTeamWithResponse request + GetAddonOrderByTeamWithResponse(ctx context.Context, teamName TeamName, addonOrderID AddonOrderID, reqEditors ...RequestEditorFn) (*GetAddonOrderByTeamResponse, error) + // DeleteAddonsByTeamWithResponse request DeleteAddonsByTeamWithResponse(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*DeleteAddonsByTeamResponse, error) @@ -5806,6 +5865,7 @@ type DownloadAddonAssetResponse struct { HTTPResponse *http.Response JSON200 *AddonAsset JSON401 *RequiresAuthentication + JSON403 *Forbidden JSON404 *NotFound JSON429 *TooManyRequests JSON500 *InternalError @@ -6478,6 +6538,7 @@ func (r ListAddonOrdersByTeamResponse) StatusCode() int { type CreateAddonOrderForTeamResponse struct { Body []byte HTTPResponse *http.Response + JSON201 *AddonOrder JSON400 *BadRequest JSON401 *RequiresAuthentication JSON404 *NotFound @@ -6500,6 +6561,32 @@ func (r CreateAddonOrderForTeamResponse) StatusCode() int { return 0 } +type GetAddonOrderByTeamResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *AddonOrder + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r GetAddonOrderByTeamResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetAddonOrderByTeamResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type DeleteAddonsByTeamResponse struct { Body []byte HTTPResponse *http.Response @@ -6560,6 +6647,7 @@ type DownloadAddonAssetByTeamResponse struct { HTTPResponse *http.Response JSON200 *AddonAsset JSON401 *RequiresAuthentication + JSON403 *Forbidden JSON404 *NotFound JSON429 *TooManyRequests JSON500 *InternalError @@ -7693,6 +7781,15 @@ func (c *ClientWithResponses) CreateAddonOrderForTeamWithResponse(ctx context.Co return ParseCreateAddonOrderForTeamResponse(rsp) } +// GetAddonOrderByTeamWithResponse request returning *GetAddonOrderByTeamResponse +func (c *ClientWithResponses) GetAddonOrderByTeamWithResponse(ctx context.Context, teamName TeamName, addonOrderID AddonOrderID, reqEditors ...RequestEditorFn) (*GetAddonOrderByTeamResponse, error) { + rsp, err := c.GetAddonOrderByTeam(ctx, teamName, addonOrderID, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetAddonOrderByTeamResponse(rsp) +} + // DeleteAddonsByTeamWithResponse request returning *DeleteAddonsByTeamResponse func (c *ClientWithResponses) DeleteAddonsByTeamWithResponse(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*DeleteAddonsByTeamResponse, error) { rsp, err := c.DeleteAddonsByTeam(ctx, teamName, reqEditors...) @@ -8544,6 +8641,13 @@ func ParseDownloadAddonAssetResponse(rsp *http.Response) (*DownloadAddonAssetRes } 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 { @@ -9916,6 +10020,13 @@ func ParseCreateAddonOrderForTeamResponse(rsp *http.Response) (*CreateAddonOrder } switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest AddonOrder + 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 == 400: var dest BadRequest if err := json.Unmarshal(bodyBytes, &dest); err != nil { @@ -9949,6 +10060,60 @@ func ParseCreateAddonOrderForTeamResponse(rsp *http.Response) (*CreateAddonOrder return response, nil } +// ParseGetAddonOrderByTeamResponse parses an HTTP response from a GetAddonOrderByTeamWithResponse call +func ParseGetAddonOrderByTeamResponse(rsp *http.Response) (*GetAddonOrderByTeamResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetAddonOrderByTeamResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest AddonOrder + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &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 +} + // ParseDeleteAddonsByTeamResponse parses an HTTP response from a DeleteAddonsByTeamWithResponse call func ParseDeleteAddonsByTeamResponse(rsp *http.Response) (*DeleteAddonsByTeamResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -10088,6 +10253,13 @@ func ParseDownloadAddonAssetByTeamResponse(rsp *http.Response) (*DownloadAddonAs } 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 { diff --git a/models.gen.go b/models.gen.go index 4ee7372..29a33bb 100644 --- a/models.gen.go +++ b/models.gen.go @@ -32,6 +32,13 @@ const ( Zip AddonFormat = "zip" ) +// Defines values for AddonOrderStatus. +const ( + Cancelled AddonOrderStatus = "cancelled" + Completed AddonOrderStatus = "completed" + Pending AddonOrderStatus = "pending" +) + // Defines values for AddonTier. const ( AddonTierFree AddonTier = "free" @@ -154,7 +161,7 @@ type APIKey struct { ExpiresAt time.Time `json:"expires_at"` // Id ID of the API key - ID ID `json:"id"` + APIKeyID APIKeyID `json:"id"` // Key API key. Will be shown only in the response when creating the key. Key *string `json:"key,omitempty"` @@ -166,8 +173,8 @@ type APIKey struct { Scope APIKeyScope `json:"scope"` } -// ID ID of the API key -type ID = openapi_types.UUID +// APIKeyID ID of the API key +type APIKeyID = openapi_types.UUID // APIKeyName Name of the API key type APIKeyName = string @@ -274,11 +281,20 @@ type AddonOrder struct { AddonTeam TeamName `json:"addon_team"` // AddonType Supported types for addons - AddonType AddonType `json:"addon_type"` - PurchaseDate time.Time `json:"purchase_date"` + AddonType AddonType `json:"addon_type"` + CompletedAt *time.Time `json:"completed_at,omitempty"` + + // CompletionUrl Stripe URL for completing purchase. Only shown in response to POST request. + CompletionURL *string `json:"completion_url,omitempty"` + CreatedAt time.Time `json:"created_at"` + + // Id ID of the addon order + AddonOrderID AddonOrderID `json:"id"` + Status AddonOrderStatus `json:"status"` // TeamName The unique name for the team. - TeamName TeamName `json:"team_name"` + TeamName TeamName `json:"team_name"` + UpdatedAt time.Time `json:"updated_at"` } // AddonOrderCreate Create CloudQuery Addon Order @@ -299,6 +315,12 @@ type AddonOrderCreate struct { SuccessUrl string `json:"success_url"` } +// AddonOrderID ID of the addon order +type AddonOrderID = openapi_types.UUID + +// AddonOrderStatus defines model for AddonOrderStatus. +type AddonOrderStatus string + // AddonTier Supported tiers for addons type AddonTier string @@ -997,9 +1019,6 @@ type AddonSortBy string // AddonTeam The unique name for the team. type AddonTeam = TeamName -// APIKeyID ID of the API key -type APIKeyID = ID - // IncludeDrafts defines model for include_drafts. type IncludeDrafts = bool diff --git a/spec.json b/spec.json index 79999bf..69cb963 100644 --- a/spec.json +++ b/spec.json @@ -1787,6 +1787,9 @@ "401": { "$ref": "#/components/responses/RequiresAuthentication" }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, "404": { "$ref": "#/components/responses/NotFound" }, @@ -2359,15 +2362,15 @@ } }, "responses": { - "302": { - "headers": { - "Location": { + "201": { + "description": "Response", + "content": { + "application/json": { "schema": { - "type": "string" + "$ref": "#/components/schemas/AddonOrder" } } - }, - "description": "Response" + } }, "400": { "$ref": "#/components/responses/BadRequest" @@ -2387,6 +2390,47 @@ ] } }, + "/teams/{team_name}/addon-orders/{addon_order_id}": { + "get": { + "description": "Get an addon order for the team.", + "operationId": "GetAddonOrderByTeam", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + }, + { + "$ref": "#/components/parameters/addon_order_id" + } + ], + "responses": { + "200": { + "description": "Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddonOrder" + } + } + } + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "addons" + ] + } + }, "/teams/{team_name}/memberships": { "get": { "description": "Get memberships to the team.", @@ -2999,6 +3043,9 @@ "401": { "$ref": "#/components/responses/RequiresAuthentication" }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, "404": { "$ref": "#/components/responses/NotFound" }, @@ -4847,10 +4894,28 @@ "title": "Team", "type": "object" }, + "AddonOrderID": { + "description": "ID of the addon order", + "type": "string", + "format": "uuid", + "example": "12345678-1234-1234-1234-1234567890ab", + "x-go-name": "AddonOrderID" + }, + "AddonOrderStatus": { + "type": "string", + "enum": [ + "pending", + "completed", + "cancelled" + ] + }, "AddonOrder": { "additionalProperties": false, "description": "CloudQuery Addon Order", "properties": { + "id": { + "$ref": "#/components/schemas/AddonOrderID" + }, "team_name": { "$ref": "#/components/schemas/TeamName" }, @@ -4863,18 +4928,40 @@ "addon_name": { "$ref": "#/components/schemas/AddonName" }, - "purchase_date": { + "status": { + "$ref": "#/components/schemas/AddonOrderStatus" + }, + "created_at": { + "type": "string", + "format": "date-time", + "example": "2017-07-14T16:53:42Z" + }, + "updated_at": { "type": "string", "format": "date-time", "example": "2017-07-14T16:53:42Z" + }, + "completed_at": { + "type": "string", + "format": "date-time", + "example": "2017-07-14T16:53:42Z" + }, + "completion_url": { + "type": "string", + "format": "uri", + "description": "Stripe URL for completing purchase. Only shown in response to POST request.", + "x-go-name": "CompletionURL" } }, "required": [ + "id", "team_name", "addon_team", "addon_type", "addon_name", - "purchase_date" + "status", + "created_at", + "updated_at" ], "title": "CloudQuery Addon", "type": "object" @@ -5227,7 +5314,7 @@ "type": "string", "format": "uuid", "example": "12345678-1234-1234-1234-1234567890ab", - "x-go-name": "ID" + "x-go-name": "APIKeyID" }, "APIKeyScope": { "description": "Scope of permissions for the API key. API keys are used for creating new plugin versions and downloading existing plugins", @@ -5518,6 +5605,15 @@ "type": "boolean" } }, + "addon_order_id": { + "name": "addon_order_id", + "in": "path", + "required": true, + "schema": { + "$ref": "#/components/schemas/AddonOrderID" + }, + "x-go-name": "AddonOrderID" + }, "plugin_team": { "in": "path", "name": "plugin_team",