Skip to content

Commit

Permalink
Add support for API management API (#2354)
Browse files Browse the repository at this point in the history
* 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é <[email protected]>
Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
Co-authored-by: Kevin Zou <[email protected]>
Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
4 people authored Jan 26, 2024
1 parent 989b47f commit 7a6afc0
Show file tree
Hide file tree
Showing 27 changed files with 1,996 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
260 changes: 260 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions api/datadog/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 7a6afc0

Please sign in to comment.