mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-23 20:55:41 +00:00
fix: correctly parse insomnia exported yaml (#7966)
This commit is contained in:
@@ -23,7 +23,7 @@ const convertFileToObject = async (file) => {
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
const parsed = jsyaml.load(text);
|
||||
const parsed = jsyaml.load(text, { schema: jsyaml.JSON_SCHEMA });
|
||||
if (typeof parsed !== 'object' || parsed === null) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ export const fetchAndValidateApiSpecFromUrl = ({ url }) => {
|
||||
ipcRenderer
|
||||
.invoke('renderer:fetch-api-spec', url)
|
||||
.then(async (res) => {
|
||||
const data = await jsyaml.load(res);
|
||||
const data = await jsyaml.load(res, { schema: jsyaml.JSON_SCHEMA });
|
||||
const specType = getCollectionSpecType(data);
|
||||
resolve({ data, specType, rawContent: res });
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ const addSuffixToDuplicateName = (item, index, allItems) => {
|
||||
const regexVariable = new RegExp('{{.*?}}', 'g');
|
||||
|
||||
const normalizeVariables = (value) => {
|
||||
value = value || '';
|
||||
value = String(value ?? '');
|
||||
const variables = value.match(regexVariable) || [];
|
||||
each(variables, (variable) => {
|
||||
value = value.replace(variable, variable.replace('_.', '').replaceAll(' ', ''));
|
||||
|
||||
52
tests/import/insomnia/fixtures/insomnia-v5-dates.yaml
Normal file
52
tests/import/insomnia/fixtures/insomnia-v5-dates.yaml
Normal file
@@ -0,0 +1,52 @@
|
||||
type: collection.insomnia.rest/5.0
|
||||
schema_version: "5.1"
|
||||
name: Date Type Test
|
||||
meta:
|
||||
id: wrk_date_test
|
||||
created: 1776845227518
|
||||
modified: 1776845227518
|
||||
collection:
|
||||
- url: http://example.com/test
|
||||
name: Date Request
|
||||
meta:
|
||||
id: req_date_test_001
|
||||
created: 1776845260825
|
||||
modified: 1778146479401
|
||||
isPrivate: false
|
||||
sortKey: -1776845260825
|
||||
method: GET
|
||||
parameters:
|
||||
- name: date
|
||||
value: 2024-01-01
|
||||
disabled: false
|
||||
- name: is_active
|
||||
value: "false"
|
||||
disabled: false
|
||||
- name: limit
|
||||
value: "0"
|
||||
disabled: false
|
||||
- name: version
|
||||
value: "2.0"
|
||||
disabled: false
|
||||
- name: count
|
||||
value: 42
|
||||
disabled: false
|
||||
settings:
|
||||
renderRequestBody: true
|
||||
encodeUrl: true
|
||||
followRedirects: global
|
||||
cookies:
|
||||
send: true
|
||||
store: true
|
||||
rebuildPath: true
|
||||
environments:
|
||||
name: Base
|
||||
meta:
|
||||
id: env_date_test_001
|
||||
created: 1776845235974
|
||||
modified: 1776845235974
|
||||
isPrivate: false
|
||||
data:
|
||||
expiry_date: 2024-12-31
|
||||
max_retries: "3"
|
||||
enabled: "true"
|
||||
56
tests/import/insomnia/import-insomnia-v5-date-types.spec.ts
Normal file
56
tests/import/insomnia/import-insomnia-v5-date-types.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { test, expect } from '../../../playwright';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { closeAllCollections, importCollection } from '../../utils/page';
|
||||
|
||||
test.describe('Import Insomnia Collection - date types preserved', () => {
|
||||
test.afterEach(async ({ page }) => {
|
||||
await closeAllCollections(page);
|
||||
});
|
||||
|
||||
test('should keep date-like strings and quoted values intact through the full FileTab.js import flow', async ({
|
||||
page,
|
||||
createTmpDir
|
||||
}) => {
|
||||
const insomniaFile = path.resolve(__dirname, 'fixtures', 'insomnia-v5-dates.yaml');
|
||||
const collectionName = 'Date Type Test';
|
||||
const collectionDir = await createTmpDir('insomnia-dates-test');
|
||||
|
||||
await importCollection(page, insomniaFile, collectionDir, {
|
||||
expectedCollectionName: collectionName
|
||||
});
|
||||
|
||||
const requestFilePath = path.join(collectionDir, collectionName, 'Date Request.yml');
|
||||
const yamlContent = fs.readFileSync(requestFilePath, 'utf8');
|
||||
|
||||
expect(yamlContent).toContain(` params:
|
||||
- name: date
|
||||
value: 2024-01-01
|
||||
type: query
|
||||
- name: is_active
|
||||
value: "false"
|
||||
type: query
|
||||
- name: limit
|
||||
value: "0"
|
||||
type: query
|
||||
- name: version
|
||||
value: "2.0"
|
||||
type: query
|
||||
- name: count
|
||||
value: "42"
|
||||
type: query
|
||||
`);
|
||||
|
||||
const envFilePath = path.join(collectionDir, collectionName, 'environments', 'Base.yml');
|
||||
const envContent = fs.readFileSync(envFilePath, 'utf8');
|
||||
|
||||
expect(envContent).toContain(`variables:
|
||||
- name: expiry_date
|
||||
value: 2024-12-31
|
||||
- name: max_retries
|
||||
value: "3"
|
||||
- name: enabled
|
||||
value: "true"
|
||||
`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user