covenix / Covenix
Class: Covenix
Defined in: src/covenix.ts:718
Owns a set of controllers and wires them to Express and OpenAPI. Construct one instance, register your controllers, then mount an Express app and/or call swagger.
Example
const api = new Covenix({ info: { title: 'My API', version: '1.0.0' } });
api.register(new UsersController(db));
api.mount(app);
app.get('/swagger.json', (_req, res) => res.json(api.swagger()));Constructors
Constructor
new Covenix(
options):Covenix
Defined in: src/covenix.ts:726
Parameters
options
Instance options, including the OpenAPI info block.
Returns
Covenix
Accessors
info
Get Signature
get info():
InfoObject
Defined in: src/covenix.ts:729
The OpenAPI info block this instance was constructed with.
Returns
InfoObject
Methods
contract()
contract(
options?):object
Defined in: src/covenix.ts:815
Builds the high-fidelity CovenixContract (the codegen IR) from the registered controllers' metadata — the contract sibling of Covenix.swagger. Independent of Covenix.mount; serialize it to contract.json for a client generator.
Parameters
options?
ContractOptions = {}
Extra inputs, e.g. route-less schemas (named via .meta({ id })).
Returns
object
The validated contract document.
covenixContract
covenixContract:
"0.1"
info
info:
object
Index Signature
[key: string]: unknown
info.title
title:
string
info.version
version:
string
operations
operations:
object[]
schemas
schemas:
Record<string,SchemaNode>
group()
group(
prefix,fn):this
Defined in: src/covenix.ts:768
Registers a set of controllers under a shared base path — typically an API version segment. The callback receives a ControllerGroup scoped to prefix; groups nest. Reflected in both the routes and the generated spec.
Parameters
prefix
string
Base path for the group (e.g. '/v1').
fn
(group) => void
Receives the scoped group to register controllers on.
Returns
this
This instance, for chaining.
Example
api.group('/v1', (v1) => {
v1.register(new UsersController(svc));
v1.register(new AuthController(auth));
});mount()
mount(
app):this
Defined in: src/covenix.ts:862
Walks every registered controller's metadata and binds its routes (with validation middleware) onto the Express app.
Parameters
app
Express
The Express application to register routes on.
Returns
this
This instance, for chaining.
register()
register(
instance,options?):this
Defined in: src/covenix.ts:746
Records a pre-constructed controller instance. The caller owns construction and dependency injection; Covenix.mount does the wiring later.
Parameters
instance
object
A controller instance (not a class).
options?
RegisterOptions = {}
Registration options, e.g. a prefix base path.
Returns
this
This instance, for chaining.
serveDocs()
serveDocs(
app,path?,options?):this
Defined in: src/covenix.ts:843
Mounts a documentation UI (and the spec it renders) onto an Express app. The UI HTML is served at path and the spec at ${path}/openapi.json.
By default the assets are self-hosted from the chosen UI's package (an optional peer dependency: @scalar/api-reference for 'scalar', swagger-ui-dist for 'swagger-ui', redoc for 'redoc') — install the one you use, or pass { cdn: true } to load it from a CDN instead.
Parameters
app
Express
The Express application to mount onto.
path?
string = '/docs'
Mount path for the UI. Defaults to '/docs'.
options?
ServeDocsOptions = {}
UI choice, cdn, specVersion, title.
Returns
this
This instance, for chaining.
Example
api.serveDocs(app); // Scalar at /docs
api.serveDocs(app, '/docs', { ui: 'swagger-ui' });swagger()
swagger(
options?):OpenApiDocument
Defined in: src/covenix.ts:783
Builds the OpenAPI document from the registered controllers' metadata. Independent of Covenix.mount — does not require routes to be wired.
Parameters
options?
Generation options. specVersion defaults to '3.1'. schemas adds standalone (route-less) named schemas to components.schemas — pass the same list to generateSwagger to keep instance and static output identical.
schemas?
ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>[]
specVersion?
Returns
The assembled OpenAPI document.
