From 7a6afc0b636e841b5c0f41893b6b311875f0ebbc Mon Sep 17 00:00:00 2001 From: "api-clients-generation-pipeline[bot]" <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:11:44 +0000 Subject: [PATCH] Add support for API management API (#2354) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix handling of binary body * Add uuid dep * handle file reader in given resolver * avoid panic while testing for io.Reader type * fix the type check * Regenerate client from commit a9a258a4 of spec repo --------- Co-authored-by: Thomas Hervé Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: Kevin Zou Co-authored-by: ci.datadog-api-spec --- .apigentools-info | 8 +- .generator/schemas/v2/openapi.yaml | 260 +++++++++++ .generator/src/generator/templates/api.j2 | 13 + api/datadog/configuration.go | 4 + api/datadogV2/api_api_management.go | 433 ++++++++++++++++++ api/datadogV2/api_cloud_workload_security.go | 20 +- api/datadogV2/doc.go | 4 + .../model_create_open_api_response.go | 111 +++++ ...del_create_open_api_response_attributes.go | 102 +++++ .../model_create_open_api_response_data.go | 148 ++++++ api/datadogV2/model_open_api_endpoint.go | 137 ++++++ api/datadogV2/model_open_api_file.go | 104 +++++ .../model_update_open_api_response.go | 111 +++++ ...del_update_open_api_response_attributes.go | 102 +++++ .../model_update_open_api_response_data.go | 148 ++++++ examples/v2/api-management/CreateOpenAPI.go | 31 ++ examples/v2/api-management/DeleteOpenAPI.go | 30 ++ examples/v2/api-management/GetOpenAPI.go | 34 ++ examples/v2/api-management/UpdateOpenAPI.go | 35 ++ go.mod | 1 + go.sum | 2 + tests/scenarios/actions.go | 22 +- tests/scenarios/api_mappings.go | 1 + .../features/v2/api_management.feature | 101 ++++ tests/scenarios/features/v2/given.json | 12 + tests/scenarios/features/v2/openapi-spec.yaml | 10 + tests/scenarios/features/v2/undo.json | 31 ++ 27 files changed, 1996 insertions(+), 19 deletions(-) create mode 100644 api/datadogV2/api_api_management.go create mode 100644 api/datadogV2/model_create_open_api_response.go create mode 100644 api/datadogV2/model_create_open_api_response_attributes.go create mode 100644 api/datadogV2/model_create_open_api_response_data.go create mode 100644 api/datadogV2/model_open_api_endpoint.go create mode 100644 api/datadogV2/model_open_api_file.go create mode 100644 api/datadogV2/model_update_open_api_response.go create mode 100644 api/datadogV2/model_update_open_api_response_attributes.go create mode 100644 api/datadogV2/model_update_open_api_response_data.go create mode 100644 examples/v2/api-management/CreateOpenAPI.go create mode 100644 examples/v2/api-management/DeleteOpenAPI.go create mode 100644 examples/v2/api-management/GetOpenAPI.go create mode 100644 examples/v2/api-management/UpdateOpenAPI.go create mode 100644 tests/scenarios/features/v2/api_management.feature create mode 100644 tests/scenarios/features/v2/openapi-spec.yaml diff --git a/.apigentools-info b/.apigentools-info index 9f71db5277f..a0829ec501e 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-01-25 20:06:15.455125", - "spec_repo_commit": "29ecc007" + "regenerated": "2024-01-26 14:49:57.053323", + "spec_repo_commit": "a9a258a4" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-01-25 20:06:15.472532", - "spec_repo_commit": "29ecc007" + "regenerated": "2024-01-26 14:49:57.074322", + "spec_repo_commit": "a9a258a4" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 1435ae14cb4..61c44d79455 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -839,6 +839,11 @@ components: type: string x-enum-varnames: - BILLING_DIMENSIONS + ApiID: + description: API identifier. + example: 90646597-5fdb-4a17-a240-647003f8c028 + format: uuid + type: string ApmRetentionFilterType: default: apm_retention_filter description: The type of the resource. @@ -4873,6 +4878,29 @@ components: type: string x-enum-varnames: - COST_BY_ORG + CreateOpenAPIResponse: + description: Response for `CreateOpenAPI` operation. + properties: + data: + $ref: '#/components/schemas/CreateOpenAPIResponseData' + type: object + CreateOpenAPIResponseAttributes: + description: Attributes for `CreateOpenAPI`. + properties: + failed_endpoints: + description: List of endpoints which couldn't be parsed. + items: + $ref: '#/components/schemas/OpenAPIEndpoint' + type: array + type: object + CreateOpenAPIResponseData: + description: Data envelope for `CreateOpenAPIResponse`. + properties: + attributes: + $ref: '#/components/schemas/CreateOpenAPIResponseAttributes' + id: + $ref: '#/components/schemas/ApiID' + type: object CreateRuleRequest: description: Scorecard create rule request. properties: @@ -12079,6 +12107,24 @@ components: type: string x-enum-varnames: - ON_DEMAND_CONCURRENCY_CAP + OpenAPIEndpoint: + description: Endpoint info extracted from an `OpenAPI` specification. + properties: + method: + description: The endpoint method. + type: string + path: + description: The endpoint path. + type: string + type: object + OpenAPIFile: + description: Object for API data in an `OpenAPI` format as a file. + properties: + openapi_spec_file: + description: Binary `OpenAPI` spec file + format: binary + type: string + type: object OpsgenieServiceCreateAttributes: description: The Opsgenie service attributes for a create request. properties: @@ -20284,6 +20330,29 @@ components: example: min type: string type: object + UpdateOpenAPIResponse: + description: Response for `UpdateOpenAPI`. + properties: + data: + $ref: '#/components/schemas/UpdateOpenAPIResponseData' + type: object + UpdateOpenAPIResponseAttributes: + description: Attributes for `UpdateOpenAPI`. + properties: + failed_endpoints: + description: List of endpoints which couldn't be parsed. + items: + $ref: '#/components/schemas/OpenAPIEndpoint' + type: array + type: object + UpdateOpenAPIResponseData: + description: Data envelope for `UpdateOpenAPIResponse`. + properties: + attributes: + $ref: '#/components/schemas/UpdateOpenAPIResponseAttributes' + id: + $ref: '#/components/schemas/ApiID' + type: object UsageApplicationSecurityMonitoringResponse: description: Application Security Monitoring usage response. properties: @@ -21110,6 +21179,195 @@ paths: tags: - Key Management x-codegen-request-body-name: body + /api/v2/apicatalog/api/{id}: + delete: + description: Delete a specific API by ID. + operationId: DeleteOpenAPI + parameters: + - description: ID of the API to delete + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/ApiID' + responses: + '204': + description: API deleted successfully + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: API not found error + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Delete an API + tags: + - API Management + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + /api/v2/apicatalog/api/{id}/openapi: + get: + description: Retrieve information about a specific API in [OpenAPI](https://spec.openapis.org/oas/latest.html) + format file. + operationId: GetOpenAPI + parameters: + - description: ID of the API to retrieve + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/ApiID' + responses: + '200': + content: + multipart/form-data: + schema: + format: binary + type: string + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: API not found error + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get an API + tags: + - API Management + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + put: + description: 'Update information about a specific API. The given content will + replace all API content of the given ID. + + The ID is returned by the create API, or can be found in the URL in the API + catalog UI. + + ' + operationId: UpdateOpenAPI + parameters: + - description: ID of the API to modify + in: path + name: id + required: true + schema: + $ref: '#/components/schemas/ApiID' + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/OpenAPIFile' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/UpdateOpenAPIResponse' + description: API updated successfully + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: API not found error + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Update an API + tags: + - API Management + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + /api/v2/apicatalog/openapi: + post: + description: 'Create a new API from the [OpenAPI](https://spec.openapis.org/oas/latest.html) + specification given. + + It supports version `2.0`, `3.0` and `3.1` of the specification. A specific + extension section, `x-datadog`, + + let you specify the `teamHandle` for your team responsible for the API in + Datadog. + + It returns the created API ID. + + ' + operationId: CreateOpenAPI + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/OpenAPIFile' + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/CreateOpenAPIResponse' + description: API created successfully + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Create a new API + tags: + - API Management + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/apm/config/metrics: get: description: Get the list of configured span-based metrics with their definitions. @@ -33173,6 +33431,8 @@ servers: default: api description: The subdomain where the API is deployed. tags: +- description: Configure your API endpoints through the Datadog API. + name: API Management - description: Manage configuration of [APM retention filters](https://app.datadoghq.com/apm/traces/retention-filters) for your organization. You need an API and application key with Admin rights to interact with this endpoint. See [retention filters](https://docs.datadoghq.com/tracing/trace_pipeline/trace_retention/#retention-filters) diff --git a/.generator/src/generator/templates/api.j2 b/.generator/src/generator/templates/api.j2 index 7241db90e12..8df0da111ed 100644 --- a/.generator/src/generator/templates/api.j2 +++ b/.generator/src/generator/templates/api.j2 @@ -261,15 +261,24 @@ localVarQueryParams.Add("{{ parameter.name }}", {{ common_package_name }}.Parame if err != nil || localVarHTTPResponse == nil { return {% if returnType %}localVarReturnValue, {% endif %}localVarHTTPResponse, err } + {%- if returnType != '_io.Reader' %} localVarBody, err := datadog.ReadBody(localVarHTTPResponse) if err != nil { return {% if returnType %}localVarReturnValue, {% endif %}localVarHTTPResponse, err } + {%- endif %} {%- for responseType, (response, responseCodes) in operation|responses_by_types %} {%- if loop.first %} if localVarHTTPResponse.StatusCode >= 300 { + {%- if returnType == '_io.Reader' %} + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return {% if returnType %}localVarReturnValue, {% endif %}localVarHTTPResponse, err + } + {%- endif %} newErr := {{ common_package_name }}.GenericOpenAPIError{ ErrorBody: localVarBody, ErrorMessage: localVarHTTPResponse.Status, @@ -296,6 +305,7 @@ localVarQueryParams.Add("{{ parameter.name }}", {{ common_package_name }}.Parame {%- endif %} {%- endfor %} {%- if returnType %} + {%- if returnType != '_io.Reader' %} err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { @@ -305,6 +315,9 @@ localVarQueryParams.Add("{{ parameter.name }}", {{ common_package_name }}.Parame } return {% if returnType %}localVarReturnValue, {% endif %}localVarHTTPResponse, newErr } + {%- else %} + localVarReturnValue = localVarHTTPResponse.Body + {%- endif %} {%- endif %} return {% if returnType %}localVarReturnValue, {% endif %}localVarHTTPResponse, nil diff --git a/api/datadog/configuration.go b/api/datadog/configuration.go index af3c2902a1b..0dbecbbd2c9 100644 --- a/api/datadog/configuration.go +++ b/api/datadog/configuration.go @@ -323,6 +323,10 @@ func NewConfiguration() *Configuration { }, }, unstableOperations: map[string]bool{ + "v2.CreateOpenAPI": false, + "v2.DeleteOpenAPI": false, + "v2.GetOpenAPI": false, + "v2.UpdateOpenAPI": false, "v2.GetActiveBillingDimensions": false, "v2.GetMonthlyCostAttribution": false, "v2.CreateDORADeployment": false, diff --git a/api/datadogV2/api_api_management.go b/api/datadogV2/api_api_management.go new file mode 100644 index 00000000000..a539579557b --- /dev/null +++ b/api/datadogV2/api_api_management.go @@ -0,0 +1,433 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + _context "context" + _fmt "fmt" + _io "io" + _log "log" + _nethttp "net/http" + _neturl "net/url" + "strings" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/google/uuid" +) + +// APIManagementApi service type +type APIManagementApi datadog.Service + +// CreateOpenAPIOptionalParameters holds optional parameters for CreateOpenAPI. +type CreateOpenAPIOptionalParameters struct { + OpenapiSpecFile *_io.Reader +} + +// NewCreateOpenAPIOptionalParameters creates an empty struct for parameters. +func NewCreateOpenAPIOptionalParameters() *CreateOpenAPIOptionalParameters { + this := CreateOpenAPIOptionalParameters{} + return &this +} + +// WithOpenapiSpecFile sets the corresponding parameter name and returns the struct. +func (r *CreateOpenAPIOptionalParameters) WithOpenapiSpecFile(openapiSpecFile _io.Reader) *CreateOpenAPIOptionalParameters { + r.OpenapiSpecFile = &openapiSpecFile + return r +} + +// CreateOpenAPI Create a new API. +// Create a new API from the [OpenAPI](https://spec.openapis.org/oas/latest.html) specification given. +// It supports version `2.0`, `3.0` and `3.1` of the specification. A specific extension section, `x-datadog`, +// let you specify the `teamHandle` for your team responsible for the API in Datadog. +// It returns the created API ID. +func (a *APIManagementApi) CreateOpenAPI(ctx _context.Context, o ...CreateOpenAPIOptionalParameters) (CreateOpenAPIResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue CreateOpenAPIResponse + optionalParams CreateOpenAPIOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type CreateOpenAPIOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + operationId := "v2.CreateOpenAPI" + if a.Client.Cfg.IsUnstableOperationEnabled(operationId) { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } else { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.APIManagementApi.CreateOpenAPI") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/apicatalog/openapi" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "multipart/form-data" + localVarHeaderParams["Accept"] = "application/json" + + formFile := datadog.FormFile{} + formFile.FormFileName = "openapi_spec_file" + var localVarFile _io.Reader + if optionalParams.OpenapiSpecFile != nil { + localVarFile = *optionalParams.OpenapiSpecFile + } + if localVarFile != nil { + fbs, _ := _io.ReadAll(localVarFile) + formFile.FileBytes = fbs + } + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, &formFile) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 { + var v JSONAPIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// DeleteOpenAPI Delete an API. +// Delete a specific API by ID. +func (a *APIManagementApi) DeleteOpenAPI(ctx _context.Context, id uuid.UUID) (*_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodDelete + localVarPostBody interface{} + ) + + operationId := "v2.DeleteOpenAPI" + if a.Client.Cfg.IsUnstableOperationEnabled(operationId) { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } else { + return nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.APIManagementApi.DeleteOpenAPI") + if err != nil { + return nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/apicatalog/api/{id}" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", _neturl.PathEscape(datadog.ParameterToString(id, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "*/*" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { + var v JSONAPIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +// GetOpenAPI Get an API. +// Retrieve information about a specific API in [OpenAPI](https://spec.openapis.org/oas/latest.html) format file. +func (a *APIManagementApi) GetOpenAPI(ctx _context.Context, id uuid.UUID) (_io.Reader, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue _io.Reader + ) + + operationId := "v2.GetOpenAPI" + if a.Client.Cfg.IsUnstableOperationEnabled(operationId) { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } else { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.APIManagementApi.GetOpenAPI") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/apicatalog/api/{id}/openapi" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", _neturl.PathEscape(datadog.ParameterToString(id, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "application/json" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { + var v JSONAPIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + localVarReturnValue = localVarHTTPResponse.Body + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// UpdateOpenAPIOptionalParameters holds optional parameters for UpdateOpenAPI. +type UpdateOpenAPIOptionalParameters struct { + OpenapiSpecFile *_io.Reader +} + +// NewUpdateOpenAPIOptionalParameters creates an empty struct for parameters. +func NewUpdateOpenAPIOptionalParameters() *UpdateOpenAPIOptionalParameters { + this := UpdateOpenAPIOptionalParameters{} + return &this +} + +// WithOpenapiSpecFile sets the corresponding parameter name and returns the struct. +func (r *UpdateOpenAPIOptionalParameters) WithOpenapiSpecFile(openapiSpecFile _io.Reader) *UpdateOpenAPIOptionalParameters { + r.OpenapiSpecFile = &openapiSpecFile + return r +} + +// UpdateOpenAPI Update an API. +// Update information about a specific API. The given content will replace all API content of the given ID. +// The ID is returned by the create API, or can be found in the URL in the API catalog UI. +func (a *APIManagementApi) UpdateOpenAPI(ctx _context.Context, id uuid.UUID, o ...UpdateOpenAPIOptionalParameters) (UpdateOpenAPIResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPut + localVarPostBody interface{} + localVarReturnValue UpdateOpenAPIResponse + optionalParams UpdateOpenAPIOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type UpdateOpenAPIOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + operationId := "v2.UpdateOpenAPI" + if a.Client.Cfg.IsUnstableOperationEnabled(operationId) { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } else { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.APIManagementApi.UpdateOpenAPI") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/apicatalog/api/{id}/openapi" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", _neturl.PathEscape(datadog.ParameterToString(id, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "multipart/form-data" + localVarHeaderParams["Accept"] = "application/json" + + formFile := datadog.FormFile{} + formFile.FormFileName = "openapi_spec_file" + var localVarFile _io.Reader + if optionalParams.OpenapiSpecFile != nil { + localVarFile = *optionalParams.OpenapiSpecFile + } + if localVarFile != nil { + fbs, _ := _io.ReadAll(localVarFile) + formFile.FileBytes = fbs + } + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, &formFile) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { + var v JSONAPIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// NewAPIManagementApi Returns NewAPIManagementApi. +func NewAPIManagementApi(client *datadog.APIClient) *APIManagementApi { + return &APIManagementApi{ + Client: client, + } +} diff --git a/api/datadogV2/api_cloud_workload_security.go b/api/datadogV2/api_cloud_workload_security.go index 366a40b153b..b0cf2c61f28 100644 --- a/api/datadogV2/api_cloud_workload_security.go +++ b/api/datadogV2/api_cloud_workload_security.go @@ -190,12 +190,12 @@ func (a *CloudWorkloadSecurityApi) DownloadCloudWorkloadPolicyFile(ctx _context. return localVarReturnValue, localVarHTTPResponse, err } - localVarBody, err := datadog.ReadBody(localVarHTTPResponse) - if err != nil { - return localVarReturnValue, localVarHTTPResponse, err - } - if localVarHTTPResponse.StatusCode >= 300 { + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } newErr := datadog.GenericOpenAPIError{ ErrorBody: localVarBody, ErrorMessage: localVarHTTPResponse.Status, @@ -210,15 +210,7 @@ func (a *CloudWorkloadSecurityApi) DownloadCloudWorkloadPolicyFile(ctx _context. } return localVarReturnValue, localVarHTTPResponse, newErr } - - err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr := datadog.GenericOpenAPIError{ - ErrorBody: localVarBody, - ErrorMessage: err.Error(), - } - return localVarReturnValue, localVarHTTPResponse, newErr - } + localVarReturnValue = localVarHTTPResponse.Body return localVarReturnValue, localVarHTTPResponse, nil } diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index 90643b840ff..fc0929cc03f 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -3,6 +3,10 @@ // Copyright 2019-Present Datadog, Inc. // List of APIs: +// - [APIManagementApi.CreateOpenAPI] +// - [APIManagementApi.DeleteOpenAPI] +// - [APIManagementApi.GetOpenAPI] +// - [APIManagementApi.UpdateOpenAPI] // - [APMRetentionFiltersApi.CreateApmRetentionFilter] // - [APMRetentionFiltersApi.DeleteApmRetentionFilter] // - [APMRetentionFiltersApi.GetApmRetentionFilter] diff --git a/api/datadogV2/model_create_open_api_response.go b/api/datadogV2/model_create_open_api_response.go new file mode 100644 index 00000000000..c7e2db2d26b --- /dev/null +++ b/api/datadogV2/model_create_open_api_response.go @@ -0,0 +1,111 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// CreateOpenAPIResponse Response for `CreateOpenAPI` operation. +type CreateOpenAPIResponse struct { + // Data envelope for `CreateOpenAPIResponse`. + Data *CreateOpenAPIResponseData `json:"data,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewCreateOpenAPIResponse instantiates a new CreateOpenAPIResponse object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewCreateOpenAPIResponse() *CreateOpenAPIResponse { + this := CreateOpenAPIResponse{} + return &this +} + +// NewCreateOpenAPIResponseWithDefaults instantiates a new CreateOpenAPIResponse object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewCreateOpenAPIResponseWithDefaults() *CreateOpenAPIResponse { + this := CreateOpenAPIResponse{} + return &this +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *CreateOpenAPIResponse) GetData() CreateOpenAPIResponseData { + if o == nil || o.Data == nil { + var ret CreateOpenAPIResponseData + return ret + } + return *o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateOpenAPIResponse) GetDataOk() (*CreateOpenAPIResponseData, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *CreateOpenAPIResponse) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given CreateOpenAPIResponseData and assigns it to the Data field. +func (o *CreateOpenAPIResponse) SetData(v CreateOpenAPIResponseData) { + o.Data = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o CreateOpenAPIResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *CreateOpenAPIResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *CreateOpenAPIResponseData `json:"data,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data != nil && all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_create_open_api_response_attributes.go b/api/datadogV2/model_create_open_api_response_attributes.go new file mode 100644 index 00000000000..5ace9755a41 --- /dev/null +++ b/api/datadogV2/model_create_open_api_response_attributes.go @@ -0,0 +1,102 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// CreateOpenAPIResponseAttributes Attributes for `CreateOpenAPI`. +type CreateOpenAPIResponseAttributes struct { + // List of endpoints which couldn't be parsed. + FailedEndpoints []OpenAPIEndpoint `json:"failed_endpoints,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewCreateOpenAPIResponseAttributes instantiates a new CreateOpenAPIResponseAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewCreateOpenAPIResponseAttributes() *CreateOpenAPIResponseAttributes { + this := CreateOpenAPIResponseAttributes{} + return &this +} + +// NewCreateOpenAPIResponseAttributesWithDefaults instantiates a new CreateOpenAPIResponseAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewCreateOpenAPIResponseAttributesWithDefaults() *CreateOpenAPIResponseAttributes { + this := CreateOpenAPIResponseAttributes{} + return &this +} + +// GetFailedEndpoints returns the FailedEndpoints field value if set, zero value otherwise. +func (o *CreateOpenAPIResponseAttributes) GetFailedEndpoints() []OpenAPIEndpoint { + if o == nil || o.FailedEndpoints == nil { + var ret []OpenAPIEndpoint + return ret + } + return o.FailedEndpoints +} + +// GetFailedEndpointsOk returns a tuple with the FailedEndpoints field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateOpenAPIResponseAttributes) GetFailedEndpointsOk() (*[]OpenAPIEndpoint, bool) { + if o == nil || o.FailedEndpoints == nil { + return nil, false + } + return &o.FailedEndpoints, true +} + +// HasFailedEndpoints returns a boolean if a field has been set. +func (o *CreateOpenAPIResponseAttributes) HasFailedEndpoints() bool { + return o != nil && o.FailedEndpoints != nil +} + +// SetFailedEndpoints gets a reference to the given []OpenAPIEndpoint and assigns it to the FailedEndpoints field. +func (o *CreateOpenAPIResponseAttributes) SetFailedEndpoints(v []OpenAPIEndpoint) { + o.FailedEndpoints = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o CreateOpenAPIResponseAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.FailedEndpoints != nil { + toSerialize["failed_endpoints"] = o.FailedEndpoints + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *CreateOpenAPIResponseAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + FailedEndpoints []OpenAPIEndpoint `json:"failed_endpoints,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"failed_endpoints"}) + } else { + return err + } + o.FailedEndpoints = all.FailedEndpoints + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_create_open_api_response_data.go b/api/datadogV2/model_create_open_api_response_data.go new file mode 100644 index 00000000000..e11c045b25c --- /dev/null +++ b/api/datadogV2/model_create_open_api_response_data.go @@ -0,0 +1,148 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/google/uuid" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// CreateOpenAPIResponseData Data envelope for `CreateOpenAPIResponse`. +type CreateOpenAPIResponseData struct { + // Attributes for `CreateOpenAPI`. + Attributes *CreateOpenAPIResponseAttributes `json:"attributes,omitempty"` + // API identifier. + Id *uuid.UUID `json:"id,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewCreateOpenAPIResponseData instantiates a new CreateOpenAPIResponseData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewCreateOpenAPIResponseData() *CreateOpenAPIResponseData { + this := CreateOpenAPIResponseData{} + return &this +} + +// NewCreateOpenAPIResponseDataWithDefaults instantiates a new CreateOpenAPIResponseData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewCreateOpenAPIResponseDataWithDefaults() *CreateOpenAPIResponseData { + this := CreateOpenAPIResponseData{} + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *CreateOpenAPIResponseData) GetAttributes() CreateOpenAPIResponseAttributes { + if o == nil || o.Attributes == nil { + var ret CreateOpenAPIResponseAttributes + return ret + } + return *o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateOpenAPIResponseData) GetAttributesOk() (*CreateOpenAPIResponseAttributes, bool) { + if o == nil || o.Attributes == nil { + return nil, false + } + return o.Attributes, true +} + +// HasAttributes returns a boolean if a field has been set. +func (o *CreateOpenAPIResponseData) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given CreateOpenAPIResponseAttributes and assigns it to the Attributes field. +func (o *CreateOpenAPIResponseData) SetAttributes(v CreateOpenAPIResponseAttributes) { + o.Attributes = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *CreateOpenAPIResponseData) GetId() uuid.UUID { + if o == nil || o.Id == nil { + var ret uuid.UUID + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateOpenAPIResponseData) GetIdOk() (*uuid.UUID, bool) { + if o == nil || o.Id == nil { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *CreateOpenAPIResponseData) HasId() bool { + return o != nil && o.Id != nil +} + +// SetId gets a reference to the given uuid.UUID and assigns it to the Id field. +func (o *CreateOpenAPIResponseData) SetId(v uuid.UUID) { + o.Id = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o CreateOpenAPIResponseData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Attributes != nil { + toSerialize["attributes"] = o.Attributes + } + if o.Id != nil { + toSerialize["id"] = o.Id + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *CreateOpenAPIResponseData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *CreateOpenAPIResponseAttributes `json:"attributes,omitempty"` + Id *uuid.UUID `json:"id,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + o.Id = all.Id + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_open_api_endpoint.go b/api/datadogV2/model_open_api_endpoint.go new file mode 100644 index 00000000000..9a8b3e80e11 --- /dev/null +++ b/api/datadogV2/model_open_api_endpoint.go @@ -0,0 +1,137 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// OpenAPIEndpoint Endpoint info extracted from an `OpenAPI` specification. +type OpenAPIEndpoint struct { + // The endpoint method. + Method *string `json:"method,omitempty"` + // The endpoint path. + Path *string `json:"path,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewOpenAPIEndpoint instantiates a new OpenAPIEndpoint object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewOpenAPIEndpoint() *OpenAPIEndpoint { + this := OpenAPIEndpoint{} + return &this +} + +// NewOpenAPIEndpointWithDefaults instantiates a new OpenAPIEndpoint object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewOpenAPIEndpointWithDefaults() *OpenAPIEndpoint { + this := OpenAPIEndpoint{} + return &this +} + +// GetMethod returns the Method field value if set, zero value otherwise. +func (o *OpenAPIEndpoint) GetMethod() string { + if o == nil || o.Method == nil { + var ret string + return ret + } + return *o.Method +} + +// GetMethodOk returns a tuple with the Method field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OpenAPIEndpoint) GetMethodOk() (*string, bool) { + if o == nil || o.Method == nil { + return nil, false + } + return o.Method, true +} + +// HasMethod returns a boolean if a field has been set. +func (o *OpenAPIEndpoint) HasMethod() bool { + return o != nil && o.Method != nil +} + +// SetMethod gets a reference to the given string and assigns it to the Method field. +func (o *OpenAPIEndpoint) SetMethod(v string) { + o.Method = &v +} + +// GetPath returns the Path field value if set, zero value otherwise. +func (o *OpenAPIEndpoint) GetPath() string { + if o == nil || o.Path == nil { + var ret string + return ret + } + return *o.Path +} + +// GetPathOk returns a tuple with the Path field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OpenAPIEndpoint) GetPathOk() (*string, bool) { + if o == nil || o.Path == nil { + return nil, false + } + return o.Path, true +} + +// HasPath returns a boolean if a field has been set. +func (o *OpenAPIEndpoint) HasPath() bool { + return o != nil && o.Path != nil +} + +// SetPath gets a reference to the given string and assigns it to the Path field. +func (o *OpenAPIEndpoint) SetPath(v string) { + o.Path = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o OpenAPIEndpoint) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Method != nil { + toSerialize["method"] = o.Method + } + if o.Path != nil { + toSerialize["path"] = o.Path + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *OpenAPIEndpoint) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Method *string `json:"method,omitempty"` + Path *string `json:"path,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"method", "path"}) + } else { + return err + } + o.Method = all.Method + o.Path = all.Path + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_open_api_file.go b/api/datadogV2/model_open_api_file.go new file mode 100644 index 00000000000..3c514848cad --- /dev/null +++ b/api/datadogV2/model_open_api_file.go @@ -0,0 +1,104 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + _io "io" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// OpenAPIFile Object for API data in an `OpenAPI` format as a file. +type OpenAPIFile struct { + // Binary `OpenAPI` spec file + OpenapiSpecFile *_io.Reader `json:"openapi_spec_file,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewOpenAPIFile instantiates a new OpenAPIFile object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewOpenAPIFile() *OpenAPIFile { + this := OpenAPIFile{} + return &this +} + +// NewOpenAPIFileWithDefaults instantiates a new OpenAPIFile object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewOpenAPIFileWithDefaults() *OpenAPIFile { + this := OpenAPIFile{} + return &this +} + +// GetOpenapiSpecFile returns the OpenapiSpecFile field value if set, zero value otherwise. +func (o *OpenAPIFile) GetOpenapiSpecFile() _io.Reader { + if o == nil || o.OpenapiSpecFile == nil { + var ret _io.Reader + return ret + } + return *o.OpenapiSpecFile +} + +// GetOpenapiSpecFileOk returns a tuple with the OpenapiSpecFile field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OpenAPIFile) GetOpenapiSpecFileOk() (*_io.Reader, bool) { + if o == nil || o.OpenapiSpecFile == nil { + return nil, false + } + return o.OpenapiSpecFile, true +} + +// HasOpenapiSpecFile returns a boolean if a field has been set. +func (o *OpenAPIFile) HasOpenapiSpecFile() bool { + return o != nil && o.OpenapiSpecFile != nil +} + +// SetOpenapiSpecFile gets a reference to the given _io.Reader and assigns it to the OpenapiSpecFile field. +func (o *OpenAPIFile) SetOpenapiSpecFile(v _io.Reader) { + o.OpenapiSpecFile = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o OpenAPIFile) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.OpenapiSpecFile != nil { + toSerialize["openapi_spec_file"] = o.OpenapiSpecFile + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *OpenAPIFile) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + OpenapiSpecFile *_io.Reader `json:"openapi_spec_file,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"openapi_spec_file"}) + } else { + return err + } + o.OpenapiSpecFile = all.OpenapiSpecFile + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_update_open_api_response.go b/api/datadogV2/model_update_open_api_response.go new file mode 100644 index 00000000000..375ab150cd0 --- /dev/null +++ b/api/datadogV2/model_update_open_api_response.go @@ -0,0 +1,111 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// UpdateOpenAPIResponse Response for `UpdateOpenAPI`. +type UpdateOpenAPIResponse struct { + // Data envelope for `UpdateOpenAPIResponse`. + Data *UpdateOpenAPIResponseData `json:"data,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewUpdateOpenAPIResponse instantiates a new UpdateOpenAPIResponse object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewUpdateOpenAPIResponse() *UpdateOpenAPIResponse { + this := UpdateOpenAPIResponse{} + return &this +} + +// NewUpdateOpenAPIResponseWithDefaults instantiates a new UpdateOpenAPIResponse object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewUpdateOpenAPIResponseWithDefaults() *UpdateOpenAPIResponse { + this := UpdateOpenAPIResponse{} + return &this +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *UpdateOpenAPIResponse) GetData() UpdateOpenAPIResponseData { + if o == nil || o.Data == nil { + var ret UpdateOpenAPIResponseData + return ret + } + return *o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateOpenAPIResponse) GetDataOk() (*UpdateOpenAPIResponseData, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *UpdateOpenAPIResponse) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given UpdateOpenAPIResponseData and assigns it to the Data field. +func (o *UpdateOpenAPIResponse) SetData(v UpdateOpenAPIResponseData) { + o.Data = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o UpdateOpenAPIResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *UpdateOpenAPIResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *UpdateOpenAPIResponseData `json:"data,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data != nil && all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_update_open_api_response_attributes.go b/api/datadogV2/model_update_open_api_response_attributes.go new file mode 100644 index 00000000000..6a8e4b8ac06 --- /dev/null +++ b/api/datadogV2/model_update_open_api_response_attributes.go @@ -0,0 +1,102 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// UpdateOpenAPIResponseAttributes Attributes for `UpdateOpenAPI`. +type UpdateOpenAPIResponseAttributes struct { + // List of endpoints which couldn't be parsed. + FailedEndpoints []OpenAPIEndpoint `json:"failed_endpoints,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewUpdateOpenAPIResponseAttributes instantiates a new UpdateOpenAPIResponseAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewUpdateOpenAPIResponseAttributes() *UpdateOpenAPIResponseAttributes { + this := UpdateOpenAPIResponseAttributes{} + return &this +} + +// NewUpdateOpenAPIResponseAttributesWithDefaults instantiates a new UpdateOpenAPIResponseAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewUpdateOpenAPIResponseAttributesWithDefaults() *UpdateOpenAPIResponseAttributes { + this := UpdateOpenAPIResponseAttributes{} + return &this +} + +// GetFailedEndpoints returns the FailedEndpoints field value if set, zero value otherwise. +func (o *UpdateOpenAPIResponseAttributes) GetFailedEndpoints() []OpenAPIEndpoint { + if o == nil || o.FailedEndpoints == nil { + var ret []OpenAPIEndpoint + return ret + } + return o.FailedEndpoints +} + +// GetFailedEndpointsOk returns a tuple with the FailedEndpoints field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateOpenAPIResponseAttributes) GetFailedEndpointsOk() (*[]OpenAPIEndpoint, bool) { + if o == nil || o.FailedEndpoints == nil { + return nil, false + } + return &o.FailedEndpoints, true +} + +// HasFailedEndpoints returns a boolean if a field has been set. +func (o *UpdateOpenAPIResponseAttributes) HasFailedEndpoints() bool { + return o != nil && o.FailedEndpoints != nil +} + +// SetFailedEndpoints gets a reference to the given []OpenAPIEndpoint and assigns it to the FailedEndpoints field. +func (o *UpdateOpenAPIResponseAttributes) SetFailedEndpoints(v []OpenAPIEndpoint) { + o.FailedEndpoints = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o UpdateOpenAPIResponseAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.FailedEndpoints != nil { + toSerialize["failed_endpoints"] = o.FailedEndpoints + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *UpdateOpenAPIResponseAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + FailedEndpoints []OpenAPIEndpoint `json:"failed_endpoints,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"failed_endpoints"}) + } else { + return err + } + o.FailedEndpoints = all.FailedEndpoints + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_update_open_api_response_data.go b/api/datadogV2/model_update_open_api_response_data.go new file mode 100644 index 00000000000..4a08e3cab50 --- /dev/null +++ b/api/datadogV2/model_update_open_api_response_data.go @@ -0,0 +1,148 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/google/uuid" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// UpdateOpenAPIResponseData Data envelope for `UpdateOpenAPIResponse`. +type UpdateOpenAPIResponseData struct { + // Attributes for `UpdateOpenAPI`. + Attributes *UpdateOpenAPIResponseAttributes `json:"attributes,omitempty"` + // API identifier. + Id *uuid.UUID `json:"id,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewUpdateOpenAPIResponseData instantiates a new UpdateOpenAPIResponseData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewUpdateOpenAPIResponseData() *UpdateOpenAPIResponseData { + this := UpdateOpenAPIResponseData{} + return &this +} + +// NewUpdateOpenAPIResponseDataWithDefaults instantiates a new UpdateOpenAPIResponseData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewUpdateOpenAPIResponseDataWithDefaults() *UpdateOpenAPIResponseData { + this := UpdateOpenAPIResponseData{} + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *UpdateOpenAPIResponseData) GetAttributes() UpdateOpenAPIResponseAttributes { + if o == nil || o.Attributes == nil { + var ret UpdateOpenAPIResponseAttributes + return ret + } + return *o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateOpenAPIResponseData) GetAttributesOk() (*UpdateOpenAPIResponseAttributes, bool) { + if o == nil || o.Attributes == nil { + return nil, false + } + return o.Attributes, true +} + +// HasAttributes returns a boolean if a field has been set. +func (o *UpdateOpenAPIResponseData) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given UpdateOpenAPIResponseAttributes and assigns it to the Attributes field. +func (o *UpdateOpenAPIResponseData) SetAttributes(v UpdateOpenAPIResponseAttributes) { + o.Attributes = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *UpdateOpenAPIResponseData) GetId() uuid.UUID { + if o == nil || o.Id == nil { + var ret uuid.UUID + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateOpenAPIResponseData) GetIdOk() (*uuid.UUID, bool) { + if o == nil || o.Id == nil { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *UpdateOpenAPIResponseData) HasId() bool { + return o != nil && o.Id != nil +} + +// SetId gets a reference to the given uuid.UUID and assigns it to the Id field. +func (o *UpdateOpenAPIResponseData) SetId(v uuid.UUID) { + o.Id = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o UpdateOpenAPIResponseData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Attributes != nil { + toSerialize["attributes"] = o.Attributes + } + if o.Id != nil { + toSerialize["id"] = o.Id + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *UpdateOpenAPIResponseData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *UpdateOpenAPIResponseAttributes `json:"attributes,omitempty"` + Id *uuid.UUID `json:"id,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + o.Id = all.Id + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/examples/v2/api-management/CreateOpenAPI.go b/examples/v2/api-management/CreateOpenAPI.go new file mode 100644 index 00000000000..b7247881804 --- /dev/null +++ b/examples/v2/api-management/CreateOpenAPI.go @@ -0,0 +1,31 @@ +// Create a new API returns "API created successfully" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "io" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.CreateOpenAPI", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewAPIManagementApi(apiClient) + resp, r, err := api.CreateOpenAPI(ctx, *datadogV2.NewCreateOpenAPIOptionalParameters().WithOpenapiSpecFile(func() io.Reader { fp, _ := os.Open("openapi-spec.yaml"); return fp }())) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `APIManagementApi.CreateOpenAPI`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `APIManagementApi.CreateOpenAPI`:\n%s\n", responseContent) +} diff --git a/examples/v2/api-management/DeleteOpenAPI.go b/examples/v2/api-management/DeleteOpenAPI.go new file mode 100644 index 00000000000..a5b8810cdf8 --- /dev/null +++ b/examples/v2/api-management/DeleteOpenAPI.go @@ -0,0 +1,30 @@ +// Delete an API returns "API deleted successfully" response + +package main + +import ( + "context" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" + "github.com/google/uuid" +) + +func main() { + // there is a valid "managed_api" in the system + ManagedAPIDataID := uuid.MustParse(os.Getenv("MANAGED_API_DATA_ID")) + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.DeleteOpenAPI", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewAPIManagementApi(apiClient) + r, err := api.DeleteOpenAPI(ctx, ManagedAPIDataID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `APIManagementApi.DeleteOpenAPI`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/api-management/GetOpenAPI.go b/examples/v2/api-management/GetOpenAPI.go new file mode 100644 index 00000000000..058d5923f27 --- /dev/null +++ b/examples/v2/api-management/GetOpenAPI.go @@ -0,0 +1,34 @@ +// Get an API returns "OK" response + +package main + +import ( + "context" + "fmt" + "io/ioutil" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" + "github.com/google/uuid" +) + +func main() { + // there is a valid "managed_api" in the system + ManagedAPIDataID := uuid.MustParse(os.Getenv("MANAGED_API_DATA_ID")) + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.GetOpenAPI", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewAPIManagementApi(apiClient) + resp, r, err := api.GetOpenAPI(ctx, ManagedAPIDataID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `APIManagementApi.GetOpenAPI`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := ioutil.ReadAll(resp) + fmt.Fprintf(os.Stdout, "Response from `APIManagementApi.GetOpenAPI`:\n%s\n", responseContent) +} diff --git a/examples/v2/api-management/UpdateOpenAPI.go b/examples/v2/api-management/UpdateOpenAPI.go new file mode 100644 index 00000000000..b2b07cdd057 --- /dev/null +++ b/examples/v2/api-management/UpdateOpenAPI.go @@ -0,0 +1,35 @@ +// Update an API returns "API updated successfully" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "io" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" + "github.com/google/uuid" +) + +func main() { + // there is a valid "managed_api" in the system + ManagedAPIDataID := uuid.MustParse(os.Getenv("MANAGED_API_DATA_ID")) + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.UpdateOpenAPI", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewAPIManagementApi(apiClient) + resp, r, err := api.UpdateOpenAPI(ctx, ManagedAPIDataID, *datadogV2.NewUpdateOpenAPIOptionalParameters().WithOpenapiSpecFile(func() io.Reader { fp, _ := os.Open("openapi-spec.yaml"); return fp }())) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `APIManagementApi.UpdateOpenAPI`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `APIManagementApi.UpdateOpenAPI`:\n%s\n", responseContent) +} diff --git a/go.mod b/go.mod index 31856402001..ea9be6c152f 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ retract ( require ( github.com/DataDog/zstd v1.5.2 github.com/goccy/go-json v0.10.2 + github.com/google/uuid v1.5.0 golang.org/x/oauth2 v0.10.0 ) diff --git a/go.sum b/go.sum index 216a4e7a74b..f8f53ae08b3 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= diff --git a/tests/scenarios/actions.go b/tests/scenarios/actions.go index 1c644de5d4a..ea57626153b 100644 --- a/tests/scenarios/actions.go +++ b/tests/scenarios/actions.go @@ -36,7 +36,7 @@ type UndoAction struct { Name string `json:"name"` Source *string `json:"source"` Template *string `json:"template"` - Origin *string `json:origin` + Origin *string `json:"origin"` } `json:"parameters"` } `json:"undo"` } @@ -50,6 +50,26 @@ type operationParameter struct { func (p operationParameter) Resolve(t gobdd.StepTest, ctx gobdd.Context, tp reflect.Type) reflect.Value { if p.Value != nil { + if tp.Kind() == reflect.Slice { + field, ok := tp.Elem().FieldByName(SnakeToCamelCase(p.Name)) + if ok && field.Type == reflect.TypeOf((*io.Reader)(nil)) { + version := GetVersion(ctx) + var basePath string + tpl := Templated(t, GetData(ctx), *p.Value) + if err := datadog.Unmarshal([]byte(tpl), &basePath); err != nil { + t.Fatalf("can't unmarshal parameter value for %s: %v", p.Name, err) + } + filepath := fmt.Sprintf("./features/%s/%s", version, basePath) + fp, err := os.Open(filepath) + if err != nil { + t.Error(err) + } + reader := io.Reader(fp) + v := reflect.New(tp.Elem()) + v.Elem().FieldByName(SnakeToCamelCase(p.Name)).Set(reflect.ValueOf(&reader)) + return v.Elem() + } + } tpl := Templated(t, GetData(ctx), *p.Value) v := reflect.New(tp) err := datadog.Unmarshal([]byte(tpl), v.Interface()) diff --git a/tests/scenarios/api_mappings.go b/tests/scenarios/api_mappings.go index 60fafb55522..f31efbbcd99 100644 --- a/tests/scenarios/api_mappings.go +++ b/tests/scenarios/api_mappings.go @@ -45,6 +45,7 @@ var apiMappings = map[string]map[string]reflect.Value{ }, "v2": { "KeyManagementApi": reflect.ValueOf(datadogV2.NewKeyManagementApi), + "APIManagementApi": reflect.ValueOf(datadogV2.NewAPIManagementApi), "SpansMetricsApi": reflect.ValueOf(datadogV2.NewSpansMetricsApi), "APMRetentionFiltersApi": reflect.ValueOf(datadogV2.NewAPMRetentionFiltersApi), "AuditApi": reflect.ValueOf(datadogV2.NewAuditApi), diff --git a/tests/scenarios/features/v2/api_management.feature b/tests/scenarios/features/v2/api_management.feature new file mode 100644 index 00000000000..b010e6e81f2 --- /dev/null +++ b/tests/scenarios/features/v2/api_management.feature @@ -0,0 +1,101 @@ +@endpoint(api-management) @endpoint(api-management-v2) +Feature: API Management + Configure your API endpoints through the Datadog API. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "APIManagement" API + + @integration-only @skip-terraform-config @skip-validation @team:DataDog/api-management + Scenario: Create a new API returns "API created successfully" response + Given operation "CreateOpenAPI" enabled + And new "CreateOpenAPI" request + And request contains "openapi_spec_file" parameter with value "openapi-spec.yaml" + When the request is sent + Then the response status is 201 API created successfully + And the response "data.attributes.failed_endpoints" has length 0 + + @generated @skip @team:DataDog/api-management + Scenario: Create a new API returns "Bad request" response + Given operation "CreateOpenAPI" enabled + And new "CreateOpenAPI" request + When the request is sent + Then the response status is 400 Bad request + + @integration-only @skip-terraform-config @skip-validation @team:DataDog/api-management + Scenario: Delete an API returns "API deleted successfully" response + Given operation "DeleteOpenAPI" enabled + And there is a valid "managed_api" in the system + And new "DeleteOpenAPI" request + And request contains "id" parameter from "managed_api.data.id" + When the request is sent + Then the response status is 204 API deleted successfully + + @generated @skip @team:DataDog/api-management + Scenario: Delete an API returns "API not found error" response + Given operation "DeleteOpenAPI" enabled + And new "DeleteOpenAPI" request + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 API not found error + + @generated @skip @team:DataDog/api-management + Scenario: Delete an API returns "Bad request" response + Given operation "DeleteOpenAPI" enabled + And new "DeleteOpenAPI" request + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad request + + @generated @skip @team:DataDog/api-management + Scenario: Get an API returns "API not found error" response + Given operation "GetOpenAPI" enabled + And new "GetOpenAPI" request + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 API not found error + + @generated @skip @team:DataDog/api-management + Scenario: Get an API returns "Bad request" response + Given operation "GetOpenAPI" enabled + And new "GetOpenAPI" request + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad request + + @integration-only @skip-terraform-config @skip-validation @team:DataDog/api-management + Scenario: Get an API returns "OK" response + Given operation "GetOpenAPI" enabled + And there is a valid "managed_api" in the system + And new "GetOpenAPI" request + And request contains "id" parameter from "managed_api.data.id" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/api-management + Scenario: Update an API returns "API not found error" response + Given operation "UpdateOpenAPI" enabled + And new "UpdateOpenAPI" request + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 API not found error + + @integration-only @skip-terraform-config @skip-validation @team:DataDog/api-management + Scenario: Update an API returns "API updated successfully" response + Given operation "UpdateOpenAPI" enabled + And there is a valid "managed_api" in the system + And new "UpdateOpenAPI" request + And request contains "id" parameter from "managed_api.data.id" + And request contains "openapi_spec_file" parameter with value "openapi-spec.yaml" + When the request is sent + Then the response status is 200 API updated successfully + And the response "data.attributes.failed_endpoints" has length 0 + + @generated @skip @team:DataDog/api-management + Scenario: Update an API returns "Bad request" response + Given operation "UpdateOpenAPI" enabled + And new "UpdateOpenAPI" request + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad request diff --git a/tests/scenarios/features/v2/given.json b/tests/scenarios/features/v2/given.json index 5baa4e01925..da22a5fc35d 100644 --- a/tests/scenarios/features/v2/given.json +++ b/tests/scenarios/features/v2/given.json @@ -11,6 +11,18 @@ "tag": "Key Management", "operationId": "CreateAPIKey" }, + { + "parameters": [ + { + "name": "openapi_spec_file", + "value": "\"openapi-spec.yaml\"" + } + ], + "step": "there is a valid \"managed_api\" in the system", + "key": "managed_api", + "tag": "API Management", + "operationId": "CreateOpenAPI" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v2/openapi-spec.yaml b/tests/scenarios/features/v2/openapi-spec.yaml new file mode 100644 index 00000000000..83047f617d9 --- /dev/null +++ b/tests/scenarios/features/v2/openapi-spec.yaml @@ -0,0 +1,10 @@ +info: + description: My API description. + title: My API +x-datadog: + teamHandle: API team +openapi: 3.0.0 +paths: + /api/my-api: + get: + description: An endpoint diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index ecf9568a331..61d85e0fcad 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -36,6 +36,37 @@ "type": "idempotent" } }, + "DeleteOpenAPI": { + "tag": "API Management", + "undo": { + "type": "idempotent" + } + }, + "GetOpenAPI": { + "tag": "API Management", + "undo": { + "type": "safe" + } + }, + "UpdateOpenAPI": { + "tag": "API Management", + "undo": { + "type": "idempotent" + } + }, + "CreateOpenAPI": { + "tag": "API Management", + "undo": { + "operationId": "DeleteOpenAPI", + "parameters": [ + { + "name": "id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, "ListSpansMetrics": { "tag": "Spans Metrics", "undo": {