Skip to content

feat: enable tree-shaking by moving provider dispatch to factory pattern#7

Merged
akfaiz merged 3 commits intomainfrom
feat/tree-shaking-providers
Apr 5, 2026
Merged

feat: enable tree-shaking by moving provider dispatch to factory pattern#7
akfaiz merged 3 commits intomainfrom
feat/tree-shaking-providers

Conversation

@akfaiz
Copy link
Copy Markdown
Member

@akfaiz akfaiz commented Apr 5, 2026

Replace the switch statement in handler.go (which forced all 5 UI providers into every binary) with a DocsHandlerFactory field set by each With option. The Go linker now eliminates any provider whose option is never called, reducing binary size to only the provider(s) in use.

  • Remove default StoplightElements provider; callers must now explicitly specify a provider via WithSwaggerUI, WithStoplightElements, etc.
  • Cache the docs handler with sync.Once so template parsing happens once
  • Simplify DocsFunc to resolve the handler at registration time

Replace the switch statement in handler.go (which forced all 5 UI
providers into every binary) with a DocsHandlerFactory field set by
each With<Provider> option. The Go linker now eliminates any provider
whose option is never called, reducing binary size to only the
provider(s) in use.

- Remove default StoplightElements provider; callers must now explicitly
  specify a provider via WithSwaggerUI, WithStoplightElements, etc.
- Cache the docs handler with sync.Once so template parsing happens once
- Simplify DocsFunc to resolve the handler at registration time
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
handler.go 71.42% 1 Missing and 1 partial ⚠️
internal/scalar/index.tpl.go 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@akfaiz akfaiz merged commit 71f6d67 into main Apr 5, 2026
8 of 9 checks passed
@akfaiz akfaiz deleted the feat/tree-shaking-providers branch April 5, 2026 03:18
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.

1 participant