Skip to content

Commit d4ea883

Browse files
braden-wBraden Wong
andauthored
fix(excludeStaticFile): check period in last segment only, not entire path (#197)
* fix(excludeStaticFile): check period in last segment only, not entire path The previous implementation excluded any path containing a period anywhere, which incorrectly filtered out legitimate API routes like /my.workspace/action or /api.v2/users. Changes: - Check only the final path segment for periods to identify static files - Rename isStaticFileExcluded to shouldIncludePath for clarity - Add inline comments explaining each condition in the logic - Update JSDoc to clarify the detection mechanism This correctly distinguishes between static files (/style.css) and API routes with periods in earlier segments (/my.workspace/action). * docs: clarify comment to describe exclusion condition rather than result --------- Co-authored-by: Braden Wong <git@bradenwong.com>
1 parent e20762e commit d4ea883

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type GenerateSpecOptions = {
4444
includeEmptyPaths: boolean;
4545

4646
/**
47-
* Determine if Swagger should exclude static files.
47+
* Determine if Swagger should exclude static files (by checking if the last path segment contains a period).
4848
*
4949
* @default true
5050
*/

src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ export function removeExcludedPaths(
213213
return x.test(key);
214214
});
215215

216-
// If excludeStaticFile is true, we want to exclude static files
217-
const isStaticFileExcluded = excludeStaticFile
218-
? !key.includes(".") || key.includes("{")
219-
: true;
216+
const shouldIncludePath =
217+
!excludeStaticFile || // Include all paths when static file filtering is disabled
218+
key.includes("{") || // Always include paths with parameters (e.g., /users/{id}.json)
219+
!key.split("/").pop()?.includes("."); // Exclude if last segment has a period (e.g., /style.css)
220220

221221
if (
222222
isPathExcluded &&
223223
!(key.includes("*") && !key.includes("{")) &&
224-
isStaticFileExcluded &&
224+
shouldIncludePath &&
225225
value != null
226226
) {
227227
for (const method of Object.keys(value)) {

0 commit comments

Comments
 (0)