Skip to content

fix: use TypeScript compiler API for interface parsing in swagger.ts#35

Merged
Many0nne merged 1 commit into
mainfrom
fix/issue-24-swagger-ast-parsing
Mar 13, 2026
Merged

fix: use TypeScript compiler API for interface parsing in swagger.ts#35
Many0nne merged 1 commit into
mainfrom
fix/issue-24-swagger-ast-parsing

Conversation

@Many0nne
Copy link
Copy Markdown
Owner

Summary

  • Replace the regex-based extractInterfaceProperties() with AST traversal using ts.createSourceFile() and ts.forEachChild()
  • Exact interface name matching (no regex injection risk)
  • Correctly handles readonly properties, optional fields (?), nested objects ({ foo: string }), and generic types (Record<string, string>)
  • Extend typeToOpenAPISchema() to map generic types (containing <) to { type: 'object' }

Test plan

  • All 171 existing tests pass
  • Swagger spec generation works correctly for standard interfaces

Closes #24

🤖 Generated with Claude Code

Replace the fragile regex-based extractInterfaceProperties() with a proper
AST traversal using ts.createSourceFile() and ts.forEachChild(). This correctly
handles readonly properties, optional fields, nested object types, and generics
like Record<K,V>. Also extends typeToOpenAPISchema() to map generic types to
{ type: 'object' }.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Many0nne Many0nne merged commit af54300 into main Mar 13, 2026
2 checks passed
@Many0nne Many0nne deleted the fix/issue-24-swagger-ast-parsing branch March 13, 2026 21:33
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.

Enhancement: replace regex-based interface parsing in swagger.ts with TypeScript compiler API

1 participant