Skip to content

Commit

Permalink
fix(postman): introduce support for v2.0.0 auth object
Browse files Browse the repository at this point in the history
fixes #250
  • Loading branch information
ostridm committed Aug 22, 2024
1 parent 70d8afe commit 5cc3237
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/postman/src/converter/DefaultConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,18 @@ export class DefaultConverter implements Converter {

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

if (!params) {
return;
}

// ADHOC: convert 2.0.0 auth carried as a Record
if (!Array.isArray(params)) {
params = Object.entries(params).map((x) => ({ key: x[0], value: x[1] }));
}

const options = Object.fromEntries(
params.map((val: Postman.Variable) => [val.key, val.value].map(String))
);
Expand Down
5 changes: 5 additions & 0 deletions packages/postman/tests/DefaultConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe('DefaultConverter', () => {
});

it.each([
{
inputPath: './fixtures/v2.0.0-auth.postman_collection.json',
expectedPath: './fixtures/v2.0.0-auth.postman_collection.result.json',
label: 'v2.0.0 auth'
},
{
inputPath: './fixtures/trailing-slash.postman_collection.json',
expectedPath:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"info": {
"name": "Auth",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "users",
"item": [
{
"name": "Users",
"request": {
"auth": {
"type": "bearer",
"bearer": {
"token": "token-value"
}
},
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": "{{baseUrl}}/users"
},
"response": [
{
"name": "Success",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer <token>",
"description": "Added as a part of security scheme: bearer"
}
],
"url": "{{baseUrl}}/user"
},
"status": "OK",
"code": 200,
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [],
"body": "{\n \"username\": \"<string>\",\n \"name\": \"<string>\" \n}"
}
]
}
]
}
],
"variable": [
{
"key": "baseUrl",
"value": "https://example.com/api/v1"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"bodySize": -1,
"cookies": [],
"headers": [
{
"name": "Accept",
"value": "application/json"
},
{
"name": "authorization",
"value": "Bearer token-value"
}
],
"headersSize": -1,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [],
"url": "https://example.com/api/v1/users"
}
]

0 comments on commit 5cc3237

Please sign in to comment.