-
Notifications
You must be signed in to change notification settings - Fork 41
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
base: main
Are you sure you want to change the base?
Conversation
View your CI Pipeline Execution ↗ for commit 0dbb519.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found. Additional details and impacted files☔ View full report in Codecov by Sentry. |
@@ -67,7 +67,7 @@ public UrlParamReplacerLambda() {} | |||
|
|||
@Override | |||
public String formatFragment(String fragment) { | |||
return fragment.replaceAll("\\{([\\w_-]+)\\}", "\\${data['$1']}"); | |||
return fragment.replaceAll("\\{([\\w_-]+)\\}", "\\${pathParameters['$1']}"); |
There was a problem hiding this comment.
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)
? Object.keys(object) | ||
.filter((objectKey) => !!object[objectKey]) | ||
.reduce<{ [key: string]: ParamSerialization }>((acc, objectKey) => { | ||
acc[objectKey] = object[objectKey] as ParamSerialization; | ||
return acc; | ||
}, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? 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')) |
There was a problem hiding this comment.
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
:
? 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')) |
)
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), |
There was a problem hiding this comment.
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
if (Array.isArray(names)) { | ||
return extractQueryParams(data, names); | ||
} | ||
return extractQueryParams(data, names); |
There was a problem hiding this comment.
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
if (Array.isArray(names)) { | |
return extractQueryParams(data, names); | |
} | |
return extractQueryParams(data, names); | |
return extractQueryParams(data, names); |
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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:
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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( |
There was a problem hiding this comment.
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?
You may want to add a |
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 -