Skip to content

Commit

Permalink
Support schema version parameter in Get and List Service Definition e…
Browse files Browse the repository at this point in the history
…ndpoints (#1991)

Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored May 12, 2023
1 parent ff76b1d commit 7ab24e2
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 370 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.4",
"regenerated": "2023-05-11 14:30:58.836250",
"spec_repo_commit": "b6d2ec34"
"regenerated": "2023-05-12 13:13:13.223351",
"spec_repo_commit": "9eca3996"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-05-11 14:30:58.849251",
"spec_repo_commit": "b6d2ec34"
"regenerated": "2023-05-12 13:13:13.242466",
"spec_repo_commit": "9eca3996"
}
}
}
20 changes: 20 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ components:
required: true
schema:
type: string
SchemaVersion:
description: The schema version desired in the response.
in: query
name: schema_version
required: false
schema:
$ref: '#/components/schemas/ServiceDefinitionSchemaVersions'
SecurityFilterID:
description: The ID of the security filter.
in: path
Expand Down Expand Up @@ -12502,6 +12509,17 @@ components:
- $ref: '#/components/schemas/ServiceDefinitionV2'
- $ref: '#/components/schemas/ServiceDefinitionV2Dot1'
type: object
ServiceDefinitionSchemaVersions:
description: Schema versions
enum:
- v1
- v2
- v2.1
type: string
x-enum-varnames:
- V1
- V2
- V2_1
ServiceDefinitionV1:
deprecated: true
description: Deprecated - Service definition V1 for providing additional service
Expand Down Expand Up @@ -22234,6 +22252,7 @@ paths:
parameters:
- $ref: '#/components/parameters/PageSize'
- $ref: '#/components/parameters/PageNumber'
- $ref: '#/components/parameters/SchemaVersion'
responses:
'200':
content:
Expand Down Expand Up @@ -22306,6 +22325,7 @@ paths:
operationId: GetServiceDefinition
parameters:
- $ref: '#/components/parameters/ServiceName'
- $ref: '#/components/parameters/SchemaVersion'
responses:
'200':
content:
Expand Down
44 changes: 41 additions & 3 deletions api/datadogV2/api_service_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,40 @@ func (a *ServiceDefinitionApi) DeleteServiceDefinition(ctx _context.Context, ser
return localVarHTTPResponse, nil
}

// GetServiceDefinitionOptionalParameters holds optional parameters for GetServiceDefinition.
type GetServiceDefinitionOptionalParameters struct {
SchemaVersion *ServiceDefinitionSchemaVersions
}

// NewGetServiceDefinitionOptionalParameters creates an empty struct for parameters.
func NewGetServiceDefinitionOptionalParameters() *GetServiceDefinitionOptionalParameters {
this := GetServiceDefinitionOptionalParameters{}
return &this
}

// WithSchemaVersion sets the corresponding parameter name and returns the struct.
func (r *GetServiceDefinitionOptionalParameters) WithSchemaVersion(schemaVersion ServiceDefinitionSchemaVersions) *GetServiceDefinitionOptionalParameters {
r.SchemaVersion = &schemaVersion
return r
}

