Skip to content

Commit

Permalink
fix(ui): Import > Postman v2 > path params not imported (fixes #293)
Browse files Browse the repository at this point in the history
  • Loading branch information
flawiddsouza committed Dec 26, 2024
1 parent 790c676 commit 4e2c28e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/ui/src/parsers/postman.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { convertPostmanExportToRestfoxCollection } from './postman'
import { addSortOrderToTree, flattenTree } from '@/helpers'

test('importPostmanV2.0', async() => {
const currentFolder = path.dirname(new URL(import.meta.url).pathname)
const currentFolder = process.cwd()

const testDataFolder = path.join(currentFolder, '..', '..', 'test-data', 'postman-import-v2')
const testDataFolder = path.resolve(path.join(currentFolder,'test-data', 'postman-import-v2'))

console.log('testDataFolder', testDataFolder)

const inputFile = await readFile(path.join(testDataFolder, 'Argos.API.postman_collection.v2.0.json'), 'utf-8')
const input = JSON.parse(inputFile)
Expand Down Expand Up @@ -49,9 +51,9 @@ test('importPostmanV2.0', async() => {
})

test('importPostmanV2.1', async() => {
const currentFolder = path.dirname(new URL(import.meta.url).pathname)
const currentFolder = process.cwd()

const testDataFolder = path.join(currentFolder, '..', '..', 'test-data', 'postman-import-v2')
const testDataFolder = path.join(currentFolder, 'test-data', 'postman-import-v2')

const inputFile = await readFile(path.join(testDataFolder, 'Argos.API.postman_collection.v2.1.json'), 'utf-8')
const input = JSON.parse(inputFile)
Expand Down
13 changes: 13 additions & 0 deletions packages/ui/src/parsers/postman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ function handlePostmanV2CollectionItem(postmanCollectionItem: any, parentId: str
})
})

const pathParameters: RequestParam[] = []

const pathParams = 'url' in request.request && typeof request.request.url !== 'string' && 'variable' in request.request.url ? request.request.url.variable : []
pathParams.forEach((pathParam: any) => {
pathParameters.push({
name: pathParam.key,
value: pathParam.value,
description: pathParam.description,
disabled: pathParam.disabled
})
})

let url = ''

if('url' in request.request) {
Expand Down Expand Up @@ -258,6 +270,7 @@ function handlePostmanV2CollectionItem(postmanCollectionItem: any, parentId: str
body,
headers,
parameters,
pathParameters: pathParameters.length > 0 ? pathParameters : undefined,
authentication,
description: 'description' in request.request ? request.request.description : undefined,
parentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
}
],
"parameters": [],
"pathParameters": [
{
"name": "buildId",
"value": "<string>",
"description": "(Required) A unique identifier for the build"
}
],
"authentication": {
"type": "No Auth"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/test-data/postman-import-v2/test-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@
}
],
"parameters": [],
"pathParameters": [
{
"name": "buildId",
"value": "<string>",
"description": "(Required) A unique identifier for the build"
}
],
"authentication": {
"type": "No Auth"
},
Expand Down

0 comments on commit 4e2c28e

Please sign in to comment.