@digitaldefiance/node-express-suite 3.11.32 → 3.12.1

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.
Files changed (146) hide show
  1. package/README.md +874 -8
  2. package/package.json +5 -5
  3. package/src/controllers/openapi.d.ts +67 -0
  4. package/src/controllers/openapi.d.ts.map +1 -0
  5. package/src/controllers/openapi.js +89 -0
  6. package/src/controllers/openapi.js.map +1 -0
  7. package/src/decorators/auth.d.ts +128 -0
  8. package/src/decorators/auth.d.ts.map +1 -0
  9. package/src/decorators/auth.js +230 -0
  10. package/src/decorators/auth.js.map +1 -0
  11. package/src/decorators/base-controller.d.ts +144 -6
  12. package/src/decorators/base-controller.d.ts.map +1 -1
  13. package/src/decorators/base-controller.js +487 -31
  14. package/src/decorators/base-controller.js.map +1 -1
  15. package/src/decorators/controller.d.ts +63 -7
  16. package/src/decorators/controller.d.ts.map +1 -1
  17. package/src/decorators/controller.js +70 -39
  18. package/src/decorators/controller.js.map +1 -1
  19. package/src/decorators/handler-args.d.ts +68 -0
  20. package/src/decorators/handler-args.d.ts.map +1 -0
  21. package/src/decorators/handler-args.js +83 -0
  22. package/src/decorators/handler-args.js.map +1 -0
  23. package/src/decorators/http-methods.d.ts +143 -0
  24. package/src/decorators/http-methods.d.ts.map +1 -0
  25. package/src/decorators/http-methods.js +265 -0
  26. package/src/decorators/http-methods.js.map +1 -0
  27. package/src/decorators/index.d.ts +22 -0
  28. package/src/decorators/index.d.ts.map +1 -1
  29. package/src/decorators/index.js +56 -0
  30. package/src/decorators/index.js.map +1 -1
  31. package/src/decorators/lifecycle.d.ts +248 -0
  32. package/src/decorators/lifecycle.d.ts.map +1 -0
  33. package/src/decorators/lifecycle.js +301 -0
  34. package/src/decorators/lifecycle.js.map +1 -0
  35. package/src/decorators/metadata-collector.d.ts +175 -0
  36. package/src/decorators/metadata-collector.d.ts.map +1 -0
  37. package/src/decorators/metadata-collector.js +272 -0
  38. package/src/decorators/metadata-collector.js.map +1 -0
  39. package/src/decorators/metadata-keys.d.ts +121 -0
  40. package/src/decorators/metadata-keys.d.ts.map +1 -0
  41. package/src/decorators/metadata-keys.js +116 -0
  42. package/src/decorators/metadata-keys.js.map +1 -0
  43. package/src/decorators/middleware.d.ts +181 -0
  44. package/src/decorators/middleware.d.ts.map +1 -0
  45. package/src/decorators/middleware.js +400 -0
  46. package/src/decorators/middleware.js.map +1 -0
  47. package/src/decorators/openapi-params.d.ts +192 -0
  48. package/src/decorators/openapi-params.d.ts.map +1 -0
  49. package/src/decorators/openapi-params.js +332 -0
  50. package/src/decorators/openapi-params.js.map +1 -0
  51. package/src/decorators/openapi.d.ts +201 -0
  52. package/src/decorators/openapi.d.ts.map +1 -0
  53. package/src/decorators/openapi.js +334 -0
  54. package/src/decorators/openapi.js.map +1 -0
  55. package/src/decorators/params.d.ts +217 -0
  56. package/src/decorators/params.d.ts.map +1 -0
  57. package/src/decorators/params.js +323 -0
  58. package/src/decorators/params.js.map +1 -0
  59. package/src/decorators/response.d.ts +200 -0
  60. package/src/decorators/response.d.ts.map +1 -0
  61. package/src/decorators/response.js +315 -0
  62. package/src/decorators/response.js.map +1 -0
  63. package/src/decorators/schema.d.ts +99 -0
  64. package/src/decorators/schema.d.ts.map +1 -0
  65. package/src/decorators/schema.js +329 -0
  66. package/src/decorators/schema.js.map +1 -0
  67. package/src/decorators/transaction.d.ts +69 -0
  68. package/src/decorators/transaction.d.ts.map +1 -0
  69. package/src/decorators/transaction.js +80 -0
  70. package/src/decorators/transaction.js.map +1 -0
  71. package/src/decorators/validation.d.ts +188 -0
  72. package/src/decorators/validation.d.ts.map +1 -0
  73. package/src/decorators/validation.js +269 -0
  74. package/src/decorators/validation.js.map +1 -0
  75. package/src/decorators/zod-validation.d.ts +164 -4
  76. package/src/decorators/zod-validation.d.ts.map +1 -1
  77. package/src/decorators/zod-validation.js +692 -13
  78. package/src/decorators/zod-validation.js.map +1 -1
  79. package/src/index.d.ts +1 -0
  80. package/src/index.d.ts.map +1 -1
  81. package/src/index.js +1 -0
  82. package/src/index.js.map +1 -1
  83. package/src/interfaces/openApi/decoratorOptions.d.ts +760 -0
  84. package/src/interfaces/openApi/decoratorOptions.d.ts.map +1 -0
  85. package/src/interfaces/openApi/decoratorOptions.js +734 -0
  86. package/src/interfaces/openApi/decoratorOptions.js.map +1 -0
  87. package/src/interfaces/openApi/index.d.ts +1 -0
  88. package/src/interfaces/openApi/index.d.ts.map +1 -1
  89. package/src/interfaces/openApi/index.js +23 -0
  90. package/src/interfaces/openApi/index.js.map +1 -1
  91. package/src/interfaces/openApi/parameter.d.ts +2 -0
  92. package/src/interfaces/openApi/parameter.d.ts.map +1 -1
  93. package/src/interfaces/openApi/parameter.js +3 -1
  94. package/src/interfaces/openApi/parameter.js.map +1 -1
  95. package/src/interfaces/openApi/parameterSchema.d.ts +2 -0
  96. package/src/interfaces/openApi/parameterSchema.d.ts.map +1 -1
  97. package/src/interfaces/openApi/parameterSchema.js +3 -0
  98. package/src/interfaces/openApi/parameterSchema.js.map +1 -1
  99. package/src/openapi/builder.d.ts +249 -0
  100. package/src/openapi/builder.d.ts.map +1 -0
  101. package/src/openapi/builder.js +352 -0
  102. package/src/openapi/builder.js.map +1 -0
  103. package/src/openapi/controller.d.ts +153 -0
  104. package/src/openapi/controller.d.ts.map +1 -0
  105. package/src/openapi/controller.js +331 -0
  106. package/src/openapi/controller.js.map +1 -0
  107. package/src/openapi/index.d.ts +12 -0
  108. package/src/openapi/index.d.ts.map +1 -0
  109. package/src/openapi/index.js +20 -0
  110. package/src/openapi/index.js.map +1 -0
  111. package/src/openapi/markdown-generator.d.ts +52 -0
  112. package/src/openapi/markdown-generator.d.ts.map +1 -0
  113. package/src/openapi/markdown-generator.js +569 -0
  114. package/src/openapi/markdown-generator.js.map +1 -0
  115. package/src/openapi/middleware/index.d.ts +9 -0
  116. package/src/openapi/middleware/index.d.ts.map +1 -0
  117. package/src/openapi/middleware/index.js +15 -0
  118. package/src/openapi/middleware/index.js.map +1 -0
  119. package/src/openapi/middleware/redoc.d.ts +314 -0
  120. package/src/openapi/middleware/redoc.d.ts.map +1 -0
  121. package/src/openapi/middleware/redoc.js +181 -0
  122. package/src/openapi/middleware/redoc.js.map +1 -0
  123. package/src/openapi/middleware/swagger-ui.d.ts +123 -0
  124. package/src/openapi/middleware/swagger-ui.d.ts.map +1 -0
  125. package/src/openapi/middleware/swagger-ui.js +227 -0
  126. package/src/openapi/middleware/swagger-ui.js.map +1 -0
  127. package/src/openapi/schemas.d.ts +170 -0
  128. package/src/openapi/schemas.d.ts.map +1 -0
  129. package/src/openapi/schemas.js +340 -0
  130. package/src/openapi/schemas.js.map +1 -0
  131. package/src/registry/controller-registry.d.ts +78 -0
  132. package/src/registry/controller-registry.d.ts.map +1 -0
  133. package/src/registry/controller-registry.js +86 -0
  134. package/src/registry/controller-registry.js.map +1 -0
  135. package/src/registry/index.d.ts +2 -0
  136. package/src/registry/index.d.ts.map +1 -1
  137. package/src/registry/index.js +3 -1
  138. package/src/registry/index.js.map +1 -1
  139. package/src/routers/api.d.ts +2 -1
  140. package/src/routers/api.d.ts.map +1 -1
  141. package/src/routers/api.js +7 -1
  142. package/src/routers/api.js.map +1 -1
  143. package/src/types.d.ts +1 -0
  144. package/src/types.d.ts.map +1 -1
  145. package/src/types.js +1 -0
  146. package/src/types.js.map +1 -1
