Skip to content

Commit 31d7ade

Browse files
committed
incorporate common parameters defined for each path and for all operations
1 parent 00ea713 commit 31d7ade

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

packages/flowtest-electron/src/utils/collection.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ const parseOpenAPISpec = (collection) => {
2828
try {
2929
// servers is array,, figure case where there can be multiple servers
3030
const baseUrl = collection['servers'][0]['url'];
31-
Object.entries(collection['paths']).map(([path, operation], _) => {
32-
Object.entries(operation).map(([requestType, request], _) => {
31+
Object.entries(collection['paths']).map(([path, operations], _) => {
32+
const commonParameters = Object.prototype.hasOwnProperty.call(operations, 'parameters')
33+
? operations['parameters']
34+
: [];
35+
const { parameters, ...operationsFiltered } = operations;
36+
Object.entries(operationsFiltered).map(([requestType, request], _) => {
3337
const summary = request['summary'];
3438
const operationId = request['operationId'];
3539
const tags = request['tags'];
@@ -39,9 +43,29 @@ const parseOpenAPISpec = (collection) => {
3943
const pathParameters = [];
4044
const queryParameters = [];
4145

46+
const requestParameters = commonParameters.map((obj) => {
47+
if (request['parameters']) {
48+
// Find the object in the second array that has the same id as the current object
49+
const objFromArr2 = request['parameters'].find((o) => o.name === obj.name && o.in === obj.in);
50+
// If found, merge the two objects, otherwise return the original object
51+
return objFromArr2 ? { ...obj, ...objFromArr2 } : obj;
52+
} else {
53+
return obj;
54+
}
55+
});
56+
4257
if (request['parameters']) {
58+
// Add any objects from the second array that do not exist in the first array
59+
request['parameters'].forEach((obj) => {
60+
if (!commonParameters.some((o) => o.name === obj.name && o.in === obj.in)) {
61+
requestParameters.push(obj);
62+
}
63+
});
64+
}
65+
66+
if (requestParameters.length > 0) {
4367
let firstQueryParam = true;
44-
request['parameters'].map((value, _) => {
68+
requestParameters.map((value, _) => {
4569
if (value['in'] === 'query') {
4670
if (firstQueryParam) {
4771
url = url.concat(`?${value['name']}={{${value['name']}}}`);

src/components/molecules/flow/utils.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { isEqual, reduce, map } from 'lodash';
2+
import requestNodes from './constants/requestNodes';
23

34
export const orderNodesByTags = (nodes, filter) => {
45
const result = {};
5-
let filterNodes = nodes;
6+
let filterNodes = nodes.filter(
7+
(node) => node.requestType && requestNodes.map((req) => req.requestType).includes(node.requestType),
8+
);
69
if (filter.trim() != '') {
710
filterNodes = nodes.filter(
811
(n) =>
9-
n.operationId.toLowerCase().includes(filter.toLowerCase()) ||
10-
n.description.toLowerCase().includes(filter.toLowerCase()),
12+
(n.operationId && n.operationId.toLowerCase().includes(filter.toLowerCase())) ||
13+
(n.description && n.description.toLowerCase().includes(filter.toLowerCase())),
1114
);
1215
}
1316
if (filterNodes) {
@@ -20,10 +23,10 @@ export const orderNodesByTags = (nodes, filter) => {
2023
result[tag].push(node);
2124
});
2225
} else {
23-
if (!result['All']) {
24-
result['All'] = [];
26+
if (!result['no_tag']) {
27+
result['no_tag'] = [];
2528
}
26-
result['All'].push(node);
29+
result['no_tag'].push(node);
2730
}
2831
});
2932
}

src/components/molecules/modals/OpenCollectionModal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const OpenCollectionModal = ({ closeFn = () => null, open = false }) => {
9999
<div className='mt-4'>
100100
<ul className='text-lg font-medium'>
101101
<li
102-
className={`hover:bg-background-light cursor-pointer rounded border border-transparent px-2 py-4 ${selectedFilePath ? 'text-green-500' : ''}`}
102+
className={`cursor-pointer rounded border border-transparent px-2 py-4 hover:bg-background-light ${selectedFilePath ? 'text-green-500' : ''}`}
103103
onClick={handleImportCollectionClick}
104104
data-import-type='yaml'
105105
>
@@ -117,7 +117,7 @@ const OpenCollectionModal = ({ closeFn = () => null, open = false }) => {
117117
<input
118118
type='file'
119119
id='file'
120-
accept='.yaml,.yml'
120+
accept='.yaml,.yml,.json'
121121
ref={importYamlFile}
122122
onChange={handleFileSelection}
123123
/>
@@ -134,7 +134,7 @@ const OpenCollectionModal = ({ closeFn = () => null, open = false }) => {
134134
)}
135135
</li>
136136
<li
137-
className={`hover:bg-background-light flex cursor-pointer items-center justify-start gap-4 px-2 py-4 ${selectedFilePath ? 'cursor-default' : 'cursor-not-allowed'}`}
137+
className={`flex cursor-pointer items-center justify-start gap-4 px-2 py-4 hover:bg-background-light ${selectedFilePath ? 'cursor-default' : 'cursor-not-allowed'}`}
138138
onClick={handleDirectorySelectionClick}
139139
>
140140
<div className='flex items-center justify-center w-8 h-8 border-4 rounded-full border-cyan-900'>

0 commit comments

Comments
 (0)