Dev Toolsv0.1.7
@tekir/swagger
OpenAPI 3.0 spec builder and Swagger UI.
Installation
$
bun add @tekir/swaggerFeatures
- Auto-generates OpenAPI 3.0 spec from routes
- Built-in Swagger UI served at configurable path
- Optional HTTP Basic auth gating
- Route decorators: @ApiTag, @ApiBody, @ApiResponse, @ApiParam
- Zod-to-JSON-Schema conversion via zodToJsonSchema()
- SwaggerProvider for automatic setup
Quick Example
TypeScript
import { swagger } from '@tekir/swagger'
swagger(router, {
title: 'My API',
version: '1.0.0',
path: '/docs',
auth: { username: 'admin', password: process.env.DOCS_PASSWORD! },
})Changelog
v0.1.7LatestSeptember 16, 2026
- OpenAPI route collection now includes domain-constrained handlers.
- Published output now uses the shared Node-targeted ESM bundle pipeline with external dependencies and generated TypeScript declarations, while Bun consumers keep the native source export.
v0.1.6July 31, 2026
ApiParamOptions.schemaand fluentapiParam(..., { schema })now preserve complete OpenAPI parameter schemas, including enums, arrays, bounds, unions, and other JSON Schema keywords.- Legacy parameter options continue to emit
type,format,example, andenumcorrectly.
v0.1.5July 23, 2026
- Package metadata now follows the shared compatible
0.1.xdependency range used by the coordinated Tekir release.
v0.1.4June 13, 2026
- Swagger docs are now gated by environment by default. Under
NODE_ENV=productionwith noauthconfigured, the routes are not registered and a warning is logged. UseSwaggerConfig.enabledto force the docs on or off in either direction. - New
@ApiHide()decorator plusSwaggerConfig.hidePaths(string prefix or RegExp) let you keep internal routes out of the generated spec. - Found and fixed with Fable.
v0.1.3May 17, 2026
- Swagger UI assets now load from a pinned
[email protected]URL with optional Subresource Integrity. The newui.cssUrl,ui.jsUrl,ui.cssIntegrity, andui.jsIntegrityconfig keys let apps self-host the bundle or pin SRI hashes that the browser enforces before executing the CDN payload. - The
/docsHTML response now ships a strictContent-Security-Policywith nounsafe-inline. The only inline bootstrap is allowlisted via its SHA-256 hash, so any injected<script>is refused by the browser. The response also carriesX-Frame-Options: DENY,X-Content-Type-Options: nosniff, andReferrer-Policy: no-referrer. jsonPathis now embedded into the bootstrap viaJSON.stringify(...)plus</scriptescaping, so a customconfig.pathcannot break out of the inline script context.- Basic auth credential comparison now hashes both sides to fixed-length HMAC digests before
timingSafeEqual(). Earlier releases short-circuited on length mismatch, which leaked the password length to attackers timing the response. Theauthconfig surface is unchanged.
v0.1.2May 8, 2026
@ApiParamaccepts anenumfield on its options, matching the OpenAPI parameter spec:@ApiParam('status', { type: 'string', enum: ['active', 'inactive'] })now type-checks and propagates into the generated spec.buildOpenApiSpec(router, config)acceptsnull/undefinedfor the router argument. The runtime path already returned an emptypathsobject for falsy routers; the signature now matches the documented behaviour.RouterLike.getis optional. Spec-only consumers (a plain trie wrapper, a test fixture, a CI script generating JSON) can satisfy the interface without supplying a handler-registration method;swagger()still requires it for live UI wiring.
v0.1.1April 29, 2026
- Optional HTTP Basic auth on the Swagger UI and JSON spec. Pass
auth: { username, password, realm? }to gate/docs,/docs/, and/docs/json. Constant-time credential comparison; sends a 401 withWWW-Authenticate: Basic realm="docs"when credentials are missing or wrong.
v0.1.0April 1, 2026
- Initial release