@@ -0,0 +1,192 @@
1
+ /**
2
+ * @fileoverview OpenAPI parameter decorators for Express Suite.
3
+ * Provides @ApiParam, @ApiQuery, @ApiHeader, and @ApiRequestBody decorators
4
+ * for documenting API parameters with full OpenAPI metadata.
5
+ * These decorators merge with auto-extracted parameters from @Param, @Query, @Header.
6
+ * @module decorators/openapi-params
7
+ */
8
+ import 'reflect-metadata';
9
+ import { z } from 'zod';
10
+ import { ApiParamDecoratorOptions, ApiRequestBodyDecoratorOptions } from '../interfaces/openApi/decoratorOptions';
11
+ import { OpenAPIParameter } from '../interfaces/openApi/parameter';
12
+ import { OpenAPIParameterSchema } from '../interfaces/openApi/parameterSchema';
13
+ import { OpenAPIRequestBody } from '../interfaces/openApi/requestBody';
14
+ /**
15
+ * Internal interface for stored request body metadata.
16
+ */
17
+ export interface RequestBodyMetadata {
18
+ schema: string | z.ZodSchema;
19
+ description?: string;
20
+ required?: boolean;
21
+ example?: unknown;
22
+ contentType?: string;
23
+ }
24
+ /**
25
+ * Extended OpenAPI parameter schema that supports $ref for schema references.
26
+ * This extends the base schema to allow referencing component schemas.
27
+ */
28
+ export interface ExtendedOpenAPIParameterSchema extends OpenAPIParameterSchema {
29
+ $ref?: string;
30
+ example?: unknown;
31
+ }
32
+ /**
33
+ * Extended OpenAPI parameter that supports deprecated field.
34
+ */
35
+ export interface ExtendedOpenAPIParameter extends Omit<OpenAPIParameter, 'schema'> {
36
+ schema: ExtendedOpenAPIParameterSchema;
37
+ deprecated?: boolean;
38
+ }
39
+ /**
40
+ * Decorator that documents a path parameter with full OpenAPI metadata.
41
+ * Merges with auto-extracted parameters from @Param decorator.
42
+ *
43
+ * @param name - Name of the path parameter
44
+ * @param options - OpenAPI parameter options
45
+ * @returns Method decorator
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * class UserController {
50
+ * @ApiParam('id', {
51
+ * description: 'User ID',
52
+ * schema: { type: 'string', format: 'uuid' },
53
+ * example: '123e4567-e89b-12d3-a456-426614174000'
54
+ * })
55
+ * @Get('/:id')
56
+ * getUser(@Param('id') id: string) {}
57
+ * }
58
+ * ```
59
+ */
60
+ export declare function ApiParam(name: string, options?: ApiParamDecoratorOptions): MethodDecorator;
61
+ /**
62
+ * Decorator that documents a query parameter with full OpenAPI metadata.
63
+ * Merges with auto-extracted parameters from @Query decorator.
64
+ *
65
+ * @param name - Name of the query parameter
66
+ * @param options - OpenAPI parameter options
67
+ * @returns Method decorator
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * class UserController {
72
+ * @ApiQuery('page', {
73
+ * description: 'Page number',
74
+ * schema: { type: 'integer', minimum: 1 },
75
+ * required: false,
76
+ * example: 1
77
+ * })
78
+ * @ApiQuery('limit', {
79
+ * description: 'Items per page',
80
+ * schema: { type: 'integer', minimum: 1, maximum: 100 },
81
+ * required: false
82
+ * })
83
+ * @Get('/')
84
+ * listUsers(@Query('page') page: number, @Query('limit') limit: number) {}
85
+ * }
86
+ * ```
87
+ */
88
+ export declare function ApiQuery(name: string, options?: ApiParamDecoratorOptions): MethodDecorator;
89
+ /**
90
+ * Decorator that documents a header parameter with full OpenAPI metadata.
91
+ * Merges with auto-extracted parameters from @Header decorator.
92
+ *
93
+ * @param name - Name of the header
94
+ * @param options - OpenAPI parameter options
95
+ * @returns Method decorator
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * class DataController {
100
+ * @ApiHeader('X-Request-ID', {
101
+ * description: 'Unique request identifier for tracing',
102
+ * schema: { type: 'string', format: 'uuid' },
103
+ * required: true
104
+ * })
105
+ * @ApiHeader('Accept-Language', {
106
+ * description: 'Preferred language',
107
+ * schema: { type: 'string' },
108
+ * enum: ['en', 'es', 'fr'],
109
+ * required: false
110
+ * })
111
+ * @Get('/')
112
+ * getData(@Header('X-Request-ID') requestId: string) {}
113
+ * }
114
+ * ```
115
+ */
116
+ export declare function ApiHeader(name: string, options?: ApiParamDecoratorOptions): MethodDecorator;
117
+ /**
118
+ * Decorator that documents the request body with full OpenAPI metadata.
119
+ * Supports both schema references and Zod schemas.
120
+ *
121
+ * @param options - Request body options including schema, description, required, example
122
+ * @returns Method decorator
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // With schema reference
127
+ * class UserController {
128
+ * @ApiRequestBody({
129
+ * schema: 'CreateUserDto',
130
+ * description: 'User data to create',
131
+ * required: true,
132
+ * example: { name: 'John Doe', email: 'john@example.com' }
133
+ * })
134
+ * @Post('/')
135
+ * createUser(@Body() data: CreateUserDto) {}
136
+ * }
137
+ *
138
+ * // With Zod schema
139
+ * const CreateUserSchema = z.object({
140
+ * name: z.string(),
141
+ * email: z.string().email()
142
+ * });
143
+ *
144
+ * class UserController {
145
+ * @ApiRequestBody({
146
+ * schema: CreateUserSchema,
147
+ * description: 'User data to create',
148
+ * required: true
149
+ * })
150
+ * @Post('/')
151
+ * createUser(@Body() data: z.infer<typeof CreateUserSchema>) {}
152
+ * }
153
+ * ```
154
+ */
155
+ export declare function ApiRequestBody(options: ApiRequestBodyDecoratorOptions): MethodDecorator;
156
+ /**
157
+ * Gets all OpenAPI parameter definitions for a method.
158
+ * Returns parameters from both @ApiParam/@ApiQuery/@ApiHeader decorators
159
+ * and auto-extracted parameters from @Param/@Query/@Header decorators.
160
+ *
161
+ * @param target - The class constructor
162
+ * @param propertyKey - The method name
163
+ * @returns Array of OpenAPI parameter definitions
164
+ */
165
+ export declare function getOpenAPIParams(target: object, propertyKey: string | symbol): ExtendedOpenAPIParameter[];
166
+ /**
167
+ * Gets the request body metadata for a method.
168
+ *
169
+ * @param target - The class constructor
170
+ * @param propertyKey - The method name
171
+ * @returns Request body metadata or undefined
172
+ */
173
+ export declare function getRequestBodyMetadata(target: object, propertyKey: string | symbol): RequestBodyMetadata | undefined;
174
+ /**
175
+ * Converts request body metadata to OpenAPI request body definition.
176
+ * Handles both schema references and Zod schemas.
177
+ *
178
+ * @param metadata - Request body metadata
179
+ * @returns OpenAPI request body definition
180
+ */
181
+ export declare function requestBodyMetadataToOpenAPI(metadata: RequestBodyMetadata): OpenAPIRequestBody;
182
+ /**
183
+ * Merges OpenAPI parameters from multiple sources.
184
+ * Parameters from explicit @ApiParam/@ApiQuery/@ApiHeader decorators
185
+ * take precedence over auto-extracted parameters.
186
+ *
187
+ * @param autoExtracted - Parameters auto-extracted from @Param/@Query/@Header
188
+ * @param explicit - Parameters from @ApiParam/@ApiQuery/@ApiHeader
189
+ * @returns Merged parameters array
190
+ */
191
+ export declare function mergeOpenAPIParameters(autoExtracted: ExtendedOpenAPIParameter[], explicit: ExtendedOpenAPIParameter[]): ExtendedOpenAPIParameter[];
192
+ //# sourceMappingURL=openapi-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi-params.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/openapi-params.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC/B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,gBAAgB,EAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAOvE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,8BAA+B,SAAQ,sBAAsB;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,gBAAgB,EAChB,QAAQ,CACT;IACC,MAAM,EAAE,8BAA8B,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA2GD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACrC,eAAe,CAqBjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACrC,eAAe,CAqBjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACrC,eAAe,CAqBjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,8BAA8B,GACtC,eAAe,CAmBjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,wBAAwB,EAAE,CAO5B;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,mBAAmB,GAAG,SAAS,CAOjC;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,mBAAmB,GAC5B,kBAAkB,CAiCpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,wBAAwB,EAAE,EACzC,QAAQ,EAAE,wBAAwB,EAAE,GACnC,wBAAwB,EAAE,CAQ5B"}
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview OpenAPI parameter decorators for Express Suite.
4
+ * Provides @ApiParam, @ApiQuery, @ApiHeader, and @ApiRequestBody decorators
5
+ * for documenting API parameters with full OpenAPI metadata.
6
+ * These decorators merge with auto-extracted parameters from @Param, @Query, @Header.
7
+ * @module decorators/openapi-params
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ApiParam = ApiParam;
11
+ exports.ApiQuery = ApiQuery;
12
+ exports.ApiHeader = ApiHeader;
13
+ exports.ApiRequestBody = ApiRequestBody;
14
+ exports.getOpenAPIParams = getOpenAPIParams;
15
+ exports.getRequestBodyMetadata = getRequestBodyMetadata;
16
+ exports.requestBodyMetadataToOpenAPI = requestBodyMetadataToOpenAPI;
17
+ exports.mergeOpenAPIParameters = mergeOpenAPIParameters;
18
+ require("reflect-metadata");
19
+ const zod_1 = require("zod");
20
+ const metadata_keys_1 = require("./metadata-keys");
21
+ const metadata_collector_1 = require("./metadata-collector");
22
+ /**
23
+ * Converts ApiParamDecoratorOptions to ExtendedOpenAPIParameterSchema.
24
+ * Handles both string references and inline schemas.
25
+ * @param options - The decorator options
26
+ * @returns OpenAPI parameter schema
27
+ */
28
+ function optionsToSchema(options) {
29
+ if (options.schema) {
30
+ if (typeof options.schema === 'string') {
31
+ // Schema reference - create a schema with $ref
32
+ return { type: 'string', $ref: `#/components/schemas/${options.schema}` };
33
+ }
34
+ // Inline schema - return as-is with extended type
35
+ return options.schema;
36
+ }
37
+ // Build schema from options
38
+ const schema = { type: 'string' };
39
+ if (options.enum) {
40
+ schema.enum = options.enum;
41
+ }
42
+ return schema;
43
+ }
44
+ /**
45
+ * Creates an OpenAPI parameter from decorator options.
46
+ * @param name - Parameter name
47
+ * @param location - Parameter location (path, query, header)
48
+ * @param options - Decorator options
49
+ * @returns OpenAPI parameter definition
50
+ */
51
+ function createOpenAPIParameter(name, location, options) {
52
+ const schema = optionsToSchema(options);
53
+ // Add example to schema if provided
54
+ if (options.example !== undefined) {
55
+ schema.example = options.example;
56
+ }
57
+ const param = {
58
+ name,
59
+ in: location,
60
+ schema,
61
+ };
62
+ // Path parameters are always required
63
+ if (location === 'path') {
64
+ param.required = true;
65
+ }
66
+ else if (options.required !== undefined) {
67
+ param.required = options.required;
68
+ }
69
+ if (options.description) {
70
+ param.description = options.description;
71
+ }
72
+ if (options.deprecated) {
73
+ param.deprecated = options.deprecated;
74
+ }
75
+ return param;
76
+ }
77
+ /**
78
+ * Merges a new parameter with existing parameters.
79
+ * If a parameter with the same name and location exists, it's updated.
80
+ * Otherwise, the new parameter is added.
81
+ * @param existing - Existing parameters array
82
+ * @param newParam - New parameter to merge
83
+ * @returns Updated parameters array
84
+ */
85
+ function mergeParameter(existing, newParam) {
86
+ const result = [...existing];
87
+ const existingIndex = result.findIndex((p) => p.name === newParam.name && p.in === newParam.in);
88
+ if (existingIndex >= 0) {
89
+ // Merge with existing parameter - new values override
90
+ result[existingIndex] = {
91
+ ...result[existingIndex],
92
+ ...newParam,
93
+ schema: {
94
+ ...result[existingIndex].schema,
95
+ ...newParam.schema,
96
+ },
97
+ };
98
+ }
99
+ else {
100
+ result.push(newParam);
101
+ }
102
+ return result;
103
+ }
104
+ /**
105
+ * Decorator that documents a path parameter with full OpenAPI metadata.
106
+ * Merges with auto-extracted parameters from @Param decorator.
107
+ *
108
+ * @param name - Name of the path parameter
109
+ * @param options - OpenAPI parameter options
110
+ * @returns Method decorator
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * class UserController {
115
+ * @ApiParam('id', {
116
+ * description: 'User ID',
117
+ * schema: { type: 'string', format: 'uuid' },
118
+ * example: '123e4567-e89b-12d3-a456-426614174000'
119
+ * })
120
+ * @Get('/:id')
121
+ * getUser(@Param('id') id: string) {}
122
+ * }
123
+ * ```
124
+ */
125
+ function ApiParam(name, options = {}) {
126
+ return (target, propertyKey, descriptor) => {
127
+ const existingParams = (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.OPENAPI_PARAMS_METADATA, target.constructor, propertyKey, []);
128
+ const newParam = createOpenAPIParameter(name, 'path', options);
129
+ const mergedParams = mergeParameter(existingParams, newParam);
130
+ (0, metadata_collector_1.setMetadata)(metadata_keys_1.OPENAPI_PARAMS_METADATA, mergedParams, target.constructor, propertyKey);
131
+ return descriptor;
132
+ };
133
+ }
134
+ /**
135
+ * Decorator that documents a query parameter with full OpenAPI metadata.
136
+ * Merges with auto-extracted parameters from @Query decorator.
137
+ *
138
+ * @param name - Name of the query parameter
139
+ * @param options - OpenAPI parameter options
140
+ * @returns Method decorator
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * class UserController {
145
+ * @ApiQuery('page', {
146
+ * description: 'Page number',
147
+ * schema: { type: 'integer', minimum: 1 },
148
+ * required: false,
149
+ * example: 1
150
+ * })
151
+ * @ApiQuery('limit', {
152
+ * description: 'Items per page',
153
+ * schema: { type: 'integer', minimum: 1, maximum: 100 },
154
+ * required: false
155
+ * })
156
+ * @Get('/')
157
+ * listUsers(@Query('page') page: number, @Query('limit') limit: number) {}
158
+ * }
159
+ * ```
160
+ */
161
+ function ApiQuery(name, options = {}) {
162
+ return (target, propertyKey, descriptor) => {
163
+ const existingParams = (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.OPENAPI_PARAMS_METADATA, target.constructor, propertyKey, []);
164
+ const newParam = createOpenAPIParameter(name, 'query', options);
165
+ const mergedParams = mergeParameter(existingParams, newParam);
166
+ (0, metadata_collector_1.setMetadata)(metadata_keys_1.OPENAPI_PARAMS_METADATA, mergedParams, target.constructor, propertyKey);
167
+ return descriptor;
168
+ };
169
+ }
170
+ /**
171
+ * Decorator that documents a header parameter with full OpenAPI metadata.
172
+ * Merges with auto-extracted parameters from @Header decorator.
173
+ *
174
+ * @param name - Name of the header
175
+ * @param options - OpenAPI parameter options
176
+ * @returns Method decorator
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * class DataController {
181
+ * @ApiHeader('X-Request-ID', {
182
+ * description: 'Unique request identifier for tracing',
183
+ * schema: { type: 'string', format: 'uuid' },
184
+ * required: true
185
+ * })
186
+ * @ApiHeader('Accept-Language', {
187
+ * description: 'Preferred language',
188
+ * schema: { type: 'string' },
189
+ * enum: ['en', 'es', 'fr'],
190
+ * required: false
191
+ * })
192
+ * @Get('/')
193
+ * getData(@Header('X-Request-ID') requestId: string) {}
194
+ * }
195
+ * ```
196
+ */
197
+ function ApiHeader(name, options = {}) {
198
+ return (target, propertyKey, descriptor) => {
199
+ const existingParams = (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.OPENAPI_PARAMS_METADATA, target.constructor, propertyKey, []);
200
+ const newParam = createOpenAPIParameter(name, 'header', options);
201
+ const mergedParams = mergeParameter(existingParams, newParam);
202
+ (0, metadata_collector_1.setMetadata)(metadata_keys_1.OPENAPI_PARAMS_METADATA, mergedParams, target.constructor, propertyKey);
203
+ return descriptor;
204
+ };
205
+ }
206
+ /**
207
+ * Decorator that documents the request body with full OpenAPI metadata.
208
+ * Supports both schema references and Zod schemas.
209
+ *
210
+ * @param options - Request body options including schema, description, required, example
211
+ * @returns Method decorator
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * // With schema reference
216
+ * class UserController {
217
+ * @ApiRequestBody({
218
+ * schema: 'CreateUserDto',
219
+ * description: 'User data to create',
220
+ * required: true,
221
+ * example: { name: 'John Doe', email: 'john@example.com' }
222
+ * })
223
+ * @Post('/')
224
+ * createUser(@Body() data: CreateUserDto) {}
225
+ * }
226
+ *
227
+ * // With Zod schema
228
+ * const CreateUserSchema = z.object({
229
+ * name: z.string(),
230
+ * email: z.string().email()
231
+ * });
232
+ *
233
+ * class UserController {
234
+ * @ApiRequestBody({
235
+ * schema: CreateUserSchema,
236
+ * description: 'User data to create',
237
+ * required: true
238
+ * })
239
+ * @Post('/')
240
+ * createUser(@Body() data: z.infer<typeof CreateUserSchema>) {}
241
+ * }
242
+ * ```
243
+ */
244
+ function ApiRequestBody(options) {
245
+ return (target, propertyKey, descriptor) => {
246
+ const metadata = {
247
+ schema: options.schema,
248
+ description: options.description,
249
+ required: options.required ?? true,
250
+ example: options.example,
251
+ contentType: options.contentType ?? 'application/json',
252
+ };
253
+ (0, metadata_collector_1.setMetadata)(metadata_keys_1.OPENAPI_REQUEST_BODY_METADATA, metadata, target.constructor, propertyKey);
254
+ return descriptor;
255
+ };
256
+ }
257
+ /**
258
+ * Gets all OpenAPI parameter definitions for a method.
259
+ * Returns parameters from both @ApiParam/@ApiQuery/@ApiHeader decorators
260
+ * and auto-extracted parameters from @Param/@Query/@Header decorators.
261
+ *
262
+ * @param target - The class constructor
263
+ * @param propertyKey - The method name
264
+ * @returns Array of OpenAPI parameter definitions
265
+ */
266
+ function getOpenAPIParams(target, propertyKey) {
267
+ return (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.OPENAPI_PARAMS_METADATA, target, propertyKey, []);
268
+ }
269
+ /**
270
+ * Gets the request body metadata for a method.
271
+ *
272
+ * @param target - The class constructor
273
+ * @param propertyKey - The method name
274
+ * @returns Request body metadata or undefined
275
+ */
276
+ function getRequestBodyMetadata(target, propertyKey) {
277
+ return (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.OPENAPI_REQUEST_BODY_METADATA, target, propertyKey, undefined);
278
+ }
279
+ /**
280
+ * Converts request body metadata to OpenAPI request body definition.
281
+ * Handles both schema references and Zod schemas.
282
+ *
283
+ * @param metadata - Request body metadata
284
+ * @returns OpenAPI request body definition
285
+ */
286
+ function requestBodyMetadataToOpenAPI(metadata) {
287
+ let schemaName;
288
+ if (typeof metadata.schema === 'string') {
289
+ // Schema reference - use directly
290
+ schemaName = metadata.schema;
291
+ }
292
+ else if (metadata.schema instanceof zod_1.z.ZodType) {
293
+ // Zod schema - we need to generate a schema name
294
+ // The actual schema conversion should be handled by the OpenAPI builder
295
+ // For now, we use a placeholder that indicates it's a Zod schema
296
+ schemaName = 'ZodSchema';
297
+ }
298
+ else {
299
+ // Fallback
300
+ schemaName = 'Object';
301
+ }
302
+ const requestBody = {
303
+ schema: schemaName,
304
+ };
305
+ if (metadata.description) {
306
+ requestBody.description = metadata.description;
307
+ }
308
+ if (metadata.required !== undefined) {
309
+ requestBody.required = metadata.required;
310
+ }
311
+ if (metadata.example !== undefined) {
312
+ requestBody.example = metadata.example;
313
+ }
314
+ return requestBody;
315
+ }
316
+ /**
317
+ * Merges OpenAPI parameters from multiple sources.
318
+ * Parameters from explicit @ApiParam/@ApiQuery/@ApiHeader decorators
319
+ * take precedence over auto-extracted parameters.
320
+ *
321
+ * @param autoExtracted - Parameters auto-extracted from @Param/@Query/@Header
322
+ * @param explicit - Parameters from @ApiParam/@ApiQuery/@ApiHeader
323
+ * @returns Merged parameters array
324
+ */
325
+ function mergeOpenAPIParameters(autoExtracted, explicit) {
326
+ let result = [...autoExtracted];
327
+ for (const param of explicit) {
328
+ result = mergeParameter(result, param);
329
+ }
330
+ return result;
331
+ }
332
+ //# sourceMappingURL=openapi-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi-params.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/openapi-params.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAiLH,4BAwBC;AA6BD,4BAwBC;AA6BD,8BAwBC;AAwCD,wCAqBC;AAWD,4CAUC;AASD,wDAUC;AASD,oEAmCC;AAWD,wDAWC;AAxdD,4BAA0B;AAC1B,6BAAwB;AAWxB,mDAGyB;AACzB,6DAAyE;AAiCzE;;;;;GAKG;AACH,SAAS,eAAe,CACtB,OAAiC;IAEjC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACvC,+CAA+C;YAC/C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,wBAAwB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5E,CAAC;QACD,kDAAkD;QAClD,OAAO,OAAO,CAAC,MAAwC,CAAC;IAC1D,CAAC;IAED,4BAA4B;IAC5B,MAAM,MAAM,GAAmC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAElE,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,sBAAsB,CAC7B,IAAY,EACZ,QAAkC,EAClC,OAAiC;IAEjC,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAExC,oCAAoC;IACpC,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,CAAC,OAAO,GAAG,OAAO,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