Skip to content

Commit 3fcbd65

Browse files
committed
fix: sdk exploded syntax - take into account request plugin options
1 parent 0a1fa58 commit 3fcbd65

File tree

23 files changed

+442
-84
lines changed

23 files changed

+442
-84
lines changed

packages/@ama-sdk/client-angular/src/api-angular-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class ApiAngularClient implements ApiClient {
130130
}
131131

132132
/** @inheritdoc */
133-
public prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
133+
public prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string {
134134
return prepareUrlWithQueryParams(url, serializedQueryParams);
135135
}
136136

packages/@ama-sdk/client-beacon/src/api-beacon-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class ApiBeaconClient implements ApiClient {
130130
}
131131

132132
/** @inheritdoc */
133-
public prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
133+
public prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string {
134134
return prepareUrlWithQueryParams(url, serializedQueryParams);
135135
}
136136

packages/@ama-sdk/client-fetch/src/api-fetch-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class ApiFetchClient implements ApiClient {
131131
}
132132

133133
/** @inheritdoc */
134-
public prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
134+
public prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string {
135135
return prepareUrlWithQueryParams(url, serializedQueryParams);
136136
}
137137

packages/@ama-sdk/core/src/clients/api-angular-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class ApiAngularClient implements ApiClient {
160160
}
161161

162162
/** @inheritdoc */
163-
public prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
163+
public prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string {
164164
return prepareUrlWithQueryParams(url, serializedQueryParams);
165165
}
166166

packages/@ama-sdk/core/src/clients/api-beacon-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class ApiBeaconClient implements ApiClient {
148148
}
149149

150150
/** @inheritdoc */
151-
public prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
151+
public prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string {
152152
return prepareUrlWithQueryParams(url, serializedQueryParams);
153153
}
154154

packages/@ama-sdk/core/src/clients/api-fetch-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class ApiFetchClient implements ApiClient {
156156
}
157157

158158
/** @inheritdoc */
159-
public prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
159+
public prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string {
160160
return prepareUrlWithQueryParams(url, serializedQueryParams);
161161
}
162162

