Skip to content

Commit 66796bb

Browse files
skarimoci.datadog-api-spec
andauthored
Generate pagination examples (#776)
* generate pagination examples * spacing * support older js version syntax * pre-commit fixes * pre-commit fixes Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 7bea5f0 commit 66796bb

14 files changed

+355
-1
lines changed

.generator/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def pytest_bdd_after_scenario(request, feature, scenario):
105105

106106
def pytest_bdd_apply_tag(tag, function):
107107
"""Register tags as custom markers and skip test for '@skip' ones."""
108-
skip_tags = {"with-pagination"}
108+
skip_tags = {}
109109
if tag in skip_tags:
110110
marker = pytest.mark.skip(reason=f"skipped because '{tag}' in {skip_tags}")
111111
marker(function)
@@ -442,6 +442,7 @@ def execute_request(context, api_version):
442442
@when("the request with pagination is sent")
443443
def execute_request_with_pagination(context):
444444
"""Execute the prepared request paginated."""
445+
context["pagination"] = True
445446

446447

447448
@then(parsers.parse("the response status is {status:d} {description}"))

.generator/src/generator/templates/example.j2

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,24 @@ const params: {{ version }}.{{ context.api_instance.name }}Api{{ context.api_req
5353
};
5454
{%- endif %}
5555

56+
{%- if context.pagination %}
57+
58+
(async () => {
59+
try {
60+
for await (const item of apiInstance.{{ context.api_request.operation_id|untitle_case }}WithPagination({% if has_params %}params{% endif %})) {
61+
console.log(item);
62+
}
63+
} catch (error) {
64+
console.error(error)
65+
}
66+
})();
67+
68+
{%- else %}
69+
5670
apiInstance
5771
.{{ context.api_request.operation_id|untitle_case }}({% if has_params %}params{% endif %})
5872
.then((data: {% if api_response_type %}{{ api_response_type }}{% else %}any{% endif %}) => {
5973
console.log("API called successfully. Returned data: " + JSON.stringify(data));
6074
})
6175
.catch((error: any) => console.error(error));
76+
{%-endif %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get a list of Audit Logs events returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.AuditApi(configuration);
9+
10+
const params: v2.AuditApiListAuditLogsRequest = {
11+
pageLimit: 2,
12+
};
13+
14+
(async () => {
15+
try {
16+
for await (const item of apiInstance.listAuditLogsWithPagination(params)) {
17+
console.log(item);
18+
}
19+
} catch (error) {
20+
console.error(error);
21+
}
22+
})();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Search Audit Logs events returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.AuditApi(configuration);
9+
10+
const params: v2.AuditApiSearchAuditLogsRequest = {
11+
body: {
12+
filter: {
13+
from: "now-15m",
14+
to: "now",
15+
},
16+
options: {
17+
timezone: "GMT",
18+
},
19+
page: {
20+
limit: 2,
21+
},
22+
sort: "timestamp",
23+
},
24+
};
25+
26+
(async () => {
27+
try {
28+
for await (const item of apiInstance.searchAuditLogsWithPagination(
29+
params
30+
)) {
31+
console.log(item);
32+
}
33+
} catch (error) {
34+
console.error(error);
35+
}
36+
})();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Get a list of events returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
configuration.unstableOperations["v2.listEvents"] = true;
9+
const apiInstance = new v2.EventsApi(configuration);
10+
11+
const params: v2.EventsApiListEventsRequest = {
12+
filterFrom: "now-15m",
13+
filterTo: "now",
14+
pageLimit: 2,
15+
};
16+
17+
(async () => {
18+
try {
19+
for await (const item of apiInstance.listEventsWithPagination(params)) {
20+
console.log(item);
21+
}
22+
} catch (error) {
23+
console.error(error);
24+
}
25+
})();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Search events returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
configuration.unstableOperations["v2.searchEvents"] = true;
9+
const apiInstance = new v2.EventsApi(configuration);
10+
11+
const params: v2.EventsApiSearchEventsRequest = {
12+
body: {
13+
filter: {
14+
from: "now-15m",
15+
to: "now",
16+
},
17+
options: {
18+
timezone: "GMT",
19+
},
20+
page: {
21+
limit: 2,
22+
},
23+
sort: "timestamp",
24+
},
25+
};
26+
27+
(async () => {
28+
try {
29+
for await (const item of apiInstance.searchEventsWithPagination(params)) {
30+
console.log(item);
31+
}
32+
} catch (error) {
33+
console.error(error);
34+
}
35+
})();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Get a list of incidents returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
configuration.unstableOperations["v2.listIncidents"] = true;
9+
const apiInstance = new v2.IncidentsApi(configuration);
10+
11+
const params: v2.IncidentsApiListIncidentsRequest = {
12+
pageSize: 2,
13+
};
14+
15+
(async () => {
16+
try {
17+
for await (const item of apiInstance.listIncidentsWithPagination(params)) {
18+
console.log(item);
19+
}
20+
} catch (error) {
21+
console.error(error);
22+
}
23+
})();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get a list of logs returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.LogsApi(configuration);
9+
10+
const params: v2.LogsApiListLogsGetRequest = {
11+
pageLimit: 2,
12+
};
13+
14+
(async () => {
15+
try {
16+
for await (const item of apiInstance.listLogsGetWithPagination(params)) {
17+
console.log(item);
18+
}
19+
} catch (error) {
20+
console.error(error);
21+
}
22+
})();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Search logs returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.LogsApi(configuration);
9+
10+
const params: v2.LogsApiListLogsRequest = {
11+
body: {
12+
filter: {
13+
from: "now-15m",
14+
indexes: ["main"],
15+
to: "now",
16+
},
17+
options: {
18+
timezone: "GMT",
19+
},
20+
page: {
21+
limit: 2,
22+
},
23+
sort: "timestamp",
24+
},
25+
};
26+
27+
(async () => {
28+
try {
29+
for await (const item of apiInstance.listLogsWithPagination(params)) {
30+
console.log(item);
31+
}
32+
} catch (error) {
33+
console.error(error);
34+
}
35+
})();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get all processes returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.ProcessesApi(configuration);
9+
10+
const params: v2.ProcessesApiListProcessesRequest = {
11+
pageLimit: 2,
12+
};
13+
14+
(async () => {
15+
try {
16+
for await (const item of apiInstance.listProcessesWithPagination(params)) {
17+
console.log(item);
18+
}
19+
} catch (error) {
20+
console.error(error);
21+
}
22+
})();

0 commit comments

Comments
 (0)