Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT REVIEW] feat: support exploded syntax in sdk #2865

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sdo-1A
Copy link
Contributor

@sdo-1A sdo-1A commented Feb 18, 2025

Proposed change

Support of exploded syntax for query and path parameters: https://swagger.io/docs/specification/v3_0/serialization/

Related issues

#640

- No issue associated -

Copy link

nx-cloud bot commented Feb 18, 2025

View your CI Pipeline Execution ↗ for commit 0dbb519.

Command Status Duration Result
nx run-many --target=test-int ✅ Succeeded 24m 23s View ↗
nx run-many --target=test-e2e ✅ Succeeded 10m 21s View ↗
nx run-many --target=build --projects=eslint-pl... ✅ Succeeded 2s View ↗
nx run-many --target=publish --nx-bail --userco... ✅ Succeeded 33s View ↗
nx run-many --target=prepare-publish --exclude-... ✅ Succeeded 1m 15s View ↗
nx run-many --target=build,build-swagger ✅ Succeeded 5m 48s View ↗
nx affected --target=test --collectCoverage ✅ Succeeded 1m 1s View ↗
nx affected --target=lint ✅ Succeeded 2m 36s View ↗
Additional runs (3) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-18 17:02:16 UTC

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 66.05505% with 37 lines in your changes missing coverage. Please review.

Project coverage is 71.47%. Comparing base (d032a4d) to head (0dbb519).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/@ama-sdk/core/src/fwk/api.helpers.ts 76.25% 16 Missing and 3 partials ⚠️
...ges/@ama-sdk/core/src/clients/api-beacon-client.ts 0.00% 7 Missing ⚠️
...ages/@ama-sdk/core/src/clients/api-fetch-client.ts 0.00% 7 Missing ⚠️
...-sdk/core/src/plugins/si-token/si-token.request.ts 57.14% 0 Missing and 3 partials ⚠️
packages/@ama-sdk/core/src/utils/generic-api.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sdo-1A sdo-1A marked this pull request as ready for review February 19, 2025 09:56
@sdo-1A sdo-1A requested a review from a team as a code owner February 19, 2025 09:56
@@ -67,7 +67,7 @@ public UrlParamReplacerLambda() {}

@Override
public String formatFragment(String fragment) {
return fragment.replaceAll("\\{([\\w_-]+)\\}", "\\${data['$1']}");
return fragment.replaceAll("\\{([\\w_-]+)\\}", "\\${pathParameters['$1']}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the doc of the class should be updated as well (same for the other one bellow)

Comment on lines +227 to +232
? Object.keys(object)
.filter((objectKey) => !!object[objectKey])
.reduce<{ [key: string]: ParamSerialization }>((acc, objectKey) => {
acc[objectKey] = object[objectKey] as ParamSerialization;
return acc;
}, {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? Object.keys(object)
.filter((objectKey) => !!object[objectKey])
.reduce<{ [key: string]: ParamSerialization }>((acc, objectKey) => {
acc[objectKey] = object[objectKey] as ParamSerialization;
return acc;
}, {})
? Object.fromEntries(Object.entries(object).filter(([_key, value]) => typeof value !== 'undefined'))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(you can even remove _key:

Suggested change
? Object.keys(object)
.filter((objectKey) => !!object[objectKey])
.reduce<{ [key: string]: ParamSerialization }>((acc, objectKey) => {
acc[objectKey] = object[objectKey] as ParamSerialization;
return acc;
}, {})
? Object.fromEntries(Object.entries(object).filter(([, value]) => typeof value !== 'undefined'))

)

Comment on lines +44 to +53
if (isPartialRecordTypeString(queryParameters)) {
const queryPart = Object.keys(queryParameters)
.filter((name) => typeof queryParameters[name] !== 'undefined')
.map((name) => `${name}=${queryParameters[name]!}`)
.join('&');

return url + (queryPart ? paramsPrefix + queryPart : '');
}

const filteredQueryParams = filterUndefinedQueryParams(queryParameters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isPartialRecordTypeString(queryParameters)) {
const queryPart = Object.keys(queryParameters)
.filter((name) => typeof queryParameters[name] !== 'undefined')
.map((name) => `${name}=${queryParameters[name]!}`)
.join('&');
return url + (queryPart ? paramsPrefix + queryPart : '');
}
const filteredQueryParams = filterUndefinedQueryParams(queryParameters);
const filteredQueryParams = filterUndefinedQueryParams(queryParameters);
if (isRecordTypeString(filteredQueryParams)) {
const queryPart = Object.entries(filteredQueryParams)
.map(([name, value]) => `${name}=${value}`)
.join('&');
return url + (queryPart ? paramsPrefix + queryPart : '');
}

@@ -75,7 +88,8 @@ export class ApiAngularClient implements ApiClient {
let opts: RequestOptions = {
...requestOptionsParameters,
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have a breaking change here for the plugins:
Regarding your template update, you always pass {} as value for queryParams.
Which means that the external plugins implemented to treat queryParams will not have any effect anymore.

There is also another point to handle: even if the correct queryParams are provided to the plugin, the update of it by a plugin will be ignore (as queryParameters has the priority).
A suggestion (not the best one :S) can be to raise an error if the ref to the queryParams is different that the original one and if !!queryParameters

Comment on lines +80 to 83
if (Array.isArray(names)) {
return extractQueryParams(data, names);
}
return extractQueryParams(data, names);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it different to

Suggested change
if (Array.isArray(names)) {
return extractQueryParams(data, names);
}
return extractQueryParams(data, names);
return extractQueryParams(data, names);

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in order to target the correct function since this function has been overloaded, I check the type of the parameter to target either the deprecated version or the new version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it should not change the return type of extractQueryParams.
Did you face type issue without the Array.isArray?
(I was actually triggered because adding JS process to handle TypeScript type issue is generally not the good practice :S)

* @param obj
*/
export function isRecordTypeString(obj: any): obj is { [key: string]: string } {
return Object.values(obj).every((item) => typeof item === 'string');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true for any type obj !== 'object' maybe you should check:

Suggested change
return Object.values(obj).every((item) => typeof item === 'string');
return typeof obj === 'object' && Object.values(obj).every((item) => typeof item === 'string');

? Object.keys(object)
.filter((objectKey) => !!object[objectKey])
.reduce<{ [key: string]: ParamSerialization }>((acc, objectKey) => {
acc[objectKey] = object[objectKey] as ParamSerialization;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
acc[objectKey] = object[objectKey] as ParamSerialization;
acc[objectKey] = object[objectKey]!;

?

return extractQueryParams(data, names);
}

/** @inheritdoc */
public tokenizeRequestOptions(url: string, queryParameters: { [key: string]: string }, piiParamTokens: { [key: string]: string }, data: any): TokenizedOptions | undefined {
public tokenizeRequestOptions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As other function you implemented, maybe an overload of this one to deprecate { [key: string]: string } can be valuable?

@kpanot
Copy link
Contributor

kpanot commented Feb 19, 2025

You may want to add a deprecate: .... commit message to list your commit in deprecated warnings in release not

@sdo-1A sdo-1A changed the title feat: support exploded syntax in sdk [DO NOT REVIEW] feat: support exploded syntax in sdk Feb 20, 2025
@kpanot kpanot marked this pull request as draft February 22, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants