Skip to content

Commit eda96aa

Browse files
fix: removing the path if object is empty int the resulting spec (#208)
1 parent cb1e12c commit eda96aa

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/__tests__/__snapshots__/basic.test.ts.snap

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ exports[`basic > hide with a boolean value 1`] = `
6868
"version": "0.0.0",
6969
},
7070
"openapi": "3.1.0",
71-
"paths": {
72-
"/": {
73-
"get": undefined,
74-
},
75-
},
71+
"paths": {},
7672
"tags": undefined,
7773
}
7874
`;
@@ -86,11 +82,7 @@ exports[`basic > hide with a function 1`] = `
8682
"version": "0.0.0",
8783
},
8884
"openapi": "3.1.0",
89-
"paths": {
90-
"/": {
91-
"get": undefined,
92-
},
93-
},
85+
"paths": {},
9486
"tags": undefined,
9587
}
9688
`;

src/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,18 @@ export function removeExcludedPaths(
298298
}
299299
}
300300

301-
newPaths[key] = value;
301+
// Build filtered value with only non-null methods
302+
const filteredValue: OpenAPIV3_1.PathItemObject = {};
303+
for (const method of Object.keys(value)) {
304+
if (value[method] != null) {
305+
filteredValue[method] = value[method];
306+
}
307+
}
308+
309+
// Only add path if it has at least one valid method
310+
if (Object.keys(filteredValue).length > 0) {
311+
newPaths[key] = filteredValue;
312+
}
302313
}
303314

304315
return newPaths;

0 commit comments

Comments
 (0)