Skip to content

Commit 42bda02

Browse files
authored
fix(Sync): Do not show conflicts for empty keys (#7556)
* Remove keys that have empty values and can be undefined in a model * only scripts can be undefined for now * New fields are now initialized as undefined * update tests
1 parent cd3a355 commit 42bda02

9 files changed

Lines changed: 32 additions & 31 deletions

File tree

packages/insomnia/src/common/__tests__/export.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('export', () => {
268268
const exportWorkspacesDataJson = JSON.parse(exportedWorkspacesJson);
269269
const exportWorkspacesDataYaml = YAML.parse(exportedWorkspacesYaml);
270270
// Ensure JSON is the same as YAML
271-
expect(exportWorkspacesDataJson.resources).toEqual(exportWorkspacesDataYaml.resources);
271+
expect(exportWorkspacesDataYaml.resources).toMatchObject(exportWorkspacesDataJson.resources);
272272
expect(exportWorkspacesDataJson).toMatchObject({
273273
_type: 'export',
274274
__export_format: 4,

packages/insomnia/src/common/export.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,11 @@ export async function exportRequestsData(
268268
return d;
269269
});
270270

271+
const stringifiedData = JSON.stringify(data);
271272
if (format.toLowerCase() === 'yaml') {
272-
return YAML.stringify(data);
273+
return YAML.stringify(JSON.parse(stringifiedData));
273274
} else if (format.toLowerCase() === 'json') {
274-
return JSON.stringify(data);
275+
return stringifiedData;
275276
} else {
276277
throw new Error(`Invalid export format ${format}. Must be "json" or "yaml"`);
277278
}

packages/insomnia/src/models/__tests__/request.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ describe('init()', () => {
2020
name: 'New Request',
2121
description: '',
2222
parameters: [],
23-
pathParameters: [],
24-
preRequestScript: '',
25-
afterResponseScript: '',
23+
pathParameters: undefined,
24+
preRequestScript: undefined,
25+
afterResponseScript: undefined,
2626
url: '',
2727
settingStoreCookies: true,
2828
settingSendCookies: true,
@@ -59,9 +59,9 @@ describe('create()', () => {
5959
method: 'GET',
6060
name: 'Test Request',
6161
parameters: [],
62-
pathParameters: [],
63-
preRequestScript: '',
64-
afterResponseScript: '',
62+
pathParameters: undefined,
63+
preRequestScript: undefined,
64+
afterResponseScript: undefined,
6565
url: '',
6666
settingStoreCookies: true,
6767
settingSendCookies: true,
@@ -394,9 +394,9 @@ describe('migrate()', () => {
394394
headers: [],
395395
authentication: {},
396396
parameters: [],
397-
pathParameters: [],
398-
preRequestScript: '',
399-
afterResponseScript: '',
397+
pathParameters: undefined,
398+
preRequestScript: undefined,
399+
afterResponseScript: undefined,
400400
parentId: null,
401401
body: {
402402
mimeType: '',

packages/insomnia/src/models/request-group.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ interface BaseRequestGroup {
1717
environment: Record<string, any>;
1818
environmentPropertyOrder: Record<string, any> | null;
1919
metaSortKey: number;
20-
preRequestScript: string;
21-
afterResponseScript: string;
20+
preRequestScript?: string;
21+
afterResponseScript?: string;
2222
authentication?: RequestAuthentication | {};
2323
headers?: RequestHeader[];
2424
}
@@ -36,10 +36,10 @@ export function init(): BaseRequestGroup {
3636
environment: {},
3737
environmentPropertyOrder: null,
3838
metaSortKey: -1 * Date.now(),
39-
preRequestScript: '',
40-
afterResponseScript: '',
41-
authentication: {},
42-
headers: [],
39+
preRequestScript: undefined,
40+
afterResponseScript: undefined,
41+
authentication: undefined,
42+
headers: undefined,
4343
};
4444
}
4545

packages/insomnia/src/models/request.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ export interface BaseRequest {
251251
description: string;
252252
method: string;
253253
body: RequestBody;
254-
preRequestScript: string;
255-
afterResponseScript: string;
254+
preRequestScript?: string;
255+
afterResponseScript?: string;
256256
parameters: RequestParameter[];
257-
pathParameters: RequestPathParameter[];
257+
pathParameters?: RequestPathParameter[];
258258
headers: RequestHeader[];
259259
authentication: RequestAuthentication | {};
260260
metaSortKey: number;
@@ -289,14 +289,14 @@ export function init(): BaseRequest {
289289
description: '',
290290
method: METHOD_GET,
291291
body: {},
292-
preRequestScript: '',
293-
afterResponseScript: '',
294292
parameters: [],
295293
headers: [],
296294
authentication: {},
295+
preRequestScript: undefined,
297296
metaSortKey: -1 * Date.now(),
298297
isPrivate: false,
299-
pathParameters: [],
298+
pathParameters: undefined,
299+
afterResponseScript: undefined,
300300
// Settings
301301
settingStoreCookies: true,
302302
settingSendCookies: true,

packages/insomnia/src/models/websocket-request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface BaseWebSocketRequest {
2020
headers: RequestHeader[];
2121
authentication: RequestAuthentication | {};
2222
parameters: RequestParameter[];
23-
pathParameters: RequestPathParameter[];
23+
pathParameters?: RequestPathParameter[];
2424
settingEncodeUrl: boolean;
2525
settingStoreCookies: boolean;
2626
settingSendCookies: boolean;
@@ -44,7 +44,7 @@ export const init = (): BaseWebSocketRequest => ({
4444
headers: [],
4545
authentication: {},
4646
parameters: [],
47-
pathParameters: [],
47+
pathParameters: undefined,
4848
settingEncodeUrl: true,
4949
settingStoreCookies: true,
5050
settingSendCookies: true,

packages/insomnia/src/plugins/context/__tests__/data.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ describe('app.export.*', () => {
195195
modified: 222,
196196
name: 'New Request',
197197
parameters: [],
198-
pathParameters: [],
199-
preRequestScript: '',
200-
afterResponseScript: '',
198+
pathParameters: undefined,
199+
preRequestScript: undefined,
200+
afterResponseScript: undefined,
201201
parentId: 'wrk_1',
202202
settingDisableRenderRequestBody: false,
203203
settingEncodeUrl: true,

packages/insomnia/src/ui/components/panes/request-pane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const RequestPane: FC<Props> = ({
8080
if (!activeRequest) {
8181
return <PlaceholderRequestPane />;
8282
}
83-
const pathParameters = getCombinedPathParametersFromUrl(activeRequest.url, activeRequest.pathParameters);
83+
const pathParameters = getCombinedPathParametersFromUrl(activeRequest.url, activeRequest.pathParameters || []);
8484

8585
const onPathParameterChange = (pathParameters: RequestParameter[]) => {
8686
patchRequest(requestId, { pathParameters });

packages/insomnia/src/ui/components/websockets/websocket-request-pane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export const WebSocketRequestPane: FC<Props> = ({ environment }) => {
227227
};
228228

229229
// Path parameters are path segments that start with a colon (:)
230-
const pathParameters = getCombinedPathParametersFromUrl(activeRequest.url, activeRequest.pathParameters);
230+
const pathParameters = getCombinedPathParametersFromUrl(activeRequest.url, activeRequest.pathParameters || []);
231231

232232
const onPathParameterChange = (pathParameters: RequestPathParameter[]) => {
233233
patchRequest(requestId, { pathParameters });

0 commit comments

Comments
 (0)