forked from usebruno/bruno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: import openapi -- baseUrl env value should not include trailing …
…slash (usebruno#3440) * fix: openapi baseUrl env value should remove trailing slash * feat: updates
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
rootDir: '.', | ||
moduleNameMapper: { | ||
'^assets/(.*)$': '<rootDir>/src/assets/$1', | ||
'^components/(.*)$': '<rootDir>/src/components/$1', | ||
'^hooks/(.*)$': '<rootDir>/src/hooks/$1', | ||
'^themes/(.*)$': '<rootDir>/src/themes/$1', | ||
'^api/(.*)$': '<rootDir>/src/api/$1', | ||
'^pageComponents/(.*)$': '<rootDir>/src/pageComponents/$1', | ||
'^providers/(.*)$': '<rootDir>/src/providers/$1', | ||
'^utils/(.*)$': '<rootDir>/src/utils/$1' | ||
}, | ||
clearMocks: true, | ||
moduleDirectories: ['node_modules', 'src'], | ||
testEnvironment: 'node' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/bruno-app/src/utils/importers/openapi-collection.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { parseOpenApiCollection } from './openapi-collection'; | ||
import { uuid } from 'utils/common'; | ||
|
||
jest.mock('utils/common'); | ||
|
||
describe('openapi importer util functions', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('should convert openapi object to bruno collection correctly', async () => { | ||
const input = { | ||
openapi: '3.0.3', | ||
info: { | ||
title: 'Sample API with Multiple Servers', | ||
description: 'API spec with multiple servers.', | ||
version: '1.0.0' | ||
}, | ||
servers: [ | ||
{ url: 'https://api.example.com/v1', description: 'Production Server' }, | ||
{ url: 'https://staging-api.example.com/v1', description: 'Staging Server' }, | ||
{ url: 'http://localhost:3000/v1', description: 'Local Server' } | ||
], | ||
paths: { | ||
'/users': { | ||
get: { | ||
summary: 'Get a list of users', | ||
parameters: [ | ||
{ name: 'page', in: 'query', required: false, schema: { type: 'integer' } }, | ||
{ name: 'limit', in: 'query', required: false, schema: { type: 'integer' } } | ||
], | ||
responses: { | ||
'200': { description: 'A list of users' } | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const expectedOutput = { | ||
name: 'Sample API with Multiple Servers', | ||
version: '1', | ||
items: [ | ||
{ | ||
name: 'Get a list of users', | ||
type: 'http-request', | ||
request: { | ||
url: '{{baseUrl}}/users', | ||
method: 'GET', | ||
params: [ | ||
{ name: 'page', value: '', enabled: false, type: 'query' }, | ||
{ name: 'limit', value: '', enabled: false, type: 'query' } | ||
] | ||
} | ||
} | ||
], | ||
environments: [ | ||
{ name: 'Production Server', variables: [{ name: 'baseUrl', value: 'https://api.example.com/v1' }] }, | ||
{ name: 'Staging Server', variables: [{ name: 'baseUrl', value: 'https://staging-api.example.com/v1' }] }, | ||
{ name: 'Local Server', variables: [{ name: 'baseUrl', value: 'http://localhost:3000/v1' }] } | ||
] | ||
}; | ||
|
||
const result = await parseOpenApiCollection(input); | ||
|
||
expect(result).toMatchObject(expectedOutput); | ||
expect(uuid).toHaveBeenCalledTimes(10); | ||
}); | ||
}); |