// GetServiceDefinition Get a single service definition.
// Get a single service definition from the Datadog Service Catalog.
func (a *ServiceDefinitionApi) GetServiceDefinition(ctx _context.Context, serviceName string) (ServiceDefinitionGetResponse, *_nethttp.Response, error) {
func (a *ServiceDefinitionApi) GetServiceDefinition(ctx _context.Context, serviceName string, o ...GetServiceDefinitionOptionalParameters) (ServiceDefinitionGetResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodGet
localVarPostBody interface{}
localVarReturnValue ServiceDefinitionGetResponse
optionalParams GetServiceDefinitionOptionalParameters
)

if len(o) > 1 {
return localVarReturnValue, nil, datadog.ReportError("only one argument of type GetServiceDefinitionOptionalParameters is allowed")
}
if len(o) == 1 {
optionalParams = o[0]
}

localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.ServiceDefinitionApi.GetServiceDefinition")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
Expand All @@ -170,6 +195,9 @@ func (a *ServiceDefinitionApi) GetServiceDefinition(ctx _context.Context, servic
localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if optionalParams.SchemaVersion != nil {
localVarQueryParams.Add("schema_version", datadog.ParameterToString(*optionalParams.SchemaVersion, ""))
}
localVarHeaderParams["Accept"] = "application/json"

datadog.SetAuthKeys(
Expand Down Expand Up @@ -223,8 +251,9 @@ func (a *ServiceDefinitionApi) GetServiceDefinition(ctx _context.Context, servic

// ListServiceDefinitionsOptionalParameters holds optional parameters for ListServiceDefinitions.
type ListServiceDefinitionsOptionalParameters struct {
PageSize *int64
PageNumber *int64
PageSize *int64
PageNumber *int64
SchemaVersion *ServiceDefinitionSchemaVersions
}

// NewListServiceDefinitionsOptionalParameters creates an empty struct for parameters.
Expand All @@ -245,6 +274,12 @@ func (r *ListServiceDefinitionsOptionalParameters) WithPageNumber(pageNumber int
return r
}

// WithSchemaVersion sets the corresponding parameter name and returns the struct.
func (r *ListServiceDefinitionsOptionalParameters) WithSchemaVersion(schemaVersion ServiceDefinitionSchemaVersions) *ListServiceDefinitionsOptionalParameters {
r.SchemaVersion = &schemaVersion
return r
}

// ListServiceDefinitions Get all service definitions.
// Get a list of all service definitions from the Datadog Service Catalog.
func (a *ServiceDefinitionApi) ListServiceDefinitions(ctx _context.Context, o ...ListServiceDefinitionsOptionalParameters) (ServiceDefinitionsListResponse, *_nethttp.Response, error) {
Expand Down Expand Up @@ -278,6 +313,9 @@ func (a *ServiceDefinitionApi) ListServiceDefinitions(ctx _context.Context, o ..
if optionalParams.PageNumber != nil {
localVarQueryParams.Add("page[number]", datadog.ParameterToString(*optionalParams.PageNumber, ""))
}
if optionalParams.SchemaVersion != nil {
localVarQueryParams.Add("schema_version", datadog.ParameterToString(*optionalParams.SchemaVersion, ""))
}
localVarHeaderParams["Accept"] = "application/json"

datadog.SetAuthKeys(
Expand Down
111 changes: 111 additions & 0 deletions api/datadogV2/model_service_definition_schema_versions.go
Original file line number Diff line number Diff line change
@@ -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 (
"encoding/json"
"fmt"
)

// ServiceDefinitionSchemaVersions Schema versions
type ServiceDefinitionSchemaVersions string

// List of ServiceDefinitionSchemaVersions.
const (
SERVICEDEFINITIONSCHEMAVERSIONS_V1 ServiceDefinitionSchemaVersions = "v1"
SERVICEDEFINITIONSCHEMAVERSIONS_V2 ServiceDefinitionSchemaVersions = "v2"
SERVICEDEFINITIONSCHEMAVERSIONS_V2_1 ServiceDefinitionSchemaVersions = "v2.1"
)

var allowedServiceDefinitionSchemaVersionsEnumValues = []ServiceDefinitionSchemaVersions{
SERVICEDEFINITIONSCHEMAVERSIONS_V1,
SERVICEDEFINITIONSCHEMAVERSIONS_V2,
SERVICEDEFINITIONSCHEMAVERSIONS_V2_1,
}

// GetAllowedValues reeturns the list of possible values.
func (v *ServiceDefinitionSchemaVersions) GetAllowedValues() []ServiceDefinitionSchemaVersions {
return allowedServiceDefinitionSchemaVersionsEnumValues
}

// UnmarshalJSON deserializes the given payload.
func (v *ServiceDefinitionSchemaVersions) UnmarshalJSON(src []byte) error {
var value string
err := json.Unmarshal(src, &value)
if err != nil {
return err
}
*v = ServiceDefinitionSchemaVersions(value)
return nil
}

// NewServiceDefinitionSchemaVersionsFromValue returns a pointer to a valid ServiceDefinitionSchemaVersions
// for the value passed as argument, or an error if the value passed is not allowed by the enum.
func NewServiceDefinitionSchemaVersionsFromValue(v string) (*ServiceDefinitionSchemaVersions, error) {
ev := ServiceDefinitionSchemaVersions(v)
if ev.IsValid() {
return &ev, nil
}
return nil, fmt.Errorf("invalid value '%v' for ServiceDefinitionSchemaVersions: valid values are %v", v, allowedServiceDefinitionSchemaVersionsEnumValues)
}

// IsValid return true if the value is valid for the enum, false otherwise.
func (v ServiceDefinitionSchemaVersions) IsValid() bool {
for _, existing := range allowedServiceDefinitionSchemaVersionsEnumValues {
if existing == v {
return true
}
}
return false
}

// Ptr returns reference to ServiceDefinitionSchemaVersions value.
func (v ServiceDefinitionSchemaVersions) Ptr() *ServiceDefinitionSchemaVersions {
return &v
}

// NullableServiceDefinitionSchemaVersions handles when a null is used for ServiceDefinitionSchemaVersions.
type NullableServiceDefinitionSchemaVersions struct {
value *ServiceDefinitionSchemaVersions
isSet bool
}

// Get returns the associated value.
func (v NullableServiceDefinitionSchemaVersions) Get() *ServiceDefinitionSchemaVersions {
return v.value
}

// Set changes the value and indicates it's been called.
func (v *NullableServiceDefinitionSchemaVersions) Set(val *ServiceDefinitionSchemaVersions) {
v.value = val
v.isSet = true
}

// IsSet returns whether Set has been called.
func (v NullableServiceDefinitionSchemaVersions) IsSet() bool {
return v.isSet
}

// Unset sets the value to nil and resets the set flag.
func (v *NullableServiceDefinitionSchemaVersions) Unset() {
v.value = nil
v.isSet = false
}

// NewNullableServiceDefinitionSchemaVersions initializes the struct as if Set has been called.
func NewNullableServiceDefinitionSchemaVersions(val *ServiceDefinitionSchemaVersions) *NullableServiceDefinitionSchemaVersions {
return &NullableServiceDefinitionSchemaVersions{value: val, isSet: true}
}

// MarshalJSON serializes the associated value.
func (v NullableServiceDefinitionSchemaVersions) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}

// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called.
func (v *NullableServiceDefinitionSchemaVersions) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
2 changes: 1 addition & 1 deletion examples/v2/service-definition/GetServiceDefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewServiceDefinitionApi(apiClient)
resp, r, err := api.GetServiceDefinition(ctx, "service-definition-test")
resp, r, err := api.GetServiceDefinition(ctx, "service-definition-test", *datadogV2.NewGetServiceDefinitionOptionalParameters().WithSchemaVersion(datadogV2.SERVICEDEFINITIONSCHEMAVERSIONS_V2_1))

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `ServiceDefinitionApi.GetServiceDefinition`: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/service-definition/ListServiceDefinitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewServiceDefinitionApi(apiClient)
resp, r, err := api.ListServiceDefinitions(ctx, *datadogV2.NewListServiceDefinitionsOptionalParameters())
resp, r, err := api.ListServiceDefinitions(ctx, *datadogV2.NewListServiceDefinitionsOptionalParameters().WithSchemaVersion(datadogV2.SERVICEDEFINITIONSCHEMAVERSIONS_V2_1))

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `ServiceDefinitionApi.ListServiceDefinitions`: %v\n", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-14T18:09:34.511Z
2023-05-11T21:16:09.344Z
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ interactions:
Accept:
- application/json
method: GET
url: https://api.datadoghq.com/api/v2/services/definitions/service-definition-test
url: https://api.datadoghq.com/api/v2/services/definitions/service-definition-test?schema_version=v2.1
response:
body: '{"data":{"type":"service-definition","id":"77ae46b484fcfd92dc568170b1c534fe","attributes":{"meta":{"last-modified-time":"2022-11-14T18:03:35Z","github-html-url":"","ingestion-source":"api","warnings":[],"ingested-schema-version":"v2"},"schema":{"schema-version":"v2","dd-service":"service-definition-test","dd-team":"my-team","team":"super-team","contacts":[{"name":"Team
Email","type":"email","contact":"contact@datadoghq.com"}],"links":[{"name":"Runbook","type":"runbook","url":"https://my-runbook"}],"repos":[{"name":"Source
Code","provider":"GitHub","url":"https://github.com/DataDog/schema"}],"docs":[{"name":"Architecture","provider":"google
drive","url":"https://gdrive/mydoc"}],"tags":["service:tag","my:tag"],"integrations":{"pagerduty":"https://my-org.pagerduty.com/service-directory/PMyService","opsgenie":{"service-url":"https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000","region":"US"}},"extensions":{"myorgextension":"extensionvalue"}}}}}
body: '{"data":{"type":"service-definition","id":"77ae46b484fcfd92dc568170b1c534fe","attributes":{"meta":{"last-modified-time":"2023-04-18T16:19:17Z","github-html-url":"","ingestion-source":"api","origin":"unknown","origin-detail":"","warnings":[],"ingested-schema-version":"v2"},"schema":{"schema-version":"v2.1","dd-service":"service-definition-test","team":"my-team","contacts":[{"name":"Team
Email","type":"email","contact":"contact@datadoghq.com"}],"links":[{"name":"Runbook","type":"runbook","url":"https://my-runbook"},{"name":"Source
Code","type":"repo","provider":"GitHub","url":"https://github.com/DataDog/schema"},{"name":"Architecture","type":"doc","provider":"google
drive","url":"https://gdrive/mydoc"}],"tags":["service:tag","my:tag"],"integrations":{"pagerduty":{"service-url":"https://my-org.pagerduty.com/service-directory/PMyService"},"opsgenie":{"service-url":"https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000","region":"US"}},"extensions":{"myorgextension":"extensionvalue"}}}}}
'
code: 200
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-10-10T12:54:43.916Z
2023-05-11T21:15:27.277Z
Loading

0 comments on commit 7ab24e2

Please sign in to comment.