Skip to content

Commit e600a8f

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
Add support for multi form parameter support (#1836)
* add support for multi query params * handle edge case * cleanup * docs * Regenerate client from commit aeb956c4 of spec repo --------- Co-authored-by: Sherzod Karimov <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent ac0f7f2 commit e600a8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1138
-516
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-11-04 17:58:11.008472",
8-
"spec_repo_commit": "6ffe013b"
7+
"regenerated": "2024-11-04 18:34:30.221886",
8+
"spec_repo_commit": "aeb956c4"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-11-04 17:58:11.026745",
13-
"spec_repo_commit": "6ffe013b"
12+
"regenerated": "2024-11-04 18:34:30.241262",
13+
"spec_repo_commit": "aeb956c4"
1414
}
1515
}
1616
}

.generator/src/generator/openapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ def collection_format(parameter):
403403
explode = parameter.get("explode", True if style == "form" else False)
404404
return matrix.get((style, explode), "multi")
405405

406+
return ""
407+
406408

407409
def format_server(server, server_variables=None, path=""):
408410
url = server["url"] + path

.generator/src/generator/templates/api/api.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class {{ className }}RequestFactory extends BaseAPIRequestFactory {
7171
// Query Params
7272
{%- endif %}
7373
if ({{ name|attribute_name }} !== undefined) {
74-
requestContext.setQueryParam("{{ name }}", ObjectSerializer.serialize({{ name|attribute_name }}, "{{ get_type_for_parameter(parameter) }}", "{{ get_format_for_schema(parameter) }}"));
74+
requestContext.setQueryParam("{{ name }}", ObjectSerializer.serialize({{ name|attribute_name }}, "{{ get_type_for_parameter(parameter) }}", "{{ get_format_for_schema(parameter) }}"), "{{ parameter|collection_format }}");
7575
}
7676
{%- endfor %}
7777

.generator/src/generator/templates/http/http.j2

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { userAgent } from "../../../userAgent";
22
// TODO: evaluate if we can easily get rid of this library
33
import FormData from "form-data";
4-
import URLParse from "url-parse";
54
import { isBrowser } from "../util";
5+
import { COLLECTION_FORMATS } from "../baseapi";
66

77
/**
88
* Interface for aborting fetch requests.
@@ -88,7 +88,7 @@ export interface HttpConfiguration {
8888
export class RequestContext {
8989
private headers: { [key: string]: string } = {};
9090
private body: RequestBody = undefined;
91-
private url: URLParse;
91+
private url: URL;
9292
private httpConfig: HttpConfiguration = {};
9393

9494
/**
@@ -98,7 +98,7 @@ export class RequestContext {
9898
* @param httpMethod http method
9999
*/
100100
public constructor(url: string, private httpMethod: HttpMethod) {
101-
this.url = new URLParse(url, true);
101+
this.url = new URL(url);
102102
if (!isBrowser) {
103103
this.headers = { "user-agent": userAgent };
104104
}
@@ -117,7 +117,7 @@ export class RequestContext {
117117
*
118118
*/
119119
public setUrl(url: string): void {
120-
this.url = new URLParse(url, true);
120+
this.url = new URL(url);
121121
}
122122

123123
/**
@@ -145,10 +145,27 @@ export class RequestContext {
145145
return this.body;
146146
}
147147

148-
public setQueryParam(name: string, value: string): void {
149-
const queryObj = this.url.query;
150-
queryObj[name] = value;
151-
this.url.set("query", queryObj);
148+
/**
149+
* Sets query parameters on the request URL
150+
*
151+
* @param name the name of the query parameter
152+
* @param value the value of the query parameter
153+
* @param collectionFormat the format of the query parameter See https://spec.openapis.org/oas/v3.0.2#style-values
154+
*/
155+
public setQueryParam(name: string, value: string | string[], collectionFormat: string): void {
156+
if (collectionFormat === "multi") {
157+
for (const val of value) {
158+
this.url.searchParams.append(name, val);
159+
}
160+
return;
161+
}
162+
163+
if (Array.isArray(value)) {
164+
const delimiter = COLLECTION_FORMATS[collectionFormat as keyof typeof COLLECTION_FORMATS];
165+
value = value.join(delimiter);
166+
}
167+
168+
return this.url.searchParams.set(name, value);
152169
}
153170

154171
/**

LICENSE-3rdparty.csv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Component,Licence,Copyright
99
@types/jest,MIT,Copyright Microsoft Corporation
1010
@types/node,MIT,Copyright Microsoft Corporation
1111
@types/pako,MIT,Copyright Caleb Eggensperger Muhammet Öztürk
12-
@types/url-parse,MIT,Copyright Microsoft Corporation
1312
@typescript-eslint/eslint-plugin,MIT,Copyright (c) 2019 TypeScript ESLint and other contributors
1413
@typescript-eslint/parser,BSD-2-Clause,
1514
buffer-from,MIT,Copyright (c) 2016, 2018 Linus Unnebäck
@@ -31,6 +30,5 @@ prettier,MIT,Copyright © James Long and contributors
3130
ts-node,MIT,Copyright (c) 2014 Blake Embrey ([email protected])
3231
typedoc,Apache-2.0,Copyright (c) 2015 Sebastian Lenz Copyright (c) 2016-2021 TypeDoc Contributors.
3332
typescript,Apache-2.0,Copyright (c) Microsoft Corporation.
34-
url-parse,MIT,Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.
3533
loglevel,MIT,Copyright (c) 2013 Tim Perry
3634
zstd.ts,BSD-2-Clause,Copyright (c) [2021] [Beeno Tung (Tung Cheung Leong)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2024-10-21T20:05:58.636Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"log": {
3+
"_recordingName": "Security Monitoring/List findings with detection_type query param returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "5f6fcc703704b0462fc33728fd9b12b2",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 0,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
}
23+
],
24+
"headersSize": 611,
25+
"httpVersion": "HTTP/1.1",
26+
"method": "GET",
27+
"queryString": [
28+
{
29+
"name": "filter",
30+
"value": {
31+
"vulnerability_type": [
32+
"misconfiguration",
33+
"attack_path"
34+
]
35+
}
36+
}
37+
],
38+
"url": "https://api.datadoghq.com/api/v2/posture_management/findings?filter%5Bvulnerability_type%5D=misconfiguration&filter%5Bvulnerability_type%5D=attack_path"
39+
},
40+
"response": {
41+
"bodySize": 89,
42+
"content": {
43+
"mimeType": "application/vnd.api+json",
44+
"size": 89,
45+
"text": "{\"data\":[],\"meta\":{\"page\":{\"total_filtered_count\":0},\"snapshot_timestamp\":1729541158755}}"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/vnd.api+json"
52+
}
53+
],
54+
"headersSize": 524,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2024-10-21T20:05:58.644Z",
61+
"time": 141
62+
}
63+
],
64+
"pages": [],
65+
"version": "1.2"
66+
}
67+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* List findings with detection_type query param returns "OK" response
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
configuration.unstableOperations["v2.listFindings"] = true;
9+
const apiInstance = new v2.SecurityMonitoringApi(configuration);
10+
11+
const params: v2.SecurityMonitoringApiListFindingsRequest = {
12+
filterVulnerabilityType: ["misconfiguration", "attack_path"],
13+
};
14+
15+
apiInstance
16+
.listFindings(params)
17+
.then((data: v2.ListFindingsResponse) => {
18+
console.log(
19+
"API called successfully. Returned data: " + JSON.stringify(data)
20+
);
21+
})
22+
.catch((error: any) => console.error(error));

features/v2/security_monitoring.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,14 @@ Feature: Security Monitoring
485485
When the request with pagination is sent
486486
Then the response status is 200 OK
487487

488+
@skip-terraform-config @team:DataDog/cloud-security-posture-management
489+
Scenario: List findings with detection_type query param returns "OK" response
490+
Given operation "ListFindings" enabled
491+
And new "ListFindings" request
492+
And request contains "filter[vulnerability_type]" parameter with value ["misconfiguration", "attack_path"]
493+
When the request is sent
494+
Then the response status is 200 OK
495+
488496
@generated @skip @team:DataDog/k9-cloud-security-platform
489497
Scenario: List rules returns "Bad Request" response
490498
Given new "ListSecurityMonitoringRules" request

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@
7272
"es6-promise": "^4.2.8",
7373
"form-data": "^4.0.0",
7474
"loglevel": "^1.8.1",
75-
"pako": "^2.0.4",
76-
"url-parse": "^1.4.3"
75+
"pako": "^2.0.4"
7776
},
7877
"resolutions": {
7978
"@pollyjs/adapter-node-http/nock": "^13.1.3"
@@ -86,7 +85,6 @@
8685
"@pollyjs/persister-fs": "^6.0.5",
8786
"@types/chai": "^4.3.4",
8887
"@types/jest": "^29.5.2",
89-
"@types/url-parse": "^1.4.3",
9088
"@typescript-eslint/eslint-plugin": "^5.54.0",
9189
"@typescript-eslint/parser": "^5.54.0",
9290
"chai": "^4.3.7",

0 commit comments

Comments
 (0)