From b456ab79a3eea0ad6414c79b1fa9c8fb64f532f2 Mon Sep 17 00:00:00 2001 From: CloudQuery Bot <102256036+cq-bot@users.noreply.github.com> Date: Wed, 28 Aug 2024 12:36:35 +0300 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` (#231) This PR was created by a scheduled workflow to generate the CloudQuery Go API Client from `spec.json` --- client.gen.go | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++ spec.json | 39 ++++++++++++++ 2 files changed, 181 insertions(+) diff --git a/client.gen.go b/client.gen.go index 67b3d2a..13118e1 100644 --- a/client.gen.go +++ b/client.gen.go @@ -609,6 +609,9 @@ type ClientInterface interface { // ListCurrentUserInvitations request ListCurrentUserInvitations(ctx context.Context, params *ListCurrentUserInvitationsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + // LogoutUser request + LogoutUser(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + // LoginUserWithBody request with any body LoginUserWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -2892,6 +2895,18 @@ func (c *Client) ListCurrentUserInvitations(ctx context.Context, params *ListCur return c.Client.Do(req) } +func (c *Client) LogoutUser(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewLogoutUserRequest(c.Server) + 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) LoginUserWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewLoginUserRequestWithBody(c.Server, contentType, body) if err != nil { @@ -10795,6 +10810,33 @@ func NewListCurrentUserInvitationsRequest(server string, params *ListCurrentUser return req, nil } +// NewLogoutUserRequest generates requests for LogoutUser +func NewLogoutUserRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/user/login") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewLoginUserRequest calls the generic LoginUser builder with application/json body func NewLoginUserRequest(server string, body LoginUserJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -11520,6 +11562,9 @@ type ClientWithResponsesInterface interface { // ListCurrentUserInvitationsWithResponse request ListCurrentUserInvitationsWithResponse(ctx context.Context, params *ListCurrentUserInvitationsParams, reqEditors ...RequestEditorFn) (*ListCurrentUserInvitationsResponse, error) + // LogoutUserWithResponse request + LogoutUserWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*LogoutUserResponse, error) + // LoginUserWithBodyWithResponse request with any body LoginUserWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoginUserResponse, error) @@ -15138,6 +15183,33 @@ func (r ListCurrentUserInvitationsResponse) StatusCode() int { return 0 } +type LogoutUserResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON405 *MethodNotAllowed + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r LogoutUserResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r LogoutUserResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type LoginUserResponse struct { Body []byte HTTPResponse *http.Response @@ -16892,6 +16964,15 @@ func (c *ClientWithResponses) ListCurrentUserInvitationsWithResponse(ctx context return ParseListCurrentUserInvitationsResponse(rsp) } +// LogoutUserWithResponse request returning *LogoutUserResponse +func (c *ClientWithResponses) LogoutUserWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*LogoutUserResponse, error) { + rsp, err := c.LogoutUser(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseLogoutUserResponse(rsp) +} + // LoginUserWithBodyWithResponse request with arbitrary body returning *LoginUserResponse func (c *ClientWithResponses) LoginUserWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoginUserResponse, error) { rsp, err := c.LoginUserWithBody(ctx, contentType, body, reqEditors...) @@ -24493,6 +24574,67 @@ func ParseListCurrentUserInvitationsResponse(rsp *http.Response) (*ListCurrentUs return response, nil } +// ParseLogoutUserResponse parses an HTTP response from a LogoutUserWithResponse call +func ParseLogoutUserResponse(rsp *http.Response) (*LogoutUserResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &LogoutUserResponse{ + 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 == 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 == 405: + var dest MethodNotAllowed + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON405 = &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 +} + // ParseLoginUserResponse parses an HTTP response from a LoginUserWithResponse call func ParseLoginUserResponse(rsp *http.Response) (*LoginUserResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/spec.json b/spec.json index 960aa46..0f71c26 100644 --- a/spec.json +++ b/spec.json @@ -3576,6 +3576,45 @@ } }, "/user/login" : { + "delete" : { + "description" : "Logout a session", + "operationId" : "LogoutUser", + "responses" : { + "204" : { + "description" : "Logout is complete.", + "headers" : { + "Set-Cookie" : { + "description" : "Empty session cookie", + "explode" : false, + "schema" : { + "example" : "__session=; HttpOnly; Secure; SameSite=None; Path=/; Max-Age=3600", + "type" : "string" + }, + "style" : "simple" + } + } + }, + "400" : { + "$ref" : "#/components/responses/BadRequest" + }, + "401" : { + "$ref" : "#/components/responses/RequiresAuthentication" + }, + "403" : { + "$ref" : "#/components/responses/Forbidden" + }, + "404" : { + "$ref" : "#/components/responses/NotFound" + }, + "405" : { + "$ref" : "#/components/responses/MethodNotAllowed" + }, + "500" : { + "$ref" : "#/components/responses/InternalError" + } + }, + "tags" : [ "users" ] + }, "post" : { "description" : "Start a session using ID token", "operationId" : "LoginUser",