diff --git a/.apigentools-info b/.apigentools-info index b13de3567f9..8d23a19100f 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.4", - "regenerated": "2023-04-06 14:03:53.397002", - "spec_repo_commit": "9572acd2" + "regenerated": "2023-04-06 15:03:59.469640", + "spec_repo_commit": "b180cceb" }, "v2": { "apigentools_version": "1.6.4", - "regenerated": "2023-04-06 14:03:53.409829", - "spec_repo_commit": "9572acd2" + "regenerated": "2023-04-06 15:03:59.482002", + "spec_repo_commit": "b180cceb" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 8f5f5fbc58a..6fd306effcc 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -21758,6 +21758,9 @@ paths: description: Get a list of all service definitions from the Datadog Service Catalog. operationId: ListServiceDefinitions + parameters: + - $ref: '#/components/parameters/PageSize' + - $ref: '#/components/parameters/PageNumber' responses: '200': content: @@ -21772,6 +21775,10 @@ paths: summary: Get all service definitions tags: - Service Definition + x-pagination: + limitParam: page[size] + pageOffsetParam: page[number] + resultsPath: data post: description: Create or update service definition in the Datadog Service Catalog. operationId: CreateOrUpdateServiceDefinitions diff --git a/examples/v2/service-definition/ListServiceDefinitions_336468013.java b/examples/v2/service-definition/ListServiceDefinitions_336468013.java new file mode 100644 index 00000000000..4832017ad49 --- /dev/null +++ b/examples/v2/service-definition/ListServiceDefinitions_336468013.java @@ -0,0 +1,29 @@ +// Get all service definitions returns "OK" response with pagination + +import com.datadog.api.client.ApiClient; +import com.datadog.api.client.PaginationIterable; +import com.datadog.api.client.v2.api.ServiceDefinitionApi; +import com.datadog.api.client.v2.api.ServiceDefinitionApi.ListServiceDefinitionsOptionalParameters; +import com.datadog.api.client.v2.model.ServiceDefinitionData; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = ApiClient.getDefaultApiClient(); + ServiceDefinitionApi apiInstance = new ServiceDefinitionApi(defaultClient); + + try { + PaginationIterable iterable = + apiInstance.listServiceDefinitionsWithPagination( + new ListServiceDefinitionsOptionalParameters().pageSize(2L)); + + for (ServiceDefinitionData item : iterable) { + System.out.println(item); + } + } catch (RuntimeException e) { + System.err.println( + "Exception when calling ServiceDefinitionApi#listServiceDefinitionsWithPagination"); + System.err.println("Reason: " + e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/datadog/api/client/v2/api/ServiceDefinitionApi.java b/src/main/java/com/datadog/api/client/v2/api/ServiceDefinitionApi.java index 260346ae8ed..dd04f284d48 100644 --- a/src/main/java/com/datadog/api/client/v2/api/ServiceDefinitionApi.java +++ b/src/main/java/com/datadog/api/client/v2/api/ServiceDefinitionApi.java @@ -3,8 +3,10 @@ import com.datadog.api.client.ApiClient; import com.datadog.api.client.ApiException; import com.datadog.api.client.ApiResponse; +import com.datadog.api.client.PaginationIterable; import com.datadog.api.client.Pair; import com.datadog.api.client.v2.model.ServiceDefinitionCreateResponse; +import com.datadog.api.client.v2.model.ServiceDefinitionData; import com.datadog.api.client.v2.model.ServiceDefinitionGetResponse; import com.datadog.api.client.v2.model.ServiceDefinitionsCreateRequest; import com.datadog.api.client.v2.model.ServiceDefinitionsListResponse; @@ -12,6 +14,8 @@ import jakarta.ws.rs.core.GenericType; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -466,6 +470,35 @@ public ApiResponse getServiceDefinitionWithHttpInf new GenericType() {}); } + /** Manage optional parameters to listServiceDefinitions. */ + public static class ListServiceDefinitionsOptionalParameters { + private Long pageSize; + private Long pageNumber; + + /** + * Set pageSize. + * + * @param pageSize Size for a given page. The maximum allowed value is 5000. (optional, default + * to 10) + * @return ListServiceDefinitionsOptionalParameters + */ + public ListServiceDefinitionsOptionalParameters pageSize(Long pageSize) { + this.pageSize = pageSize; + return this; + } + + /** + * Set pageNumber. + * + * @param pageNumber Specific page number to return. (optional, default to 0) + * @return ListServiceDefinitionsOptionalParameters + */ + public ListServiceDefinitionsOptionalParameters pageNumber(Long pageNumber) { + this.pageNumber = pageNumber; + return this; + } + } + /** * Get all service definitions. * @@ -475,7 +508,8 @@ public ApiResponse getServiceDefinitionWithHttpInf * @throws ApiException if fails to make API call */ public ServiceDefinitionsListResponse listServiceDefinitions() throws ApiException { - return listServiceDefinitionsWithHttpInfo().getData(); + return listServiceDefinitionsWithHttpInfo(new ListServiceDefinitionsOptionalParameters()) + .getData(); } /** @@ -486,16 +520,100 @@ public ServiceDefinitionsListResponse listServiceDefinitions() throws ApiExcepti * @return CompletableFuture<ServiceDefinitionsListResponse> */ public CompletableFuture listServiceDefinitionsAsync() { - return listServiceDefinitionsWithHttpInfoAsync() + return listServiceDefinitionsWithHttpInfoAsync(new ListServiceDefinitionsOptionalParameters()) + .thenApply( + response -> { + return response.getData(); + }); + } + + /** + * Get all service definitions. + * + *

