From 79b867ee3db80ae06d2ac94b56a89861c505d2c0 Mon Sep 17 00:00:00 2001 From: cq-bot Date: Mon, 27 Oct 2025 15:19:29 +0000 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` --- client.gen.go | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++ models.gen.go | 101 +++++++++++++++++++++++++++++ spec.json | 69 ++++++++++++++++++++ 3 files changed, 341 insertions(+) diff --git a/client.gen.go b/client.gen.go index 7f088dc..29637c3 100644 --- a/client.gen.go +++ b/client.gen.go @@ -685,6 +685,11 @@ type ClientInterface interface { // GetCurrentUserMemberships request GetCurrentUserMemberships(ctx context.Context, params *GetCurrentUserMembershipsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + // RegisterUserWithBody request with any body + RegisterUserWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + RegisterUser(ctx context.Context, body RegisterUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // ResetUserPasswordWithBody request with any body ResetUserPasswordWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -3332,6 +3337,30 @@ func (c *Client) GetCurrentUserMemberships(ctx context.Context, params *GetCurre return c.Client.Do(req) } +func (c *Client) RegisterUserWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRegisterUserRequestWithBody(c.Server, 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) RegisterUser(ctx context.Context, body RegisterUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRegisterUserRequest(c.Server, 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) ResetUserPasswordWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewResetUserPasswordRequestWithBody(c.Server, contentType, body) if err != nil { @@ -12177,6 +12206,46 @@ func NewGetCurrentUserMembershipsRequest(server string, params *GetCurrentUserMe return req, nil } +// NewRegisterUserRequest calls the generic RegisterUser builder with application/json body +func NewRegisterUserRequest(server string, body RegisterUserJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewRegisterUserRequestWithBody(server, "application/json", bodyReader) +} + +// NewRegisterUserRequestWithBody generates requests for RegisterUser with any type of body +func NewRegisterUserRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/user/register") + 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 +} + // NewResetUserPasswordRequest calls the generic ResetUserPassword builder with application/json body func NewResetUserPasswordRequest(server string, body ResetUserPasswordJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -13109,6 +13178,11 @@ type ClientWithResponsesInterface interface { // GetCurrentUserMembershipsWithResponse request GetCurrentUserMembershipsWithResponse(ctx context.Context, params *GetCurrentUserMembershipsParams, reqEditors ...RequestEditorFn) (*GetCurrentUserMembershipsResponse, error) + // RegisterUserWithBodyWithResponse request with any body + RegisterUserWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RegisterUserResponse, error) + + RegisterUserWithResponse(ctx context.Context, body RegisterUserJSONRequestBody, reqEditors ...RequestEditorFn) (*RegisterUserResponse, error) + // ResetUserPasswordWithBodyWithResponse request with any body ResetUserPasswordWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ResetUserPasswordResponse, error) @@ -17217,6 +17291,32 @@ func (r GetCurrentUserMembershipsResponse) StatusCode() int { return 0 } +type RegisterUserResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *RegisterUser201Response + JSON400 *BadRequest + JSON404 *NotFound + JSON429 *TooManyRequests + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r RegisterUserResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RegisterUserResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type ResetUserPasswordResponse struct { Body []byte HTTPResponse *http.Response @@ -19331,6 +19431,23 @@ func (c *ClientWithResponses) GetCurrentUserMembershipsWithResponse(ctx context. return ParseGetCurrentUserMembershipsResponse(rsp) } +// RegisterUserWithBodyWithResponse request with arbitrary body returning *RegisterUserResponse +func (c *ClientWithResponses) RegisterUserWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RegisterUserResponse, error) { + rsp, err := c.RegisterUserWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRegisterUserResponse(rsp) +} + +func (c *ClientWithResponses) RegisterUserWithResponse(ctx context.Context, body RegisterUserJSONRequestBody, reqEditors ...RequestEditorFn) (*RegisterUserResponse, error) { + rsp, err := c.RegisterUser(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRegisterUserResponse(rsp) +} + // ResetUserPasswordWithBodyWithResponse request with arbitrary body returning *ResetUserPasswordResponse func (c *ClientWithResponses) ResetUserPasswordWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ResetUserPasswordResponse, error) { rsp, err := c.ResetUserPasswordWithBody(ctx, contentType, body, reqEditors...) @@ -27998,6 +28115,60 @@ func ParseGetCurrentUserMembershipsResponse(rsp *http.Response) (*GetCurrentUser return response, nil } +// ParseRegisterUserResponse parses an HTTP response from a RegisterUserWithResponse call +func ParseRegisterUserResponse(rsp *http.Response) (*RegisterUserResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RegisterUserResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest RegisterUser201Response + 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 { + return nil, err + } + response.JSON400 = &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 == 429: + var dest TooManyRequests + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON429 = &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 +} + // ParseResetUserPasswordResponse parses an HTTP response from a ResetUserPasswordWithResponse call func ParseResetUserPasswordResponse(rsp *http.Response) (*ResetUserPasswordResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index ccc9f9f..b906fee 100644 --- a/models.gen.go +++ b/models.gen.go @@ -2108,6 +2108,25 @@ type PromoteSyncSourceTestConnection struct { Tables []string `json:"tables"` } +// RegisterUser201Response defines model for RegisterUser_201_response. +type RegisterUser201Response struct { + // CustomToken Token to exchange for ID token + CustomToken string `json:"custom_token"` + + // Email Indicates successful user creation + Email string `json:"email"` +} + +// RegisterUserRequest defines model for RegisterUser_request. +type RegisterUserRequest struct { + // Email Email address + Email interface{} `json:"email"` + + // Password Password for the new user account + Password interface{} `json:"password"` + AdditionalProperties map[string]interface{} `json:"-"` +} + // RegistryAuthToken JWT token for the image registry type RegistryAuthToken struct { AccessToken string `json:"access_token"` @@ -3827,6 +3846,9 @@ type SendUserEventJSONRequestBody = SendUserEventRequest // LoginUserJSONRequestBody defines body for LoginUser for application/json ContentType. type LoginUserJSONRequestBody = LoginUserRequest +// RegisterUserJSONRequestBody defines body for RegisterUser for application/json ContentType. +type RegisterUserJSONRequestBody = RegisterUserRequest + // ResetUserPasswordJSONRequestBody defines body for ResetUserPassword for application/json ContentType. type ResetUserPasswordJSONRequestBody = ResetUserPasswordRequest @@ -5280,6 +5302,85 @@ func (a LoginUserRequest) MarshalJSON() ([]byte, error) { return json.Marshal(object) } +// Getter for additional properties for RegisterUserRequest. Returns the specified +// element and whether it was found +func (a RegisterUserRequest) Get(fieldName string) (value interface{}, found bool) { + if a.AdditionalProperties != nil { + value, found = a.AdditionalProperties[fieldName] + } + return +} + +// Setter for additional properties for RegisterUserRequest +func (a *RegisterUserRequest) Set(fieldName string, value interface{}) { + if a.AdditionalProperties == nil { + a.AdditionalProperties = make(map[string]interface{}) + } + a.AdditionalProperties[fieldName] = value +} + +// Override default JSON handling for RegisterUserRequest to handle AdditionalProperties +func (a *RegisterUserRequest) UnmarshalJSON(b []byte) error { + object := make(map[string]json.RawMessage) + err := json.Unmarshal(b, &object) + if err != nil { + return err + } + + if raw, found := object["email"]; found { + err = json.Unmarshal(raw, &a.Email) + if err != nil { + return fmt.Errorf("error reading 'email': %w", err) + } + delete(object, "email") + } + + if raw, found := object["password"]; found { + err = json.Unmarshal(raw, &a.Password) + if err != nil { + return fmt.Errorf("error reading 'password': %w", err) + } + delete(object, "password") + } + + if len(object) != 0 { + a.AdditionalProperties = make(map[string]interface{}) + for fieldName, fieldBuf := range object { + var fieldVal interface{} + err := json.Unmarshal(fieldBuf, &fieldVal) + if err != nil { + return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err) + } + a.AdditionalProperties[fieldName] = fieldVal + } + } + return nil +} + +// Override default JSON handling for RegisterUserRequest to handle AdditionalProperties +func (a RegisterUserRequest) MarshalJSON() ([]byte, error) { + var err error + object := make(map[string]json.RawMessage) + + object["email"], err = json.Marshal(a.Email) + if err != nil { + return nil, fmt.Errorf("error marshaling 'email': %w", err) + } + + object["password"], err = json.Marshal(a.Password) + if err != nil { + return nil, fmt.Errorf("error marshaling 'password': %w", err) + } + + for fieldName, field := range a.AdditionalProperties { + object[fieldName], err = json.Marshal(field) + if err != nil { + return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err) + } + } + return json.Marshal(object) +} + // Getter for additional properties for RenewPlatformActivation200Response. Returns the specified // element and whether it was found func (a RenewPlatformActivation200Response) Get(fieldName string) (value interface{}, found bool) { diff --git a/spec.json b/spec.json index 7cf29db..8ce2417 100644 --- a/spec.json +++ b/spec.json @@ -4042,6 +4042,48 @@ "tags" : [ "users" ] } }, + "/user/register" : { + "post" : { + "description" : "Register new user", + "operationId" : "RegisterUser", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/RegisterUser_request" + } + } + } + }, + "responses" : { + "201" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/RegisterUser_201_response" + } + } + }, + "description" : "User created but email not verified" + }, + "400" : { + "$ref" : "#/components/responses/BadRequest" + }, + "404" : { + "$ref" : "#/components/responses/NotFound" + }, + "429" : { + "$ref" : "#/components/responses/TooManyRequests" + }, + "500" : { + "$ref" : "#/components/responses/InternalError" + } + }, + "security" : [ ], + "tags" : [ "users" ], + "x-internal" : true + } + }, "/user/reset-password" : { "post" : { "description" : "Reset user password from email", @@ -11632,6 +11674,33 @@ }, "required" : [ "secret", "url" ] }, + "RegisterUser_request" : { + "additionalProperties" : { }, + "properties" : { + "email" : { + "description" : "Email address", + "format" : "email" + }, + "password" : { + "description" : "Password for the new user account", + "minLength" : 6 + } + }, + "required" : [ "email", "password" ] + }, + "RegisterUser_201_response" : { + "properties" : { + "email" : { + "description" : "Indicates successful user creation", + "type" : "string" + }, + "custom_token" : { + "description" : "Token to exchange for ID token", + "type" : "string" + } + }, + "required" : [ "custom_token", "email" ] + }, "ResetUserPassword_request" : { "additionalProperties" : { }, "properties" : {