Skip to content

fix: compare included files with path semantics - #639

Draft
vortsghost2025 wants to merge 2 commits into
YousefED:masterfrom
vortsghost2025:fix/windows-wildcard-path-comparison
Draft

vortsghost2025 wants to merge 2 commits into
YousefED:masterfrom
vortsghost2025:fix/windows-wildcard-path-comparison

Conversation

@vortsghost2025

Copy link
Copy Markdown

Fixes #638.

Problem

On Windows, wildcard ("*") schema generation can silently return an empty definitions object when glob and TypeScript represent the same source path with different separators.

Observed for the same file:

glob:       schema\draft\schema.ts
TypeScript: schema/draft/schema.ts

exact string equality: false
pathEqual:             true

buildGenerator() currently uses exact string membership, which can leave userSymbols empty even though named symbols remain available.

Fix

Use the existing pathEqual() helper:

- return onlyIncludeFiles.indexOf(file.fileName) >= 0;
+ return onlyIncludeFiles.some((f) => pathEqual(f, file.fileName));

The library already uses pathEqual() for a related comparison in getMainFileSymbols().

Regression test

Adds a focused test using opposite slash styles for the same source file and verifies that it is still classified as a user/main-file source.

No workflow or schema-tooling changes.

Windows validation

Validated while investigating modelcontextprotocol/modelcontextprotocol#3114 with typescript-json-schema 0.68.0.

Fresh Windows generation after this one-line fix produced:

2024-11-05     79 definitions
2025-03-26     83 definitions
2025-06-18     91 definitions
2025-11-25    145 definitions
2026-07-28    155 definitions
draft         155 definitions

The regenerated schema files had no diff from the checked-in schemas.

Example validation:

Results: 258 passed, 0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wildcard generation can return empty schemas on Windows due to path comparison

1 participant