OpenAPI Documentation
Automatic OpenAPI 3.0 specification generation from Zod schemas with interactive Swagger UI documentation.
Automatic Generation
OpenAPI specs generated automatically from Zod schemas
Interactive UI
Built-in Swagger UI with Try It Out functionality
Type Safety
Full TypeScript inference from schemas to docs
Standards Compliant
OpenAPI 3.0 specification with JSON/YAML export
Quick Start
Enable OpenAPI Documentation
typescript
That's it!
MoroJS automatically generates OpenAPI specs from your Zod schemas and route definitions. No manual configuration needed.
Configuration Options
Full Configuration Example
typescript
Route Documentation Methods
Adding Descriptions and Tags
typescript
Automatic Schema Documentation
typescript
Query Parameters Documentation
typescript
Path Parameters Documentation
typescript
Headers Documentation
typescript
Accessing Documentation
Interactive UI
Swagger UI at /docs
JSON Export
OpenAPI JSON spec
YAML Export
OpenAPI YAML spec
Programmatic Access to OpenAPI Spec
typescript
Available Methods
app.getOpenAPISpec()Returns the OpenAPI specification as a JavaScript object
app.getDocsJSON()Returns the OpenAPI specification as a JSON string
app.getDocsYAML()Returns the OpenAPI specification as a YAML string
Complete Example
Full API with Automatic Documentation
typescript
Advanced Features
Schema-First Route Definition
typescript
Complex Nested Schemas
typescript
Authentication Documentation
typescript
Rate Limiting and Caching in Docs
typescript
Best Practices
Add Descriptions
Use .describe() on all routes to make your API self-documenting
Use Tags
Group related endpoints with .tag() for better organization
Include Examples
Enable includeExamples: true for better developer experience
Document Auth
Use .auth() to automatically document security requirements
Multiple Servers
Configure servers array to help users understand different environments
Version Your API
Use semantic versioning in the version field
Installation
OpenAPI documentation requires the swagger-ui-dist package:
Install Dependencies
typescript
The swagger-ui-dist dependency is optional and only needed if you want to enable interactive documentation.