From 854b0dfa1011b27b257027573a5131122c8ff16f Mon Sep 17 00:00:00 2001 From: CloudQuery Bot <102256036+cq-bot@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:05:05 +0200 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` (#87) This PR was created by a scheduled workflow to generate the CloudQuery Go API Client from `spec.json` --- client.gen.go | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++ models.gen.go | 8 ++ spec.json | 83 ++++++++++++++++++- 3 files changed, 308 insertions(+), 2 deletions(-) diff --git a/client.gen.go b/client.gen.go index c7837c1..6c1f6be 100644 --- a/client.gen.go +++ b/client.gen.go @@ -182,6 +182,11 @@ type ClientInterface interface { // ListPluginVersionDocs request ListPluginVersionDocs(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, params *ListPluginVersionDocsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + // ReplacePluginVersionDocsWithBody request with any body + ReplacePluginVersionDocsWithBody(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ReplacePluginVersionDocs(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, body ReplacePluginVersionDocsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // CreatePluginVersionDocsWithBody request with any body CreatePluginVersionDocsWithBody(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -748,6 +753,30 @@ func (c *Client) ListPluginVersionDocs(ctx context.Context, teamName TeamName, p return c.Client.Do(req) } +func (c *Client) ReplacePluginVersionDocsWithBody(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewReplacePluginVersionDocsRequestWithBody(c.Server, teamName, pluginKind, pluginName, versionName, 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) ReplacePluginVersionDocs(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, body ReplacePluginVersionDocsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewReplacePluginVersionDocsRequest(c.Server, teamName, pluginKind, pluginName, versionName, 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) CreatePluginVersionDocsWithBody(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewCreatePluginVersionDocsRequestWithBody(c.Server, teamName, pluginKind, pluginName, versionName, contentType, body) if err != nil { @@ -3074,6 +3103,74 @@ func NewListPluginVersionDocsRequest(server string, teamName TeamName, pluginKin return req, nil } +// NewReplacePluginVersionDocsRequest calls the generic ReplacePluginVersionDocs builder with application/json body +func NewReplacePluginVersionDocsRequest(server string, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, body ReplacePluginVersionDocsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewReplacePluginVersionDocsRequestWithBody(server, teamName, pluginKind, pluginName, versionName, "application/json", bodyReader) +} + +// NewReplacePluginVersionDocsRequestWithBody generates requests for ReplacePluginVersionDocs with any type of body +func NewReplacePluginVersionDocsRequestWithBody(server string, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, 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, "plugin_kind", runtime.ParamLocationPath, pluginKind) + if err != nil { + return nil, err + } + + var pathParam2 string + + pathParam2, err = runtime.StyleParamWithLocation("simple", false, "plugin_name", runtime.ParamLocationPath, pluginName) + if err != nil { + return nil, err + } + + var pathParam3 string + + pathParam3, err = runtime.StyleParamWithLocation("simple", false, "version_name", runtime.ParamLocationPath, versionName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/plugins/%s/%s/%s/versions/%s/docs", pathParam0, pathParam1, pathParam2, pathParam3) + 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 +} + // NewCreatePluginVersionDocsRequest calls the generic CreatePluginVersionDocs builder with application/json body func NewCreatePluginVersionDocsRequest(server string, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, body CreatePluginVersionDocsJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -5686,6 +5783,11 @@ type ClientWithResponsesInterface interface { // ListPluginVersionDocsWithResponse request ListPluginVersionDocsWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, params *ListPluginVersionDocsParams, reqEditors ...RequestEditorFn) (*ListPluginVersionDocsResponse, error) + // ReplacePluginVersionDocsWithBodyWithResponse request with any body + ReplacePluginVersionDocsWithBodyWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ReplacePluginVersionDocsResponse, error) + + ReplacePluginVersionDocsWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, body ReplacePluginVersionDocsJSONRequestBody, reqEditors ...RequestEditorFn) (*ReplacePluginVersionDocsResponse, error) + // CreatePluginVersionDocsWithBodyWithResponse request with any body CreatePluginVersionDocsWithBodyWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreatePluginVersionDocsResponse, error) @@ -6503,6 +6605,36 @@ func (r ListPluginVersionDocsResponse) StatusCode() int { return 0 } +type ReplacePluginVersionDocsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *struct { + Names *[]PluginDocsPageName `json:"names,omitempty"` + } + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON422 *UnprocessableEntity + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r ReplacePluginVersionDocsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ReplacePluginVersionDocsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type CreatePluginVersionDocsResponse struct { Body []byte HTTPResponse *http.Response @@ -7963,6 +8095,23 @@ func (c *ClientWithResponses) ListPluginVersionDocsWithResponse(ctx context.Cont return ParseListPluginVersionDocsResponse(rsp) } +// ReplacePluginVersionDocsWithBodyWithResponse request with arbitrary body returning *ReplacePluginVersionDocsResponse +func (c *ClientWithResponses) ReplacePluginVersionDocsWithBodyWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ReplacePluginVersionDocsResponse, error) { + rsp, err := c.ReplacePluginVersionDocsWithBody(ctx, teamName, pluginKind, pluginName, versionName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseReplacePluginVersionDocsResponse(rsp) +} + +func (c *ClientWithResponses) ReplacePluginVersionDocsWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, body ReplacePluginVersionDocsJSONRequestBody, reqEditors ...RequestEditorFn) (*ReplacePluginVersionDocsResponse, error) { + rsp, err := c.ReplacePluginVersionDocs(ctx, teamName, pluginKind, pluginName, versionName, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseReplacePluginVersionDocsResponse(rsp) +} + // CreatePluginVersionDocsWithBodyWithResponse request with arbitrary body returning *CreatePluginVersionDocsResponse func (c *ClientWithResponses) CreatePluginVersionDocsWithBodyWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreatePluginVersionDocsResponse, error) { rsp, err := c.CreatePluginVersionDocsWithBody(ctx, teamName, pluginKind, pluginName, versionName, contentType, body, reqEditors...) @@ -9782,6 +9931,76 @@ func ParseListPluginVersionDocsResponse(rsp *http.Response) (*ListPluginVersionD return response, nil } +// ParseReplacePluginVersionDocsResponse parses an HTTP response from a ReplacePluginVersionDocsWithResponse call +func ParseReplacePluginVersionDocsResponse(rsp *http.Response) (*ReplacePluginVersionDocsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ReplacePluginVersionDocsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest struct { + Names *[]PluginDocsPageName `json:"names,omitempty"` + } + 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 == 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 == 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 +} + // ParseCreatePluginVersionDocsResponse parses an HTTP response from a CreatePluginVersionDocsWithResponse call func ParseCreatePluginVersionDocsResponse(rsp *http.Response) (*CreatePluginVersionDocsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index 9989f7c..260078e 100644 --- a/models.gen.go +++ b/models.gen.go @@ -1274,6 +1274,11 @@ type ListPluginVersionDocsParams struct { PerPage *PerPage `form:"per_page,omitempty" json:"per_page,omitempty"` } +// ReplacePluginVersionDocsJSONBody defines parameters for ReplacePluginVersionDocs. +type ReplacePluginVersionDocsJSONBody struct { + Pages []PluginDocsPageCreate `json:"pages"` +} + // CreatePluginVersionDocsJSONBody defines parameters for CreatePluginVersionDocs. type CreatePluginVersionDocsJSONBody struct { Pages []PluginDocsPageCreate `json:"pages"` @@ -1504,6 +1509,9 @@ type CreatePluginVersionJSONRequestBody CreatePluginVersionJSONBody // DeletePluginVersionDocsJSONRequestBody defines body for DeletePluginVersionDocs for application/json ContentType. type DeletePluginVersionDocsJSONRequestBody DeletePluginVersionDocsJSONBody +// ReplacePluginVersionDocsJSONRequestBody defines body for ReplacePluginVersionDocs for application/json ContentType. +type ReplacePluginVersionDocsJSONRequestBody ReplacePluginVersionDocsJSONBody + // CreatePluginVersionDocsJSONRequestBody defines body for CreatePluginVersionDocs for application/json ContentType. type CreatePluginVersionDocsJSONRequestBody CreatePluginVersionDocsJSONBody diff --git a/spec.json b/spec.json index df30a08..1a571bb 100644 --- a/spec.json +++ b/spec.json @@ -634,7 +634,7 @@ }, "/plugins/{team_name}/{plugin_kind}/{plugin_name}/versions/{version_name}/docs": { "get": { - "description": "List all documentation pages for a given plugin version.", + "description": "List all documentation pages for a given plugin version", "operationId": "ListPluginVersionDocs", "parameters": [ { @@ -697,7 +697,7 @@ ] }, "put": { - "description": "Create or update one or more plugin version docs pages.", + "description": "Create or update one or more plugin version docs pages", "operationId": "CreatePluginVersionDocs", "parameters": [ { @@ -775,6 +775,85 @@ "plugins" ] }, + "post": { + "description": "Replace (override) multiple plugin version docs pages", + "operationId": "ReplacePluginVersionDocs", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + }, + { + "$ref": "#/components/parameters/plugin_kind" + }, + { + "$ref": "#/components/parameters/plugin_name" + }, + { + "$ref": "#/components/parameters/version_name" + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "pages" + ], + "properties": { + "pages": { + "type": "array", + "items": { + "$ref": "#/components/schemas/PluginDocsPageCreate" + } + } + } + } + } + } + }, + "responses": { + "201": { + "description": "Successfully created or updated", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "$ref": "#/components/schemas/PluginDocsPageName" + } + } + } + } + } + } + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "422": { + "$ref": "#/components/responses/UnprocessableEntity" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "plugins" + ] + }, "delete": { "description": "Delete one or more plugin version docs pages.", "operationId": "DeletePluginVersionDocs",