nestjs-openapi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,896 @@
1
+ import { Effect, Context, Layer, Option } from 'effect';
2
+ import { C as ConfigNotFoundError, O as OpenApiGeneratorConfig, a as ConfigError, R as ResolvedConfig, P as ProjectError, b as ProjectInitError, E as EntryNotFoundError, M as MethodInfo, c as OpenApiPaths$1 } from './shared/nestjs-openapi.BYUrTaMo.js';
3
+ export { A as AnalysisError, i as ConfigLoadError, j as ConfigValidationError, G as GenerateOptions, k as GeneratorError, H as HttpMethod, I as InvalidMethodError, e as ParameterLocation, f as ResolvedParameter, h as ReturnTypeInfo, d as generateAsync, g as generateEffect } from './shared/nestjs-openapi.BYUrTaMo.js';
4
+ import { DynamicModule } from '@nestjs/common';
5
+ import { Project, SourceFile, ClassDeclaration, MethodDeclaration, Decorator, Symbol, ObjectLiteralExpression, Expression } from 'ts-morph';
6
+
7
+ /**
8
+ * Public types for nestjs-openapi
9
+ *
10
+ * These types are exposed to consumers of the library. Internal types
11
+ * should be kept in domain.ts.
12
+ */
13
+ /**
14
+ * Contact information for the API
15
+ */
16
+ interface ContactConfig {
17
+ readonly name?: string;
18
+ readonly email?: string;
19
+ readonly url?: string;
20
+ }
21
+ /**
22
+ * License information for the API
23
+ */
24
+ interface LicenseConfig {
25
+ readonly name: string;
26
+ readonly url?: string;
27
+ }
28
+ /**
29
+ * API metadata for the OpenAPI info section
30
+ */
31
+ interface InfoConfig {
32
+ readonly title: string;
33
+ readonly version: string;
34
+ readonly description?: string;
35
+ readonly contact?: ContactConfig;
36
+ readonly license?: LicenseConfig;
37
+ }
38
+ /**
39
+ * Server configuration for the OpenAPI servers section
40
+ */
41
+ interface ServerConfig {
42
+ readonly url: string;
43
+ readonly description?: string;
44
+ }
45
+ /**
46
+ * Tag configuration for organizing API endpoints
47
+ */
48
+ interface TagConfig {
49
+ readonly name: string;
50
+ readonly description?: string;
51
+ }
52
+ /**
53
+ * Security scheme type for OpenAPI 3.0
54
+ */
55
+ type SecuritySchemeType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
56
+ /**
57
+ * Location for apiKey security schemes
58
+ */
59
+ type SecuritySchemeIn = 'query' | 'header' | 'cookie';
60
+ /**
61
+ * OAuth2 flow configuration
62
+ */
63
+ interface OAuth2FlowConfig {
64
+ readonly authorizationUrl?: string;
65
+ readonly tokenUrl?: string;
66
+ readonly refreshUrl?: string;
67
+ readonly scopes?: Record<string, string>;
68
+ }
69
+ /**
70
+ * OAuth2 flows configuration
71
+ */
72
+ interface OAuth2FlowsConfig {
73
+ readonly implicit?: OAuth2FlowConfig;
74
+ readonly password?: OAuth2FlowConfig;
75
+ readonly clientCredentials?: OAuth2FlowConfig;
76
+ readonly authorizationCode?: OAuth2FlowConfig;
77
+ }
78
+ /**
79
+ * Security scheme configuration for OpenAPI 3.0
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Bearer token (JWT)
84
+ * {
85
+ * name: 'bearerAuth',
86
+ * type: 'http',
87
+ * scheme: 'bearer',
88
+ * bearerFormat: 'JWT',
89
+ * }
90
+ *
91
+ * // API Key in header
92
+ * {
93
+ * name: 'apiKey',
94
+ * type: 'apiKey',
95
+ * in: 'header',
96
+ * parameterName: 'X-API-Key',
97
+ * }
98
+ *
99
+ * // OAuth2
100
+ * {
101
+ * name: 'oauth2',
102
+ * type: 'oauth2',
103
+ * flows: {
104
+ * authorizationCode: {
105
+ * authorizationUrl: 'https://example.com/oauth/authorize',
106
+ * tokenUrl: 'https://example.com/oauth/token',
107
+ * scopes: { 'read:users': 'Read user data' },
108
+ * },
109
+ * },
110
+ * }
111
+ * ```
112
+ */
113
+ interface SecuritySchemeConfig {
114
+ /** Unique name for this security scheme (used as key in securitySchemes) */
115
+ readonly name: string;
116
+ /** The type of the security scheme */
117
+ readonly type: SecuritySchemeType;
118
+ /** Description of the security scheme */
119
+ readonly description?: string;
120
+ /** The name of the HTTP Authorization scheme (for type: 'http') */
121
+ readonly scheme?: string;
122
+ /** A hint for the format of the token (for type: 'http' with scheme: 'bearer') */
123
+ readonly bearerFormat?: string;
124
+ /** The location of the API key (for type: 'apiKey') */
125
+ readonly in?: SecuritySchemeIn;
126
+ /** The name of the header, query, or cookie parameter (for type: 'apiKey') */
127
+ readonly parameterName?: string;
128
+ /** OAuth2 flows configuration (for type: 'oauth2') */
129
+ readonly flows?: OAuth2FlowsConfig;
130
+ /** OpenID Connect URL to discover OAuth2 config (for type: 'openIdConnect') */
131
+ readonly openIdConnectUrl?: string;
132
+ }
133
+ /**
134
+ * Security requirement - maps security scheme names to required scopes
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Require bearerAuth with no specific scopes
139
+ * { bearerAuth: [] }
140
+ *
141
+ * // Require oauth2 with specific scopes
142
+ * { oauth2: ['read:users', 'write:users'] }
143
+ * ```
144
+ */
145
+ type SecurityRequirement = Record<string, readonly string[]>;
146
+ /**
147
+ * Output format for the generated OpenAPI specification
148
+ */
149
+ type OutputFormat = 'json' | 'yaml';
150
+ /**
151
+ * OpenAPI specification version
152
+ * - '3.0.3': OpenAPI 3.0.3 (default, widely supported)
153
+ * - '3.1.0': OpenAPI 3.1.0 (full JSON Schema 2020-12 alignment, type arrays for nullable)
154
+ * - '3.2.0': OpenAPI 3.2.0 (when released, will include webhooks and other new features)
155
+ */
156
+ type OpenApiVersion = '3.0.3' | '3.1.0' | '3.2.0';
157
+ /**
158
+ * Input file configuration for nestjs-openapi.
159
+ * All paths are relative to the config file location.
160
+ */
161
+ interface FilesConfig {
162
+ /**
163
+ * Entry module file(s).
164
+ * @default "src/app.module.ts"
165
+ */
166
+ readonly entry?: string | readonly string[];
167
+ /**
168
+ * Path to tsconfig.json. Auto-detected if not specified.
169
+ */
170
+ readonly tsconfig?: string;
171
+ /**
172
+ * Glob pattern(s) for DTO files to generate schemas from.
173
+ * @example "src/**\/*.dto.ts"
174
+ */
175
+ readonly dtoGlob?: string | readonly string[];
176
+ /**
177
+ * Glob patterns to include.
178
+ */
179
+ readonly include?: readonly string[];
180
+ /**
181
+ * Glob patterns to exclude.
182
+ * @default ["**\/*.spec.ts", "**\/*.test.ts", "**\/node_modules/**"]
183
+ */
184
+ readonly exclude?: readonly string[];
185
+ }
186
+ /**
187
+ * Security configuration for OpenAPI spec.
188
+ */
189
+ interface SecurityConfig {
190
+ /**
191
+ * Security schemes available for the API.
192
+ * Defines authentication methods (bearer, apiKey, oauth2, etc.)
193
+ */
194
+ readonly schemes?: readonly SecuritySchemeConfig[];
195
+ /**
196
+ * Global security requirements applied to all operations.
197
+ * Can be overridden at the operation level.
198
+ * Each object in the array represents an alternative (OR logic).
199
+ * Within each object, all schemes must be satisfied (AND logic).
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Require bearerAuth for all operations
204
+ * global: [{ bearerAuth: [] }]
205
+ *
206
+ * // Allow either bearerAuth OR apiKey
207
+ * global: [{ bearerAuth: [] }, { apiKey: [] }]
208
+ * ```
209
+ */
210
+ readonly global?: readonly SecurityRequirement[];
211
+ }
212
+ /**
213
+ * OpenAPI specification metadata configuration.
214
+ * Maps directly to the OpenAPI spec structure.
215
+ */
216
+ interface OpenApiConfig {
217
+ /**
218
+ * OpenAPI specification version.
219
+ * @default "3.0.3"
220
+ */
221
+ readonly version?: OpenApiVersion;
222
+ /**
223
+ * API metadata for the info section.
224
+ * @required
225
+ */
226
+ readonly info: InfoConfig;
227
+ /**
228
+ * Server URLs for the API.
229
+ */
230
+ readonly servers?: readonly ServerConfig[];
231
+ /**
232
+ * Tags for organizing API endpoints.
233
+ */
234
+ readonly tags?: readonly TagConfig[];
235
+ /**
236
+ * Security configuration.
237
+ */
238
+ readonly security?: SecurityConfig;
239
+ }
240
+ /**
241
+ * Generation behavior options.
242
+ */
243
+ interface OptionsConfig {
244
+ /**
245
+ * Base path prefix for all routes.
246
+ * Equivalent to NestJS's app.setGlobalPrefix().
247
+ * @example "/api/v1"
248
+ */
249
+ readonly basePath?: string;
250
+ /**
251
+ * Extract validation constraints from class-validator decorators.
252
+ * @default true
253
+ */
254
+ readonly extractValidation?: boolean;
255
+ /**
256
+ * Decorator names that exclude endpoints from the spec.
257
+ * @default ["ApiExcludeEndpoint", "ApiExcludeController"]
258
+ */
259
+ readonly excludeDecorators?: readonly string[];
260
+ /**
261
+ * Filter paths by regex or predicate function.
262
+ * Paths matching the regex (or returning true) are INCLUDED.
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * // Exclude internal and versioned paths
267
+ * pathFilter: /^(?!.*(\/internal\/|\/v[\d.]+\/)).* /
268
+ *
269
+ * // Using a function
270
+ * pathFilter: (path) => !path.includes('/internal/')
271
+ * ```
272
+ */
273
+ readonly pathFilter?: RegExp | ((path: string) => boolean);
274
+ /**
275
+ * Query parameter handling options.
276
+ */
277
+ readonly query?: QueryOptions;
278
+ }
279
+ /**
280
+ * Query parameter handling options.
281
+ */
282
+ interface QueryOptions {
283
+ /**
284
+ * How to represent query object DTOs (e.g., `@Query() dto: PaginationDto`).
285
+ * - `"inline"` (default): Expand DTO properties as individual query parameters
286
+ * - `"ref"`: Keep as a single parameter with a schema reference
287
+ *
288
+ * @default "inline"
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * // With style: "inline" (default)
293
+ * // @Query() dto: PaginationDto becomes:
294
+ * // - page: integer (query)
295
+ * // - limit: integer (query)
296
+ *
297
+ * // With style: "ref"
298
+ * // @Query() dto: PaginationDto becomes:
299
+ * // - dto: $ref to PaginationDto schema (query)
300
+ * ```
301
+ */
302
+ readonly style?: 'inline' | 'ref';
303
+ }
304
+ /**
305
+ * Configuration for nestjs-openapi.
306
+ * Inspired by tsconfig.json and vite.config.ts patterns.
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * import { defineConfig } from 'nestjs-openapi';
311
+ *
312
+ * export default defineConfig({
313
+ * output: 'src/openapi/openapi.generated.json',
314
+ *
315
+ * files: {
316
+ * entry: 'src/app.module.ts',
317
+ * dtoGlob: 'src/**\/*.dto.ts',
318
+ * },
319
+ *
320
+ * openapi: {
321
+ * info: {
322
+ * title: 'My API',
323
+ * version: '1.0.0',
324
+ * },
325
+ * },
326
+ *
327
+ * options: {
328
+ * basePath: '/api',
329
+ * extractValidation: true,
330
+ * },
331
+ * });
332
+ * ```
333
+ */
334
+ interface Config {
335
+ /**
336
+ * Extend another config file. Paths are relative to this config file.
337
+ * Extended config values are deeply merged, with this config taking precedence.
338
+ * @example extends: './configs/base-openapi.config.ts'
339
+ */
340
+ readonly extends?: string;
341
+ /**
342
+ * Input file configuration.
343
+ * All paths are relative to the config file location.
344
+ */
345
+ readonly files?: FilesConfig;
346
+ /**
347
+ * Output path for the generated OpenAPI specification.
348
+ * Path is relative to the config file location.
349
+ * @required
350
+ */
351
+ readonly output: string;
352
+ /**
353
+ * Output format for the specification.
354
+ * @default "json"
355
+ */
356
+ readonly format?: OutputFormat;
357
+ /**
358
+ * OpenAPI specification metadata.
359
+ * Maps directly to the OpenAPI spec structure.
360
+ * @required
361
+ */
362
+ readonly openapi: OpenApiConfig;
363
+ /**
364
+ * Generation behavior options.
365
+ */
366
+ readonly options?: OptionsConfig;
367
+ }
368
+ /**
369
+ * Options for the generate function to override config values.
370
+ * Useful for CLI overrides.
371
+ */
372
+ interface GenerateOverrides {
373
+ /**
374
+ * Override the output format.
375
+ * Takes precedence over config.format.
376
+ */
377
+ readonly format?: OutputFormat;
378
+ /**
379
+ * Enable debug mode for verbose logging and full stack traces.
380
+ */
381
+ readonly debug?: boolean;
382
+ }
383
+ /**
384
+ * OpenAPI 3.0/3.1/3.2 specification schema object
385
+ * Type can be a string or array of strings (for nullable in 3.1+)
386
+ */
387
+ interface OpenApiSchema {
388
+ /** Schema type - string or array for 3.1+ nullable (e.g., ['string', 'null']) */
389
+ readonly type?: string | readonly string[];
390
+ readonly format?: string;
391
+ readonly $ref?: string;
392
+ readonly oneOf?: readonly OpenApiSchema[];
393
+ readonly anyOf?: readonly OpenApiSchema[];
394
+ readonly allOf?: readonly OpenApiSchema[];
395
+ readonly items?: OpenApiSchema;
396
+ readonly properties?: Record<string, OpenApiSchema>;
397
+ readonly required?: readonly string[];
398
+ readonly enum?: readonly unknown[];
399
+ readonly description?: string;
400
+ /** OpenAPI 3.0 only - use type: [T, 'null'] in 3.1+ instead */
401
+ readonly nullable?: boolean;
402
+ /** Examples array for 3.1+ (replaces single 'example' field) */
403
+ readonly examples?: readonly unknown[];
404
+ readonly minLength?: number;
405
+ readonly maxLength?: number;
406
+ readonly pattern?: string;
407
+ readonly minimum?: number;
408
+ readonly maximum?: number;
409
+ readonly exclusiveMinimum?: number;
410
+ readonly exclusiveMaximum?: number;
411
+ readonly minItems?: number;
412
+ readonly maxItems?: number;
413
+ readonly default?: unknown;
414
+ readonly additionalProperties?: boolean | OpenApiSchema;
415
+ }
416
+ /**
417
+ * OpenAPI 3.0 parameter object
418
+ */
419
+ interface OpenApiParameter {
420
+ readonly name: string;
421
+ readonly in: 'path' | 'query' | 'header' | 'cookie';
422
+ readonly description?: string;
423
+ readonly required: boolean;
424
+ readonly schema: OpenApiSchema;
425
+ }
426
+ /**
427
+ * OpenAPI 3.0 request body object
428
+ */
429
+ interface OpenApiRequestBody {
430
+ readonly description?: string;
431
+ readonly required?: boolean;
432
+ readonly content: Record<string, {
433
+ readonly schema: OpenApiSchema;
434
+ }>;
435
+ }
436
+ /**
437
+ * OpenAPI 3.0 response object
438
+ */
439
+ interface OpenApiResponse {
440
+ readonly description: string;
441
+ readonly content?: Record<string, {
442
+ readonly schema: OpenApiSchema;
443
+ }>;
444
+ }
445
+ /**
446
+ * OpenAPI 3.0 operation object
447
+ */
448
+ interface OpenApiOperation {
449
+ readonly operationId: string;
450
+ readonly summary?: string;
451
+ readonly description?: string;
452
+ readonly deprecated?: boolean;
453
+ readonly tags?: readonly string[];
454
+ readonly parameters?: readonly OpenApiParameter[];
455
+ readonly requestBody?: OpenApiRequestBody;
456
+ readonly responses: Record<string, OpenApiResponse>;
457
+ /** Per-operation security requirements (overrides global security) */
458
+ readonly security?: readonly SecurityRequirement[];
459
+ }
460
+ /**
461
+ * OpenAPI 3.0 paths object
462
+ * Maps path patterns to HTTP method operations
463
+ */
464
+ interface OpenApiPaths {
465
+ readonly [path: string]: {
466
+ readonly [method: string]: OpenApiOperation;
467
+ };
468
+ }
469
+ /**
470
+ * OpenAPI 3.0 OAuth2 flow object
471
+ */
472
+ interface OpenApiOAuth2Flow {
473
+ readonly authorizationUrl?: string;
474
+ readonly tokenUrl?: string;
475
+ readonly refreshUrl?: string;
476
+ readonly scopes: Record<string, string>;
477
+ }
478
+ /**
479
+ * OpenAPI 3.0 OAuth2 flows object
480
+ */
481
+ interface OpenApiOAuth2Flows {
482
+ readonly implicit?: OpenApiOAuth2Flow;
483
+ readonly password?: OpenApiOAuth2Flow;
484
+ readonly clientCredentials?: OpenApiOAuth2Flow;
485
+ readonly authorizationCode?: OpenApiOAuth2Flow;
486
+ }
487
+ /**
488
+ * OpenAPI 3.0 security scheme object
489
+ */
490
+ interface OpenApiSecurityScheme {
491
+ readonly type: SecuritySchemeType;
492
+ readonly description?: string;
493
+ /** The name of the HTTP Authorization scheme (for type: 'http') */
494
+ readonly scheme?: string;
495
+ /** A hint for the format of the token (for type: 'http' with scheme: 'bearer') */
496
+ readonly bearerFormat?: string;
497
+ /** The location of the API key (for type: 'apiKey') */
498
+ readonly in?: SecuritySchemeIn;
499
+ /** The name of the header, query, or cookie parameter (for type: 'apiKey') */
500
+ readonly name?: string;
501
+ /** OAuth2 flows (for type: 'oauth2') */
502
+ readonly flows?: OpenApiOAuth2Flows;
503
+ /** OpenID Connect URL (for type: 'openIdConnect') */
504
+ readonly openIdConnectUrl?: string;
505
+ }
506
+ /**
507
+ * Webhook operation for OpenAPI 3.1+
508
+ * Similar to regular operations but accessed via events rather than HTTP methods
509
+ */
510
+ interface OpenApiWebhookOperation {
511
+ readonly post?: OpenApiOperation;
512
+ readonly put?: OpenApiOperation;
513
+ readonly patch?: OpenApiOperation;
514
+ readonly delete?: OpenApiOperation;
515
+ readonly get?: OpenApiOperation;
516
+ }
517
+ /**
518
+ * Complete OpenAPI 3.0/3.1/3.2 specification
519
+ */
520
+ interface OpenApiSpec {
521
+ readonly openapi: OpenApiVersion;
522
+ readonly info: {
523
+ readonly title: string;
524
+ readonly version: string;
525
+ readonly description?: string;
526
+ readonly contact?: ContactConfig;
527
+ readonly license?: LicenseConfig;
528
+ };
529
+ readonly servers?: readonly ServerConfig[];
530
+ readonly tags?: readonly TagConfig[];
531
+ readonly paths: OpenApiPaths;
532
+ /** Webhooks for OpenAPI 3.1+ - event-driven operations */
533
+ readonly webhooks?: Record<string, OpenApiWebhookOperation>;
534
+ readonly components?: {
535
+ readonly schemas?: Record<string, OpenApiSchema>;
536
+ readonly securitySchemes?: Record<string, OpenApiSecurityScheme>;
537
+ };
538
+ /** Global security requirements */
539
+ readonly security?: readonly SecurityRequirement[];
540
+ }
541
+
542
+ /**
543
+ * OpenAPI spec validation utilities.
544
+ *
545
+ * Validates that generated specs don't have broken $ref references
546
+ * or other common issues.
547
+ */
548
+
549
+ /**
550
+ * A broken reference found during validation
551
+ */
552
+ interface BrokenRef {
553
+ /** The $ref value that couldn't be resolved */
554
+ readonly ref: string;
555
+ /** The JSON path where this reference was found */
556
+ readonly path: string;
557
+ /** The schema name that's missing (extracted from $ref) */
558
+ readonly missingSchema: string;
559
+ }
560
+ /**
561
+ * Result of spec validation
562
+ */
563
+ interface ValidationResult {
564
+ /** Whether the spec is valid (no broken refs) */
565
+ readonly valid: boolean;
566
+ /** Total number of schema refs found */
567
+ readonly totalRefs: number;
568
+ /** Number of broken refs */
569
+ readonly brokenRefCount: number;
570
+ /** Details of each broken ref */
571
+ readonly brokenRefs: readonly BrokenRef[];
572
+ /** Missing schema names grouped with their usage count */
573
+ readonly missingSchemas: ReadonlyMap<string, number>;
574
+ }
575
+ /**
576
+ * Validates an OpenAPI spec for broken $ref references.
577
+ *
578
+ * @param spec - The OpenAPI specification to validate
579
+ * @returns Validation result with details about any broken refs
580
+ *
581
+ * @example
582
+ * ```typescript
583
+ * const result = validateSpec(spec);
584
+ * if (!result.valid) {
585
+ * console.error(`Found ${result.brokenRefCount} broken refs:`);
586
+ * for (const [schema, count] of result.missingSchemas) {
587
+ * console.error(` - ${schema} (${count} usages)`);
588
+ * }
589
+ * }
590
+ * ```
591
+ */
592
+ declare function validateSpec(spec: OpenApiSpec): ValidationResult;
593
+ /**
594
+ * Categorizes broken refs by likely cause
595
+ */
596
+ interface BrokenRefCategories {
597
+ /** Primitive types that shouldn't be refs (string, number, boolean) */
598
+ readonly primitives: readonly string[];
599
+ /** Union types (Type | null, void | Type) */
600
+ readonly unionTypes: readonly string[];
601
+ /** Query/Path parameter DTOs */
602
+ readonly queryParams: readonly string[];
603
+ /** Other missing schemas (likely from different glob patterns) */
604
+ readonly other: readonly string[];
605
+ }
606
+ /**
607
+ * Categorize broken refs to help diagnose the root cause.
608
+ *
609
+ * @param missingSchemas - Map of missing schema names to usage count
610
+ * @returns Categorized broken refs
611
+ */
612
+ declare function categorizeBrokenRefs(missingSchemas: ReadonlyMap<string, number>): BrokenRefCategories;
613
+ /**
614
+ * Formats validation result as a human-readable string for CLI output.
615
+ *
616
+ * @param result - Validation result from validateSpec
617
+ * @returns Formatted string describing the validation issues
618
+ */
619
+ declare function formatValidationResult(result: ValidationResult): string;
620
+
621
+ /**
622
+ * Promise-based entry point for generating OpenAPI specifications.
623
+ *
624
+ * This module provides a clean, Promise-based API that hides the internal
625
+ * Effect-TS implementation from consumers.
626
+ */
627
+
628
+ interface GenerateResult {
629
+ /** Path where the OpenAPI spec was written */
630
+ readonly outputPath: string;
631
+ /** Number of paths in the generated spec */
632
+ readonly pathCount: number;
633
+ /** Number of operations in the generated spec */
634
+ readonly operationCount: number;
635
+ /** Number of schemas in the generated spec */
636
+ readonly schemaCount: number;
637
+ /** Validation result checking for broken refs */
638
+ readonly validation: ValidationResult;
639
+ }
640
+ /**
641
+ * Generates an OpenAPI specification from a NestJS application.
642
+ *
643
+ * @param configPath - Path to the configuration file (openapi.config.ts)
644
+ * @param options - Optional overrides for config values (e.g., format)
645
+ * @returns Promise that resolves with generation result when complete
646
+ *
647
+ * @example
648
+ * ```typescript
649
+ * import { generate } from 'nestjs-openapi';
650
+ *
651
+ * await generate('apps/backend-api/openapi.config.ts');
652
+ *
653
+ * // Override format from CLI
654
+ * await generate('apps/backend-api/openapi.config.ts', { format: 'yaml' });
655
+ * ```
656
+ */
657
+ declare const generate: (configPath: string, overrides?: GenerateOverrides) => Promise<GenerateResult>;
658
+
659
+ /**
660
+ * Define configuration for OpenAPI generation.
661
+ *
662
+ * @example
663
+ * ```typescript
664
+ * export default defineConfig({
665
+ * output: 'openapi.json',
666
+ * files: { entry: 'src/app.module.ts' },
667
+ * openapi: { info: { title: 'My API', version: '1.0.0' } },
668
+ * });
669
+ * ```
670
+ */
671
+ declare function defineConfig(config: Config): Config;
672
+ declare const findConfigFile: (startDir?: string) => Effect.Effect<string, ConfigNotFoundError>;
673
+ declare const loadConfigFromFile: (configPath: string) => Effect.Effect<typeof OpenApiGeneratorConfig.Type, ConfigError>;
674
+ declare const loadConfig: (configPath?: string, cwd?: string) => Effect.Effect<typeof OpenApiGeneratorConfig.Type, ConfigError>;
675
+ declare const resolveConfig: (config: typeof OpenApiGeneratorConfig.Type) => typeof ResolvedConfig.Type;
676
+ declare const loadAndResolveConfig: (configPath?: string, cwd?: string) => Effect.Effect<typeof ResolvedConfig.Type, ConfigError>;
677
+
678
+ /**
679
+ * NestJS Module for serving generated OpenAPI specifications at runtime.
680
+ *
681
+ * @example
682
+ * ```typescript
683
+ * import { OpenApiModule } from 'nestjs-openapi';
684
+ *
685
+ * @Module({
686
+ * imports: [
687
+ * OpenApiModule.forRoot({
688
+ * specFile: 'openapi.json',
689
+ * swagger: true,
690
+ * }),
691
+ * ],
692
+ * })
693
+ * export class AppModule {}
694
+ * ```
695
+ */
696
+
697
+ /**
698
+ * Swagger UI configuration options
699
+ */
700
+ interface SwaggerOptions {
701
+ /**
702
+ * The path where Swagger UI will be served.
703
+ * @default "/api-docs"
704
+ */
705
+ readonly path?: string;
706
+ /**
707
+ * Custom title for the Swagger UI page.
708
+ * Uses the spec's info.title if not provided.
709
+ */
710
+ readonly title?: string;
711
+ }
712
+ /**
713
+ * Configuration options for the OpenAPI module
714
+ */
715
+ interface OpenApiModuleOptions {
716
+ /**
717
+ * Path to the generated OpenAPI JSON file.
718
+ * Can be absolute or relative to the current working directory.
719
+ */
720
+ readonly specFile: string;
721
+ /**
722
+ * Whether the module is enabled.
723
+ * When false, no routes are registered.
724
+ * @default true
725
+ */
726
+ readonly enabled?: boolean;
727
+ /**
728
+ * The path where the OpenAPI JSON will be served.
729
+ * @default "/openapi.json"
730
+ */
731
+ readonly jsonPath?: string;
732
+ /**
733
+ * Swagger UI configuration.
734
+ * - `true` - Enable with defaults (path: '/api-docs', title from spec)
735
+ * - `false` or omitted - Disable Swagger UI
736
+ * - `object` - Enable with custom configuration
737
+ * @default false
738
+ */
739
+ readonly swagger?: boolean | SwaggerOptions;
740
+ }
741
+ /**
742
+ * Resolved options with all defaults applied
743
+ */
744
+ interface ResolvedOpenApiModuleOptions {
745
+ readonly specFile: string;
746
+ readonly enabled: boolean;
747
+ readonly jsonPath: string;
748
+ readonly swagger: {
749
+ readonly enabled: boolean;
750
+ readonly path: string;
751
+ readonly title: string;
752
+ };
753
+ }
754
+ /**
755
+ * Injection token for OpenAPI module options
756
+ */
757
+ declare const OPENAPI_MODULE_OPTIONS: unique symbol;
758
+ /**
759
+ * Injection token for the loaded OpenAPI specification
760
+ */
761
+ declare const OPENAPI_SPEC: unique symbol;
762
+ /**
763
+ * Generate Swagger UI HTML page
764
+ */
765
+ declare function generateSwaggerUiHtml(title: string, jsonPath: string): string;
766
+ /**
767
+ * Load the OpenAPI spec file from disk
768
+ */
769
+ declare function loadSpecFile(filePath: string): OpenApiSpec;
770
+ /**
771
+ * Resolve options with defaults
772
+ */
773
+ declare function resolveOptions(options: OpenApiModuleOptions): ResolvedOpenApiModuleOptions;
774
+ /**
775
+ * NestJS module for serving generated OpenAPI specifications at runtime.
776
+ *
777
+ * This module provides:
778
+ * - JSON endpoint for the OpenAPI specification
779
+ * - Optional Swagger UI for interactive documentation
780
+ * - Conditional enabling based on environment
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * // Basic usage - serve JSON only
785
+ * OpenApiModule.forRoot({
786
+ * specFile: 'openapi.json',
787
+ * })
788
+ *
789
+ * // With Swagger UI (defaults)
790
+ * OpenApiModule.forRoot({
791
+ * specFile: 'openapi.json',
792
+ * swagger: true,
793
+ * })
794
+ *
795
+ * // With Swagger UI (custom options)
796
+ * OpenApiModule.forRoot({
797
+ * specFile: 'openapi.json',
798
+ * swagger: { path: '/docs', title: 'My API' },
799
+ * })
800
+ *
801
+ * // Conditionally enabled
802
+ * OpenApiModule.forRoot({
803
+ * specFile: 'openapi.json',
804
+ * enabled: process.env.OPENAPI_ENABLED === 'true',
805
+ * })
806
+ * ```
807
+ */
808
+ declare class OpenApiModule {
809
+ /**
810
+ * Configure the OpenAPI module with options.
811
+ *
812
+ * @param options - Configuration options
813
+ * @returns Dynamic module configuration
814
+ */
815
+ static forRoot(options: OpenApiModuleOptions): DynamicModule;
816
+ }
817
+
818
+ interface ProjectContext {
819
+ readonly project: Project;
820
+ readonly entrySourceFile: SourceFile;
821
+ readonly entryClass: ClassDeclaration;
822
+ }
823
+ interface ProjectOptions {
824
+ readonly tsconfig: string;
825
+ readonly entry: string;
826
+ }
827
+ declare const ProjectService_base: Context.TagClass<ProjectService, "ProjectService", {
828
+ readonly context: ProjectContext;
829
+ }>;
830
+ /**
831
+ * ProjectService is an infrastructure context holder.
832
+ * Context.Tag is appropriate here as it holds externally-provided resources.
833
+ */
834
+ declare class ProjectService extends ProjectService_base {
835
+ }
836
+ declare const makeProjectContext: (options: ProjectOptions) => Effect.Effect<{
837
+ project: Project;
838
+ entrySourceFile: SourceFile;
839
+ entryClass: ClassDeclaration;
840
+ }, ProjectInitError | EntryNotFoundError, never>;
841
+ declare const ProjectServiceLive: (options: ProjectOptions) => Layer.Layer<ProjectService, ProjectError>;
842
+
843
+ interface ModuleWithControllers {
844
+ readonly declaration: ClassDeclaration;
845
+ readonly controllers: readonly ClassDeclaration[];
846
+ }
847
+ /** Iterative BFS to avoid stack overflow on deep module graphs */
848
+ declare const getModules: (root: ClassDeclaration) => Effect.Effect<readonly ModuleWithControllers[], never, never>;
849
+ declare const getAllControllers: (root: ClassDeclaration) => Effect.Effect<ClassDeclaration[], never, never>;
850
+
851
+ declare const normalizePath: (path: string) => string;
852
+ declare const getControllerPrefix: (controller: ClassDeclaration) => string;
853
+ declare const getControllerName: (controller: ClassDeclaration) => string;
854
+ declare const isHttpMethod: (method: MethodDeclaration) => boolean;
855
+ declare const getHttpMethods: (controller: ClassDeclaration) => readonly MethodDeclaration[];
856
+ /** Handles both @Get and @Get() syntax */
857
+ declare const getDecoratorName: (decorator: Decorator) => string;
858
+ /** Falls back to controller name (minus 'Controller' suffix) if no @ApiTags */
859
+ declare const getControllerTags: (controller: ClassDeclaration) => readonly string[];
860
+ declare const isHttpDecorator: (decorator: Decorator) => boolean;
861
+ declare const getHttpDecorator: (method: MethodDeclaration) => Decorator | undefined;
862
+
863
+ /** Configuration options for parameter extraction */
864
+ interface ExtractParametersOptions {
865
+ /** Query parameter handling options */
866
+ readonly query?: {
867
+ /** How to represent query DTOs: "inline" (default) or "ref" */
868
+ readonly style?: 'inline' | 'ref';
869
+ };
870
+ }
871
+ /** Returns None if the method has no HTTP decorator */
872
+ declare const getMethodInfo: (controller: ClassDeclaration, method: MethodDeclaration, options?: ExtractParametersOptions) => Option.Option<MethodInfo>;
873
+ declare const getControllerMethodInfos: (controller: ClassDeclaration, options?: ExtractParametersOptions) => readonly MethodInfo[];
874
+
875
+ declare const transformMethod: (methodInfo: MethodInfo) => OpenApiPaths$1;
876
+ declare const transformMethods: (methodInfos: readonly MethodInfo[]) => OpenApiPaths$1;
877
+
878
+ /** Handles aliased symbols (re-exports) */
879
+ declare const resolveClassFromSymbol: (sym: Symbol) => Option.Option<ClassDeclaration>;
880
+ declare const getArrayInitializer: (objectLiteral: ObjectLiteralExpression, propertyName: string) => Option.Option<Expression>;
881
+ declare const getStringLiteralValue: (expr: Expression | undefined) => Option.Option<string>;
882
+ declare const getSymbolFromIdentifier: (expr: Expression | undefined) => Option.Option<Symbol>;
883
+
884
+ declare const isModuleClass: (cls: ClassDeclaration | undefined) => boolean;
885
+ declare const getModuleDecoratorArg: (cls: ClassDeclaration) => Option.Option<ObjectLiteralExpression>;
886
+ /** Handles identifiers, forwardRef(() => Class), and property access */
887
+ declare const resolveClassFromExpression: (expr: Expression | undefined) => Option.Option<ClassDeclaration>;
888
+ declare const resolveArrayOfClasses: (propInit?: Expression) => readonly ClassDeclaration[];
889
+ interface ModuleMetadata {
890
+ readonly controllers: readonly ClassDeclaration[];
891
+ readonly imports: readonly ClassDeclaration[];
892
+ }
893
+ declare const getModuleMetadata: (mod: ClassDeclaration) => ModuleMetadata;
894
+
895
+ export { ConfigError, ConfigNotFoundError, EntryNotFoundError, MethodInfo, OPENAPI_MODULE_OPTIONS, OPENAPI_SPEC, OpenApiGeneratorConfig, OpenApiModule, ProjectError, ProjectInitError, ProjectService, ProjectServiceLive, ResolvedConfig, categorizeBrokenRefs, defineConfig, findConfigFile, formatValidationResult, generate, generateSwaggerUiHtml, getAllControllers, getArrayInitializer, getControllerMethodInfos, getControllerName, getControllerPrefix, getControllerTags, getDecoratorName, getHttpDecorator, getHttpMethods, getMethodInfo, getModuleDecoratorArg, getModuleMetadata, getModules, getStringLiteralValue, getSymbolFromIdentifier, isHttpDecorator, isHttpMethod, isModuleClass, loadAndResolveConfig, loadConfig, loadConfigFromFile, loadSpecFile, makeProjectContext, normalizePath, resolveArrayOfClasses, resolveClassFromExpression, resolveClassFromSymbol, resolveConfig, resolveOptions, transformMethod, transformMethods, validateSpec };
896
+ export type { BrokenRef, BrokenRefCategories, Config, ContactConfig, GenerateOverrides, GenerateResult, InfoConfig, LicenseConfig, ModuleMetadata, ModuleWithControllers, OpenApiModuleOptions, OpenApiOperation, OpenApiParameter, OpenApiPaths, OpenApiRequestBody, OpenApiResponse, OpenApiSchema, OpenApiSpec, OutputFormat, ProjectContext, ProjectOptions, ResolvedOpenApiModuleOptions, ServerConfig, SwaggerOptions, TagConfig, ValidationResult };