Skip to content

Commit

Permalink
fix(postman): address complexity issue
Browse files Browse the repository at this point in the history
fixes #250
  • Loading branch information
ostridm committed Aug 22, 2024
1 parent ce3233c commit 8bc4c2a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/postman/src/converter/DefaultConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,12 @@ export class DefaultConverter implements Converter {

/* istanbul ignore next */
private authRequest(request: Request, auth: Postman.RequestAuth): void {
const params: Postman.Variable[] | Record<string, string> | undefined =
auth[auth.type];
const options = this.getAuthOptions(auth);

if (!params) {
if (!options) {
return;
}

const options = Array.isArray(params)
? Object.fromEntries(
params.map((val: Postman.Variable) =>
[val.key, val.value].map(String)
)
)
: params;

switch (auth.type) {
case 'apikey':
this.apiKeyAuth(request, options);
Expand All @@ -155,6 +146,23 @@ export class DefaultConverter implements Converter {
}
}

private getAuthOptions(
auth: Postman.RequestAuth
): Record<string, string> | undefined {
const params: Postman.Variable[] | Record<string, string> | undefined =
auth[auth.type];

return !params
? params
: Array.isArray(params)
? Object.fromEntries(
params.map((val: Postman.Variable) =>
[val.key, val.value].map(String)
)
)
: params;
}

/* istanbul ignore next */
private oauth2(request: Request, options: Record<string, string>): void {
if (!options.accessToken || options.tokenType === 'mac') {
Expand Down

0 comments on commit 8bc4c2a

Please sign in to comment.