Skip to content

Commit 2d82f5d

Browse files
Merge branch 'master' into master
2 parents 969426e + 0379271 commit 2d82f5d

File tree

15 files changed

+775
-668
lines changed

15 files changed

+775
-668
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import { removeRequestBodyFromGetOperations } from './ExportOpenAPI';
2+
3+
// We're only testing the removeRequestBodyFromGetOperations function directly
4+
// No need to mock React components or hooks
5+
6+
describe('removeRequestBodyFromGetOperations', () => {
7+
it('should remove requestBody from GET operations', () => {
8+
// Create a test OpenAPI spec with a GET operation that has a requestBody
9+
const testSpec = {
10+
paths: {
11+
'/api/test': {
12+
get: {
13+
summary: 'Test GET',
14+
parameters: [
15+
{
16+
in: 'query',
17+
name: 'name',
18+
schema: {
19+
type: 'string',
20+
},
21+
},
22+
],
23+
requestBody: {
24+
content: {
25+
'application/json': {
26+
schema: {
27+
properties: {
28+
name: {
29+
type: 'string',
30+
},
31+
},
32+
},
33+
},
34+
},
35+
},
36+
responses: {
37+
'200': {
38+
description: 'OK',
39+
},
40+
},
41+
},
42+
},
43+
},
44+
};
45+
46+
// Process the spec
47+
const processedSpec = removeRequestBodyFromGetOperations(testSpec);
48+
49+
// Verify that the requestBody was removed from the GET operation
50+
expect(processedSpec.paths['/api/test'].get.requestBody).toBeUndefined();
51+
52+
// Verify that other properties were preserved
53+
expect(processedSpec.paths['/api/test'].get.summary).toBe('Test GET');
54+
expect(processedSpec.paths['/api/test'].get.parameters).toEqual([
55+
{
56+
in: 'query',
57+
name: 'name',
58+
schema: {
59+
type: 'string',
60+
},
61+
},
62+
]);
63+
});
64+
65+
it('should not modify POST operations with requestBody', () => {
66+
// Create a test OpenAPI spec with a POST operation that has a requestBody
67+
const testSpec = {
68+
paths: {
69+
'/api/test': {
70+
post: {
71+
summary: 'Test POST',
72+
requestBody: {
73+
content: {
74+
'application/json': {
75+
schema: {
76+
properties: {
77+
name: {
78+
type: 'string',
79+
},
80+
},
81+
},
82+
},
83+
},
84+
},
85+
responses: {
86+
'200': {
87+
description: 'OK',
88+
},
89+
},
90+
},
91+
},
92+
},
93+
};
94+
95+
// Process the spec
96+
const processedSpec = removeRequestBodyFromGetOperations(testSpec);
97+
98+
// Verify that the requestBody was preserved in the POST operation
99+
expect(processedSpec.paths['/api/test'].post.requestBody).toEqual(
100+
testSpec.paths['/api/test'].post.requestBody
101+
);
102+
});
103+
104+
it('should handle GET operations without requestBody', () => {
105+
// Create a test OpenAPI spec with a GET operation that doesn't have a requestBody
106+
const testSpec = {
107+
paths: {
108+
'/api/test': {
109+
get: {
110+
summary: 'Test GET',
111+
parameters: [
112+
{
113+
in: 'query',
114+
name: 'name',
115+
schema: {
116+
type: 'string',
117+
},
118+
},
119+
],
120+
responses: {
121+
'200': {
122+
description: 'OK',
123+
},
124+
},
125+
},
126+
},
127+
},
128+
};
129+
130+
// Process the spec
131+
const processedSpec = removeRequestBodyFromGetOperations(testSpec);
132+
133+
// Verify that the operation was not modified
134+
expect(processedSpec.paths['/api/test'].get).toEqual(
135+
testSpec.paths['/api/test'].get
136+
);
137+
});
138+
139+
it('should handle specs without paths', () => {
140+
// Create a test OpenAPI spec without paths
141+
const testSpec = {
142+
info: {
143+
title: 'Test API',
144+
version: '1.0.0',
145+
},
146+
};
147+
148+
// Process the spec
149+
const processedSpec = removeRequestBodyFromGetOperations(testSpec);
150+
151+
// Verify that the spec was not modified
152+
expect(processedSpec).toEqual(testSpec);
153+
});
154+
155+
it('should handle empty specs', () => {
156+
// Create an empty test OpenAPI spec
157+
const testSpec = {};
158+
159+
// Process the spec
160+
const processedSpec = removeRequestBodyFromGetOperations(testSpec);
161+
162+
// Verify that the spec was not modified
163+
expect(processedSpec).toEqual(testSpec);
164+
});
165+
});

frontend/libs/console/legacy-ce/src/lib/components/Services/ApiExplorer/Rest/Form/ExportOpenAPI.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ import { Analytics } from '../../../../../features/Analytics';
88
import endpoints from '../../../../../Endpoints';
99
import { downloadObjectAsJsonFile } from '../../../../Common/utils/export.utils';
1010

11+
// Function to remove requestBody from GET operations in OpenAPI spec
12+
export const removeRequestBodyFromGetOperations = (openApiSpec: any) => {
13+
const modifiedSpec = JSON.parse(JSON.stringify(openApiSpec));
14+
15+
// Check if paths exist in the spec
16+
if (modifiedSpec.paths) {
17+
// Iterate through all paths
18+
Object.entries(modifiedSpec.paths).forEach(
19+
([_path, pathItem]: [string, any]) => {
20+
// Check if there's a GET operation with requestBody
21+
if (pathItem.get && pathItem.get.requestBody) {
22+
// Remove the requestBody from GET operations
23+
delete pathItem.get.requestBody;
24+
}
25+
}
26+
);
27+
}
28+
29+
return modifiedSpec;
30+
};
31+
32+
// Export for testing
33+
export const __testExports = {
34+
removeRequestBodyFromGetOperations,
35+
};
36+
1137
const fetchData = async (httpClient: Axios) => {
1238
try {
1339
const response = await httpClient.get(endpoints?.exportOpenApi);
@@ -33,7 +59,11 @@ export const ExportOpenApiButton = () => {
3359
enabled: false,
3460
retry: 0,
3561
onSuccess: data => {
36-
downloadObjectAsJsonFile('OpenAPISpec.json', data);
62+
// Process the OpenAPI spec to remove requestBody from GET operations
63+
const processedData = removeRequestBodyFromGetOperations(data);
64+
65+
// Download the modified OpenAPI spec
66+
downloadObjectAsJsonFile('OpenAPISpec.json', processedData);
3767
hasuraToast({
3868
title: 'OpenApiSpec Exported Successfully!',
3969
type: 'success',

server/src-rsr/catalog_versions.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,7 @@ v2.45.3 48
240240
v2.47.0 48
241241
v2.36.11 48
242242
v2.36.12 48
243-
v2.48.0 48
243+
v2.48.0-beta.1 48
244244
v2.36.13 48
245+
v2.48.0 48
246+
v2.48.1 48

0 commit comments

Comments
 (0)