See {@link #listServiceDefinitionsWithHttpInfo}. + * + * @param parameters Optional parameters for the request. + * @return ServiceDefinitionsListResponse + * @throws ApiException if fails to make API call + */ + public ServiceDefinitionsListResponse listServiceDefinitions( + ListServiceDefinitionsOptionalParameters parameters) throws ApiException { + return listServiceDefinitionsWithHttpInfo(parameters).getData(); + } + + /** + * Get all service definitions. + * + *

See {@link #listServiceDefinitionsWithHttpInfoAsync}. + * + * @param parameters Optional parameters for the request. + * @return CompletableFuture<ServiceDefinitionsListResponse> + */ + public CompletableFuture listServiceDefinitionsAsync( + ListServiceDefinitionsOptionalParameters parameters) { + return listServiceDefinitionsWithHttpInfoAsync(parameters) .thenApply( response -> { return response.getData(); }); } + /** + * Get all service definitions. + * + *

See {@link #listServiceDefinitionsWithHttpInfo}. + * + * @return PaginationIterable<ServiceDefinitionData> + */ + public PaginationIterable listServiceDefinitionsWithPagination() { + ListServiceDefinitionsOptionalParameters parameters = + new ListServiceDefinitionsOptionalParameters(); + return listServiceDefinitionsWithPagination(parameters); + } + + /** + * Get all service definitions. + * + *

See {@link #listServiceDefinitionsWithHttpInfo}. + * + * @return ServiceDefinitionsListResponse + */ + public PaginationIterable listServiceDefinitionsWithPagination( + ListServiceDefinitionsOptionalParameters parameters) { + String resultsPath = "getData"; + String valueGetterPath = ""; + String valueSetterPath = "pageNumber"; + Boolean valueSetterParamOptional = true; + Long limit; + + if (parameters.pageSize == null) { + limit = 10l; + parameters.pageSize(limit); + } else { + limit = parameters.pageSize; + } + + LinkedHashMap args = new LinkedHashMap(); + args.put("optionalParams", parameters); + + PaginationIterable iterator = + new PaginationIterable( + this, + "listServiceDefinitions", + resultsPath, + valueGetterPath, + valueSetterPath, + valueSetterParamOptional, + limit, + args); + + return iterator; + } + /** * Get a list of all service definitions from the Datadog Service Catalog. * + * @param parameters Optional parameters for the request. * @return ApiResponse<ServiceDefinitionsListResponse> * @throws ApiException if fails to make API call * @http.response.details @@ -507,19 +625,25 @@ public CompletableFuture listServiceDefinitionsA * 429 Too many requests - * */ - public ApiResponse listServiceDefinitionsWithHttpInfo() - throws ApiException { + public ApiResponse listServiceDefinitionsWithHttpInfo( + ListServiceDefinitionsOptionalParameters parameters) throws ApiException { Object localVarPostBody = null; + Long pageSize = parameters.pageSize; + Long pageNumber = parameters.pageNumber; // create path and map variables String localVarPath = "/api/v2/services/definitions"; + List localVarQueryParams = new ArrayList(); Map localVarHeaderParams = new HashMap(); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[size]", pageSize)); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[number]", pageNumber)); + Invocation.Builder builder = apiClient.createBuilder( "v2.ServiceDefinitionApi.listServiceDefinitions", localVarPath, - new ArrayList(), + localVarQueryParams, localVarHeaderParams, new HashMap(), new String[] {"application/json"}, @@ -540,23 +664,30 @@ public ApiResponse listServiceDefinitionsWithHtt * *

See {@link #listServiceDefinitionsWithHttpInfo}. * + * @param parameters Optional parameters for the request. * @return CompletableFuture<ApiResponse<ServiceDefinitionsListResponse>> */ public CompletableFuture> - listServiceDefinitionsWithHttpInfoAsync() { + listServiceDefinitionsWithHttpInfoAsync(ListServiceDefinitionsOptionalParameters parameters) { Object localVarPostBody = null; + Long pageSize = parameters.pageSize; + Long pageNumber = parameters.pageNumber; // create path and map variables String localVarPath = "/api/v2/services/definitions"; + List localVarQueryParams = new ArrayList(); Map localVarHeaderParams = new HashMap(); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[size]", pageSize)); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[number]", pageNumber)); + Invocation.Builder builder; try { builder = apiClient.createBuilder( "v2.ServiceDefinitionApi.listServiceDefinitions", localVarPath, - new ArrayList(), + localVarQueryParams, localVarHeaderParams, new HashMap(), new String[] {"application/json"}, diff --git a/src/test/resources/cassettes/features/v2/Get_all_service_definitions_returns_OK_response_with_pagination.freeze b/src/test/resources/cassettes/features/v2/Get_all_service_definitions_returns_OK_response_with_pagination.freeze new file mode 100644 index 00000000000..86b2c4ba499 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Get_all_service_definitions_returns_OK_response_with_pagination.freeze @@ -0,0 +1 @@ +2023-04-05T09:45:34.876Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v2/Get_all_service_definitions_returns_OK_response_with_pagination.json b/src/test/resources/cassettes/features/v2/Get_all_service_definitions_returns_OK_response_with_pagination.json new file mode 100644 index 00000000000..c5f41c2c4c9 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Get_all_service_definitions_returns_OK_response_with_pagination.json @@ -0,0 +1,67 @@ +[ + { + "httpRequest": { + "headers": {}, + "method": "GET", + "path": "/api/v2/services/definitions", + "queryStringParameters": { + "page[size]": [ + "2" + ] + }, + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\":[{\"type\":\"service-definition\",\"id\":\"000c4db9ae43787066748b39ad1c3059\",\"attributes\":{\"meta\":{\"last-modified-time\":\"2023-04-03T20:23:00Z\",\"github-html-url\":\"\",\"ingestion-source\":\"api\",\"origin\":\"unknown\",\"origin-detail\":\"\",\"warnings\":[],\"ingested-schema-version\":\"v2.1\"},\"schema\":{\"schema-version\":\"v2.1\",\"dd-service\":\"service-examplecreateorupdateservicedefinitionusingschemav21returnscreatedresponse1680553380\",\"team\":\"my-team\",\"contacts\":[{\"name\":\"Team Email\",\"type\":\"email\",\"contact\":\"contact@datadoghq.com\"}],\"links\":[{\"name\":\"Architecture\",\"type\":\"doc\",\"provider\":\"Gigoogle drivetHub\",\"url\":\"https://my-runbook\"},{\"name\":\"Runbook\",\"type\":\"runbook\",\"url\":\"https://my-runbook\"},{\"name\":\"Source Code\",\"type\":\"repo\",\"provider\":\"GitHub\",\"url\":\"https://github.com/DataDog/schema\"}],\"tags\":[\"my:tag\",\"service: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\"}}}},{\"type\":\"service-definition\",\"id\":\"000c83c634df871f80ecbb47fa6b8bcc\",\"attributes\":{\"meta\":{\"last-modified-time\":\"2022-11-17T02:44:15Z\",\"github-html-url\":\"\",\"ingestion-source\":\"api\",\"origin\":\"\",\"origin-detail\":\"\",\"warnings\":[],\"ingested-schema-version\":\"v2\"},\"schema\":{\"schema-version\":\"v2\",\"dd-service\":\"service-test-ruby-create_or_update_service_definition_returns_created_response-1668653055\",\"dd-team\":\"my-team\",\"team\":\"my-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\":[\"my:tag\",\"service: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\"}}}}]}\n", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "2e4420ff-858d-e0f4-313c-cbc92eb665f7" + }, + { + "httpRequest": { + "headers": {}, + "method": "GET", + "path": "/api/v2/services/definitions", + "queryStringParameters": { + "page[size]": [ + "2" + ], + "page[number]": [ + "2" + ] + }, + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"data\":[{\"type\":\"service-definition\",\"id\":\"0059bcab67b74e99cc832ca503019574\",\"attributes\":{\"meta\":{\"last-modified-time\":\"2023-03-02T12:21:20Z\",\"github-html-url\":\"\",\"ingestion-source\":\"api\",\"origin\":\"dd_terraform\",\"origin-detail\":\"\",\"warnings\":[{\"keyword-location\":\"/properties/contacts/items/$ref/allOf/1/then/properties/contact/pattern\",\"instance-location\":\"/contacts/0/contact\",\"message\":\"does not match pattern 'https://[a-zA-Z0-9_\\\\\\\\-]+.slack\\\\\\\\.com/archives/[a-zA-Z0-9_\\\\\\\\-]+'\"},{\"keyword-location\":\"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format\",\"instance-location\":\"/contacts/1/contact\",\"message\":\"'BBB' is not valid 'email'\"},{\"keyword-location\":\"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format\",\"instance-location\":\"/contacts/2/contact\",\"message\":\"'AAA' is not valid 'email'\"},{\"keyword-location\":\"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format\",\"instance-location\":\"/contacts/3/contact\",\"message\":\"'AAA' is not valid 'email'\"},{\"keyword-location\":\"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format\",\"instance-location\":\"/contacts/4/contact\",\"message\":\"'BBB' is not valid 'email'\"}],\"ingested-schema-version\":\"v2\"},\"schema\":{\"schema-version\":\"v2\",\"dd-service\":\"tf-testaccdatadogservicedefinition_order-local-1677759678\",\"team\":\"\",\"contacts\":[{\"name\":\"AA\",\"type\":\"email\",\"contact\":\"AAA\"},{\"name\":\"AA\",\"type\":\"slack\",\"contact\":\"AAA\"},{\"name\":\"BB\",\"type\":\"email\",\"contact\":\"AAA\"},{\"name\":\"AA\",\"type\":\"email\",\"contact\":\"BBB\"},{\"name\":\"BB\",\"type\":\"email\",\"contact\":\"BBB\"}],\"links\":[],\"repos\":[],\"docs\":[],\"tags\":[\"aaa\",\"bbb\"],\"integrations\":{},\"extensions\":{}}}}]}\n", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "1c6d4b20-01a9-8d9d-e440-0911acda2436" + } +] \ No newline at end of file diff --git a/src/test/resources/com/datadog/api/client/v2/api/service_definition.feature b/src/test/resources/com/datadog/api/client/v2/api/service_definition.feature index aa775d8a753..ed4999b578c 100644 --- a/src/test/resources/com/datadog/api/client/v2/api/service_definition.feature +++ b/src/test/resources/com/datadog/api/client/v2/api/service_definition.feature @@ -104,4 +104,12 @@ Feature: Service Definition Given new "ListServiceDefinitions" request When the request is sent Then the response status is 200 OK - And the response "data[0].attributes.meta.ingested-schema-version" is equal to "v2" + And the response "data[0].attributes.meta.ingestion-source" is equal to "api" + + @replay-only @team:DataDog/service-catalog @with-pagination + Scenario: Get all service definitions returns "OK" response with pagination + Given new "ListServiceDefinitions" request + And request contains "page[size]" parameter with value 2 + When the request with pagination is sent + Then the response status is 200 OK + And the response has 3 items