From 2b5c3708a22fb33e4ab20b0f062f2e5b14246704 Mon Sep 17 00:00:00 2001 From: mathuraditya724 Date: Wed, 7 Jan 2026 12:18:35 +0530 Subject: [PATCH] fix: removing the path if object is empty int the resulting spec --- src/__tests__/__snapshots__/basic.test.ts.snap | 12 ++---------- src/utils.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/__tests__/__snapshots__/basic.test.ts.snap b/src/__tests__/__snapshots__/basic.test.ts.snap index 4ba17cf..0ef9e68 100644 --- a/src/__tests__/__snapshots__/basic.test.ts.snap +++ b/src/__tests__/__snapshots__/basic.test.ts.snap @@ -68,11 +68,7 @@ exports[`basic > hide with a boolean value 1`] = ` "version": "0.0.0", }, "openapi": "3.1.0", - "paths": { - "/": { - "get": undefined, - }, - }, + "paths": {}, "tags": undefined, } `; @@ -86,11 +82,7 @@ exports[`basic > hide with a function 1`] = ` "version": "0.0.0", }, "openapi": "3.1.0", - "paths": { - "/": { - "get": undefined, - }, - }, + "paths": {}, "tags": undefined, } `; diff --git a/src/utils.ts b/src/utils.ts index ca2bd86..568f097 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -298,7 +298,18 @@ export function removeExcludedPaths( } } - newPaths[key] = value; + // Build filtered value with only non-null methods + const filteredValue: OpenAPIV3_1.PathItemObject = {}; + for (const method of Object.keys(value)) { + if (value[method] != null) { + filteredValue[method] = value[method]; + } + } + + // Only add path if it has at least one valid method + if (Object.keys(filteredValue).length > 0) { + newPaths[key] = filteredValue; + } } return newPaths;