OpraHttpModule
NestJS dynamic module that wires OPRA's HTTP adapter into a NestJS application. Registers OPRA controllers as NestJS controllers, sets up middleware for context creation, and applies the exception filter.
import { OpraHttpModule } from '@opra/nestjs-http';
forRoot(options)
Synchronous registration. Call from your root AppModule:
import { Module } from '@nestjs/common';
import { OpraHttpModule } from '@opra/nestjs-http';
import { Customer } from './models/customer.js';
import { CustomersController } from './controllers/customers.controller.js';
@Module({
imports: [
OpraHttpModule.forRoot({
name: 'MyApi',
basePath: '/api',
types: [Customer],
controllers: [CustomersController],
}),
],
})
export class AppModule {}
Options (OpraHttpModule.ModuleOptions)
| Option | Type | Description |
|---|---|---|
name | string | API name included in the generated schema. |
description | string | Optional API description. |
basePath | string | URL prefix for all OPRA routes. |
scope | string | Validation scope applied to every request and response. |
types | Type[] | Data types to register on the ApiDocument. |
references | object | Type references from other documents. |
info | object | API info metadata (version, contact, license…). |
controllers | Type[] | NestJS / OPRA controller classes. |
providers | Provider[] | Additional NestJS providers. |
exports | any[] | Providers to export from the module. |
imports | any[] | Modules to import. |
global | boolean | Register the module globally. |
token | any | Custom injection token for the module. |
schemaIsPublic | boolean | Expose the $schema endpoint without authentication. |
interceptors | (InterceptorFunction | IHttpInterceptor | Type<IHttpInterceptor>)[] | Interceptors applied to every request. |
logger | Logger | Custom NestJS logger instance. |
forRootAsync(options)
Asynchronous registration — use when configuration depends on injected providers (e.g. ConfigService):
import { ConfigModule, ConfigService } from '@nestjs/config';
OpraHttpModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
name: 'MyApi',
basePath: config.get('API_BASE_PATH'),
types: [Customer],
controllers: [CustomersController],
}),
})
Options (OpraHttpModule.AsyncModuleOptions)
Extends BaseModuleOptions (all non-API fields from ModuleOptions) and adds:
| Option | Type | Description |
|---|---|---|
inject | any[] | Providers to inject into useFactory. |
useFactory | (...args) => ApiConfig | Promise<ApiConfig> | Factory that returns the API configuration. |