Skip to content

Commit c3f2dee

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

File tree

14 files changed

+82
-56
lines changed

14 files changed

+82
-56
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/schematics/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ The parameter types that we support are stored in `SupportedParamType` in the pa
123123
> We provide the methods `serializeQueryParams` and `serializePathParams` to serialize the values of query and path parameters. However, it is also possible to pass
124124
> your own serialization methods if the ones provided do not meet your requirements. These custom methods can be passed as a parameter to the API client constructor.
125125
126+
> [!NOTE]
127+
> If you update the query parameters within a `RequestPlugin`, these must be serialized before being returned to the API to prepare the URL. You can do so by using the
128+
> serialization method that we provide (`serializeQueryParams`) or your own serialization method. The value of the query parameters returned by the `RequestPlugin` will
129+
> be directly added to the URL.
130+
126131
#### Light SDK
127132

128133
It is also possible to generate a "light" SDK. This type of SDK does not need to generate revivers, which results in a simplified version of the code and reduces the size of the bundle.

packages/@ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/src/main/resources/typescriptFetch/api/api.mustache

+9-9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export class {{classname}} implements Api {
7272
{{/allParams}}
7373
const queryParamsProperties = {{#hasQueryParams}}this.client.getPropertiesFromData(data, [{{#trimComma}}{{#queryParams}}'{{baseName}}', {{/queryParams}}{{/trimComma}}]){{/hasQueryParams}}{{^hasQueryParams}}{}{{/hasQueryParams}};
7474
const queryParams = this.client.stringifyQueryParams(queryParamsProperties);
75+
{{#hasQueryParams}}
76+
const queryParamSerialization = { {{#trimComma}}{{#queryParams}}{{baseName}}: { explode: {{isExplode}}, style: '{{style}}' }, {{/queryParams}}{{/trimComma}} };
77+
const serializedQueryParams = this.client.serializeQueryParams(queryParamsProperties, queryParamSerialization);
78+
{{/hasQueryParams}}
7579
const metadataHeaderAccept = metadata?.headerAccept || '{{#headerJsonMimeType}}{{#produces}}{{mediaType}}{{^-last}}, {{/-last}}{{/produces}}{{/headerJsonMimeType}}';
7680
const headers: { [key: string]: string | undefined } = {
7781
{{#trimComma}} 'Content-Type': metadata?.headerContentType || '{{#headerJsonMimeType}}{{#consumes}}{{mediaType}}{{^-last}}, {{/-last}}{{/consumes}}{{/headerJsonMimeType}}',
@@ -102,7 +106,8 @@ export class {{classname}} implements Api {
102106
{{/bodyParam}}
103107
{{#hasPathParams}}
104108
const pathParamsProperties = this.client.getPropertiesFromData(data, [{{#trimComma}}{{#pathParams}}'{{baseName}}', {{/pathParams}}{{/trimComma}}]);
105-
const serializedPathParams = this.client.serializePathParams(pathParamsProperties, { {{#trimComma}}{{#pathParams}}{{baseName}}: { explode: {{isExplode}}, style: '{{style}}' }, {{/pathParams}}{{/trimComma}} });
109+
const pathParamSerialization = { {{#trimComma}}{{#pathParams}}{{baseName}}: { explode: {{isExplode}}, style: '{{style}}' }, {{/pathParams}}{{/trimComma}} }
110+
const serializedPathParams = this.client.serializePathParams(pathParamsProperties, pathParamSerialization);
106111
{{/hasPathParams}}
107112
const basePath = `${this.client.options.basePath}{{#urlParamReplacer}}{{path}}{{/urlParamReplacer}}`;
108113
const tokenizedUrl = `${this.client.options.basePath}{{#tokenizedUrlParamReplacer}}{{path}}{{/tokenizedUrlParamReplacer}}`;
@@ -112,21 +117,16 @@ export class {{classname}} implements Api {
112117
headers,
113118
method: '{{httpMethod}}',
114119
basePath,
115-
queryParams,
120+
queryParams{{#hasQueryParams}}: serializedQueryParams,
121+
queryParamSerialization{{/hasQueryParams}},
116122
body: body || undefined,
117123
metadata,
118124
tokenizedOptions,
119125
api: this
120126
};
121127

122128
const options = await this.client.getRequestOptions(requestOptions);
123-
{{#hasQueryParams}}
124-
const serializedQueryParams = this.client.serializeQueryParams(queryParamsProperties, { {{#trimComma}}{{#queryParams}}{{baseName}}: { explode: {{isExplode}}, style: '{{style}}' }, {{/queryParams}}{{/trimComma}} });
125-
const url = this.client.prepareUrlWithQueryParams(options.basePath, serializedQueryParams);
126-
{{/hasQueryParams}}
127-
{{^hasQueryParams}}
128-
const url = options.basePath;
129-
{{/hasQueryParams}}
129+
const url = this.client.prepareUrlWithQueryParams(options.basePath, options.queryParams);
130130

131131
const ret = this.client.processCall<{{#vendorExtensions}}{{#responses2xxReturnTypes}}{{.}}{{^-last}} | {{/-last}}{{/responses2xxReturnTypes}}{{^responses2xxReturnTypes}}never{{/responses2xxReturnTypes}}{{/vendorExtensions}}>(url, options, {{#tags.0.extensions.x-api-type}}ApiTypes.{{tags.0.extensions.x-api-type}}{{/tags.0.extensions.x-api-type}}{{^tags.0.extensions.x-api-type}}ApiTypes.DEFAULT{{/tags.0.extensions.x-api-type}}, {{classname}}.apiName,{{#keepRevivers}}{{#vendorExtensions}}{{#responses2xx}}{{#-first}} { {{/-first}}{{code}}: {{^primitiveType}}revive{{baseType}}{{/primitiveType}}{{#primitiveType}}undefined{{/primitiveType}}{{^-last}}, {{/-last}}{{#-last}} } {{/-last}}{{/responses2xx}}{{^responses2xx}} undefined{{/responses2xx}}{{/vendorExtensions}}{{/keepRevivers}}{{^keepRevivers}} undefined{{/keepRevivers}}, '{{nickname}}');
132132
return ret;

0 commit comments

Comments
 (0)