packages/@ama-sdk/core/src/fwk/api.helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function prepareUrl(url: string, queryParameters: { [key: string]: string
3131
* @param url Base url to be used
3232
* @param serializedQueryParams Key value pairs of query parameter names and their serialized values
3333
*/
34-
export function prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string {
34+
export function prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string } = {}): string {
3535
const paramsPrefix = url.includes('?') ? '&' : '?';
3636
const queryPart = Object.values(serializedQueryParams).join('&');
3737
return url + (queryPart ? paramsPrefix + queryPart : '');

packages/@ama-sdk/core/src/fwk/core/api-client.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface RequestOptionsParameters {
2727
basePath: string;
2828
/** Query Parameters */
2929
queryParams?: { [key: string]: string | undefined };
30+
/** Serialization of the query parameters (style and explode) */
31+
queryParamSerialization?: { [key: string]: ParamSerialization };
3032
/** Force body to string */
3133
body?: RequestBody;
3234
/** Force headers to Headers type */
@@ -91,7 +93,7 @@ export interface ApiClient {
9193
* @param url Base url to be used
9294
* @param serializedQueryParams Key value pairs of query parameter names and their serialized values
9395
*/
94-
prepareUrlWithQueryParams(url: string, serializedQueryParams: { [key: string]: string }): string;
96+
prepareUrlWithQueryParams(url: string, serializedQueryParams?: { [key: string]: string }): string;
9597

9698
/**
9799
* Serialize query parameters based on the values of exploded and style

packages/@ama-sdk/core/src/fwk/param-serialization.spec.ts

+61
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
utils,
66
} from './date';
77
import {
8+
deserializePathParams,
9+
deserializeQueryParams,
810
serializePathParams,
911
serializeQueryParams,
1012
} from './param-serialization';
@@ -215,3 +217,62 @@ describe('Serialize parameters', () => {
215217
expect(serializePathParams(mockUtilsDateTimeParams, { idUtilsDateTime: { explode: true, style: 'simple' } })).toEqual({ idUtilsDateTime: '2025-01-01T00:00:00.000' });
216218
});
217219
});
220+
221+
describe('Deserialize parameters', () => {
222+
it('should correctly deserialize query parameters', () => {
223+
// value = primitive
224+
expect(deserializeQueryParams({ idPrimitive: 'idPrimitive=5' }, { idPrimitive: { explode: true, style: 'form', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
225+
expect(deserializeQueryParams({ idPrimitive: 'idPrimitive=5' }, { idPrimitive: { explode: false, style: 'form', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
226+
// value = array
227+
expect(deserializeQueryParams({ idArray: 'idArray=3&idArray=4&idArray=5' }, { idArray: { explode: true, style: 'form', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
228+
expect(deserializeQueryParams({ idArray: 'idArray=3,4,5' }, { idArray: { explode: false, style: 'form', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
229+
expect(deserializeQueryParams({ idArray: 'should-not-work' }, { idArray: { explode: true, style: 'spaceDelimited', paramType: 'array' } })).toEqual({ idArray: undefined });
230+
expect(deserializeQueryParams({ idArray: 'idArray=3%204%205' }, { idArray: { explode: false, style: 'spaceDelimited', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
231+
expect(deserializeQueryParams({ idArray: 'should-not-work' }, { idArray: { explode: true, style: 'pipeDelimited', paramType: 'array' } })).toEqual({ idArray: undefined });
232+
expect(deserializeQueryParams({ idArray: 'idArray=3%7C4%7C5' }, { idArray: { explode: false, style: 'pipeDelimited', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
233+
// value = object
234+
expect(deserializeQueryParams({ idObject: 'role=admin&firstName=Alex' }, { idObject: { explode: true, style: 'form', paramType: 'object' } }))
235+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
236+
expect(deserializeQueryParams({ idObject: 'idObject=role,admin,firstName,Alex' }, { idObject: { explode: false, style: 'form', paramType: 'object' } }))
237+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
238+
expect(deserializeQueryParams({ idObject: 'should-not-work' }, { idObject: { explode: true, style: 'spaceDelimited', paramType: 'object' } })).toEqual({ idObject: undefined });
239+
expect(deserializeQueryParams({ idObject: 'idObject=role%20admin%20firstName%20Alex' }, { idObject: { explode: false, style: 'spaceDelimited', paramType: 'object' } }))
240+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
241+
expect(deserializeQueryParams({ idObject: 'should-not-work' }, { idObject: { explode: true, style: 'pipeDelimited', paramType: 'object' } })).toEqual({ idObject: undefined });
242+
expect(deserializeQueryParams({ idObject: 'idObject=role%7Cadmin%7CfirstName%7CAlex' }, { idObject: { explode: false, style: 'pipeDelimited', paramType: 'object' } }))
243+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
244+
expect(deserializeQueryParams({ idObject: 'idObject%5Brole%5D=admin&idObject%5BfirstName%5D=Alex' }, { idObject: { explode: true, style: 'deepObject', paramType: 'object' } }))
245+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
246+
expect(deserializeQueryParams({ idObject: 'should-not-work' }, { idObject: { explode: false, style: 'deepObject', paramType: 'object' } })).toEqual({ idObject: undefined });
247+
});
248+
249+
it('should correctly deserialize path parameters', () => {
250+
// value = primitive
251+
expect(deserializePathParams({ idPrimitive: '5' }, { idPrimitive: { explode: true, style: 'simple', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
252+
expect(deserializePathParams({ idPrimitive: '5' }, { idPrimitive: { explode: false, style: 'simple', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
253+
expect(deserializePathParams({ idPrimitive: '.5' }, { idPrimitive: { explode: true, style: 'label', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
254+
expect(deserializePathParams({ idPrimitive: '.5' }, { idPrimitive: { explode: false, style: 'label', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
255+
expect(deserializePathParams({ idPrimitive: ';idPrimitive=5' }, { idPrimitive: { explode: true, style: 'matrix', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
256+
expect(deserializePathParams({ idPrimitive: ';idPrimitive=5' }, { idPrimitive: { explode: false, style: 'matrix', paramType: 'primitive' } })).toEqual({ idPrimitive: '5' });
257+
// value = array
258+
expect(deserializePathParams({ idArray: '3,4,5' }, { idArray: { explode: true, style: 'simple', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
259+
expect(deserializePathParams({ idArray: '3,4,5' }, { idArray: { explode: false, style: 'simple', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
260+
expect(deserializePathParams({ idArray: '.3.4.5' }, { idArray: { explode: true, style: 'label', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
261+
expect(deserializePathParams({ idArray: '.3,4,5' }, { idArray: { explode: false, style: 'label', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
262+
expect(deserializePathParams({ idArray: ';idArray=3;idArray=4;idArray=5' }, { idArray: { explode: true, style: 'matrix', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
263+
expect(deserializePathParams({ idArray: ';idArray=3,4,5' }, { idArray: { explode: false, style: 'matrix', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
264+
// value = object
265+
expect(deserializePathParams({ idObject: 'role=admin,firstName=Alex' }, { idObject: { explode: true, style: 'simple', paramType: 'object' } }))
266+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
267+
expect(deserializePathParams({ idObject: 'role,admin,firstName,Alex' }, { idObject: { explode: false, style: 'simple', paramType: 'object' } }))
268+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
269+
expect(deserializePathParams({ idObject: '.role=admin.firstName=Alex' }, { idObject: { explode: true, style: 'label', paramType: 'object' } }))
270+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
271+
expect(deserializePathParams({ idObject: '.role,admin,firstName,Alex' }, { idObject: { explode: false, style: 'label', paramType: 'object' } }))
272+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
273+
expect(deserializePathParams({ idObject: ';role=admin;firstName=Alex' }, { idObject: { explode: true, style: 'matrix', paramType: 'object' } }))
274+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
275+
expect(deserializePathParams({ idObject: ';idObject=role,admin,firstName,Alex' }, { idObject: { explode: false, style: 'matrix', paramType: 'object' } }))
276+
.toEqual({ idObject: { role: 'admin', firstName: 'Alex' } });
277+
});
278+
});

0 commit comments

Comments
 (0)