@tsoa-next/runtime 7.1.0 → 7.3.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 (65) hide show
  1. package/README.MD +8 -2
  2. package/dist/config.d.ts +11 -4
  3. package/dist/decorators/example.d.ts +1 -1
  4. package/dist/decorators/example.js +1 -1
  5. package/dist/decorators/example.js.map +1 -1
  6. package/dist/decorators/methods.d.ts +7 -7
  7. package/dist/decorators/methods.js +7 -7
  8. package/dist/decorators/methods.js.map +1 -1
  9. package/dist/decorators/middlewares.d.ts +2 -1
  10. package/dist/decorators/middlewares.js +9 -6
  11. package/dist/decorators/middlewares.js.map +1 -1
  12. package/dist/decorators/operationid.d.ts +1 -1
  13. package/dist/decorators/operationid.js +1 -1
  14. package/dist/decorators/operationid.js.map +1 -1
  15. package/dist/decorators/parameter.d.ts +9 -9
  16. package/dist/decorators/parameter.js +9 -9
  17. package/dist/decorators/parameter.js.map +1 -1
  18. package/dist/decorators/response.d.ts +3 -3
  19. package/dist/decorators/response.js +3 -3
  20. package/dist/decorators/response.js.map +1 -1
  21. package/dist/decorators/route.d.ts +1 -1
  22. package/dist/decorators/route.js +1 -1
  23. package/dist/decorators/route.js.map +1 -1
  24. package/dist/decorators/security.d.ts +2 -2
  25. package/dist/decorators/security.js +1 -1
  26. package/dist/decorators/security.js.map +1 -1
  27. package/dist/decorators/tags.d.ts +1 -1
  28. package/dist/decorators/tags.js +1 -1
  29. package/dist/decorators/tags.js.map +1 -1
  30. package/dist/decorators/validate.d.ts +9 -0
  31. package/dist/decorators/validate.js +112 -0
  32. package/dist/decorators/validate.js.map +1 -0
  33. package/dist/index.d.ts +13 -11
  34. package/dist/index.js +13 -11
  35. package/dist/index.js.map +1 -1
  36. package/dist/interfaces/iocModule.d.ts +4 -2
  37. package/dist/interfaces/response.d.ts +1 -1
  38. package/dist/metadataGeneration/tsoa.d.ts +41 -9
  39. package/dist/routeGeneration/additionalProps.d.ts +2 -0
  40. package/dist/routeGeneration/externalValidation.d.ts +13 -0
  41. package/dist/routeGeneration/externalValidation.js +232 -0
  42. package/dist/routeGeneration/externalValidation.js.map +1 -0
  43. package/dist/routeGeneration/templateHelpers.d.ts +98 -21
  44. package/dist/routeGeneration/templateHelpers.js +305 -113
  45. package/dist/routeGeneration/templateHelpers.js.map +1 -1
  46. package/dist/routeGeneration/templates/express/expressTemplateService.d.ts +8 -4
  47. package/dist/routeGeneration/templates/express/expressTemplateService.js +32 -15
  48. package/dist/routeGeneration/templates/express/expressTemplateService.js.map +1 -1
  49. package/dist/routeGeneration/templates/hapi/hapiTemplateService.d.ts +22 -8
  50. package/dist/routeGeneration/templates/hapi/hapiTemplateService.js +67 -19
  51. package/dist/routeGeneration/templates/hapi/hapiTemplateService.js.map +1 -1
  52. package/dist/routeGeneration/templates/index.d.ts +1 -1
  53. package/dist/routeGeneration/templates/index.js +1 -1
  54. package/dist/routeGeneration/templates/index.js.map +1 -1
  55. package/dist/routeGeneration/templates/koa/koaTemplateService.d.ts +15 -6
  56. package/dist/routeGeneration/templates/koa/koaTemplateService.js +63 -22
  57. package/dist/routeGeneration/templates/koa/koaTemplateService.js.map +1 -1
  58. package/dist/routeGeneration/templates/templateService.d.ts +9 -4
  59. package/dist/routeGeneration/templates/templateService.js +39 -1
  60. package/dist/routeGeneration/templates/templateService.js.map +1 -1
  61. package/dist/routeGeneration/tsoa-route.d.ts +5 -0
  62. package/dist/swagger/swagger.d.ts +42 -41
  63. package/dist/swagger/swagger.js +4 -0
  64. package/dist/swagger/swagger.js.map +1 -1
  65. package/package.json +35 -6
package/dist/index.d.ts CHANGED
@@ -1,24 +1,26 @@
1
1
  import 'reflect-metadata';
2
+ export * from './config';
2
3
  export * from './decorators/deprecated';
3
4
  export * from './decorators/example';
4
- export * from './decorators/parameter';
5
+ export * from './decorators/extension';
5
6
  export * from './decorators/methods';
6
- export * from './decorators/tags';
7
+ export * from './decorators/middlewares';
7
8
  export * from './decorators/operationid';
9
+ export * from './decorators/parameter';
10
+ export * from './decorators/response';
8
11
  export * from './decorators/route';
9
12
  export * from './decorators/security';
10
- export * from './decorators/extension';
11
- export * from './decorators/middlewares';
13
+ export * from './decorators/tags';
14
+ export * from './decorators/validate';
12
15
  export * from './interfaces/controller';
13
- export * from './interfaces/response';
14
- export * from './interfaces/iocModule';
15
16
  export * from './interfaces/file';
16
- export * from './decorators/response';
17
+ export * from './interfaces/iocModule';
18
+ export * from './interfaces/response';
17
19
  export * from './metadataGeneration/tsoa';
18
- export * from './routeGeneration/templates';
20
+ export * from './routeGeneration/additionalProps';
21
+ export * from './routeGeneration/externalValidation';
19
22
  export * from './routeGeneration/templateHelpers';
23
+ export * from './routeGeneration/templates';
20
24
  export * from './routeGeneration/tsoa-route';
21
- export * from './utils/assertNever';
22
25
  export * from './swagger/swagger';
23
- export * from './config';
24
- export * from './routeGeneration/additionalProps';
26
+ export * from './utils/assertNever';
package/dist/index.js CHANGED
@@ -15,27 +15,29 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  require("reflect-metadata");
18
+ __exportStar(require("./config"), exports);
18
19
  __exportStar(require("./decorators/deprecated"), exports);
19
20
  __exportStar(require("./decorators/example"), exports);
20
- __exportStar(require("./decorators/parameter"), exports);
21
+ __exportStar(require("./decorators/extension"), exports);
21
22
  __exportStar(require("./decorators/methods"), exports);
22
- __exportStar(require("./decorators/tags"), exports);
23
+ __exportStar(require("./decorators/middlewares"), exports);
23
24
  __exportStar(require("./decorators/operationid"), exports);
25
+ __exportStar(require("./decorators/parameter"), exports);
26
+ __exportStar(require("./decorators/response"), exports);
24
27
  __exportStar(require("./decorators/route"), exports);
25
28
  __exportStar(require("./decorators/security"), exports);
26
- __exportStar(require("./decorators/extension"), exports);
27
- __exportStar(require("./decorators/middlewares"), exports);
29
+ __exportStar(require("./decorators/tags"), exports);
30
+ __exportStar(require("./decorators/validate"), exports);
28
31
  __exportStar(require("./interfaces/controller"), exports);
29
- __exportStar(require("./interfaces/response"), exports);
30
- __exportStar(require("./interfaces/iocModule"), exports);
31
32
  __exportStar(require("./interfaces/file"), exports);
32
- __exportStar(require("./decorators/response"), exports);
33
+ __exportStar(require("./interfaces/iocModule"), exports);
34
+ __exportStar(require("./interfaces/response"), exports);
33
35
  __exportStar(require("./metadataGeneration/tsoa"), exports);
34
- __exportStar(require("./routeGeneration/templates"), exports);
36
+ __exportStar(require("./routeGeneration/additionalProps"), exports);
37
+ __exportStar(require("./routeGeneration/externalValidation"), exports);
35
38
  __exportStar(require("./routeGeneration/templateHelpers"), exports);
39
+ __exportStar(require("./routeGeneration/templates"), exports);
36
40
  __exportStar(require("./routeGeneration/tsoa-route"), exports);
37
- __exportStar(require("./utils/assertNever"), exports);
38
41
  __exportStar(require("./swagger/swagger"), exports);
39
- __exportStar(require("./config"), exports);
40
- __exportStar(require("./routeGeneration/additionalProps"), exports);
42
+ __exportStar(require("./utils/assertNever"), exports);
41
43
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,0DAAuC;AACvC,uDAAoC;AACpC,yDAAsC;AACtC,uDAAoC;AACpC,oDAAiC;AACjC,2DAAwC;AACxC,qDAAkC;AAClC,wDAAqC;AACrC,yDAAsC;AACtC,2DAAwC;AACxC,0DAAuC;AACvC,wDAAqC;AACrC,yDAAsC;AACtC,oDAAiC;AACjC,wDAAqC;AACrC,4DAAyC;AACzC,8DAA2C;AAC3C,oEAAiD;AACjD,+DAA4C;AAC5C,sDAAmC;AACnC,oDAAiC;AACjC,2CAAwB;AACxB,oEAAiD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,2CAAwB;AACxB,0DAAuC;AACvC,uDAAoC;AACpC,yDAAsC;AACtC,uDAAoC;AACpC,2DAAwC;AACxC,2DAAwC;AACxC,yDAAsC;AACtC,wDAAqC;AACrC,qDAAkC;AAClC,wDAAqC;AACrC,oDAAiC;AACjC,wDAAqC;AACrC,0DAAuC;AACvC,oDAAiC;AACjC,yDAAsC;AACtC,wDAAqC;AACrC,4DAAyC;AACzC,oEAAiD;AACjD,uEAAoD;AACpD,oEAAiD;AACjD,8DAA2C;AAC3C,+DAA4C;AAC5C,oDAAiC;AACjC,sDAAmC"}
@@ -1,7 +1,9 @@
1
- export type Newable<T = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => T;
1
+ export type Newable<T = unknown, TArgs extends unknown[] = unknown[]> = new (...args: TArgs) => T;
2
2
  export type ServiceIdentifier<T = unknown> = string | symbol | Newable<T> | Function;
3
3
  export interface IocContainer {
4
4
  get<T>(controller: ServiceIdentifier<T>): T;
5
5
  get<T>(controller: ServiceIdentifier<T>): Promise<T>;
6
6
  }
7
- export type IocContainerFactory<T = any> = (request: T) => IocContainer;
7
+ export type IocContainerFactory<T = unknown> = {
8
+ bivarianceHack(request: T): IocContainer;
9
+ }['bivarianceHack'];
@@ -2,4 +2,4 @@ import { IsValidHeader } from '../utils/isHeaderType';
2
2
  export type HttpStatusCodeLiteral = 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
3
3
  export type HttpStatusCodeStringLiteral = `${HttpStatusCodeLiteral}`;
4
4
  export type OtherValidOpenApiHttpStatusCode = '1XX' | '2XX' | '3XX' | '4XX' | '5XX' | 'default';
5
- export type TsoaResponse<T extends HttpStatusCodeLiteral, BodyType, HeaderType extends IsValidHeader<HeaderType> = object> = (status: T, data: BodyType, headers?: HeaderType) => any;
5
+ export type TsoaResponse<T extends HttpStatusCodeLiteral, BodyType, HeaderType extends IsValidHeader<HeaderType> = object, ReturnType = never> = (status: T, data: BodyType, headers?: HeaderType) => ReturnType;
@@ -2,6 +2,34 @@ import { ExtensionType } from '../decorators/extension';
2
2
  import type { Swagger } from '../swagger/swagger';
3
3
  import { Validator } from '..';
4
4
  export declare namespace Tsoa {
5
+ export type ExternalValidatorKind = 'zod' | 'joi' | 'yup' | 'superstruct' | 'io-ts';
6
+ export type ValidationStrategy = 'standard' | 'external';
7
+ export interface ExternalValidatorDescriptor {
8
+ kind: ExternalValidatorKind;
9
+ strategy: 'external';
10
+ }
11
+ export interface ValidationIssue {
12
+ path: string;
13
+ code: string;
14
+ message?: string;
15
+ messageKey?: string;
16
+ messageParams?: Record<string, unknown>;
17
+ source: 'tsoa' | ExternalValidatorKind;
18
+ raw?: unknown;
19
+ }
20
+ export interface ValidationFailure {
21
+ summaryMessage: string;
22
+ issues: ValidationIssue[];
23
+ source: ValidationIssue['source'];
24
+ }
25
+ export interface ValidationContext {
26
+ locale?: string;
27
+ translate?: (key: string, params?: Record<string, unknown>) => string;
28
+ errorFormatter?: (failure: ValidationFailure) => ValidationFailure;
29
+ }
30
+ export type Example = string | number | boolean | null | undefined | Date | Example[] | {
31
+ [exampleName: string]: Example;
32
+ };
5
33
  export interface Metadata {
6
34
  controllers: Controller[];
7
35
  referenceTypeMap: ReferenceTypeMap;
@@ -33,10 +61,9 @@ export declare namespace Tsoa {
33
61
  operationId?: string;
34
62
  }
35
63
  export interface Parameter {
64
+ parameterIndex?: number;
36
65
  parameterName: string;
37
- example?: Array<{
38
- [exampleName: string]: Swagger.Example3;
39
- }>;
66
+ example?: Example[];
40
67
  description?: string;
41
68
  in: 'query' | 'queries' | 'header' | 'path' | 'formData' | 'body' | 'body-prop' | 'request' | 'request-prop' | 'res';
42
69
  name: string;
@@ -44,20 +71,27 @@ export declare namespace Tsoa {
44
71
  type: Type;
45
72
  default?: unknown;
46
73
  validators: Validators;
74
+ validationStrategy?: ValidationStrategy;
75
+ externalValidator?: ExternalValidatorDescriptor;
47
76
  deprecated: boolean;
48
77
  exampleLabels?: Array<string | undefined>;
49
78
  title?: string;
50
79
  $ref?: Swagger.BaseSchema;
51
80
  }
52
- export interface ResParameter extends Response, Parameter {
81
+ export interface ResParameter extends Parameter {
53
82
  in: 'res';
54
83
  description: string;
84
+ produces?: string[];
85
+ schema?: Type;
86
+ examples?: Example[];
87
+ exampleLabels?: Array<string | undefined>;
88
+ headers?: HeaderType;
55
89
  }
56
90
  export interface ArrayParameter extends Parameter {
57
91
  type: ArrayType;
58
92
  collectionFormat?: 'csv' | 'multi' | 'pipes' | 'ssv' | 'tsv';
59
93
  }
60
- type AllKeys<T> = T extends any ? keyof T : never;
94
+ type AllKeys<T> = T extends unknown ? keyof T : never;
61
95
  export type ValidatorKey = AllKeys<Validator>;
62
96
  export type SchemaValidatorKey = Exclude<ValidatorKey, `is${string}` | 'minDate' | 'maxDate'>;
63
97
  export type Validators = Partial<Record<ValidatorKey, {
@@ -73,12 +107,10 @@ export declare namespace Tsoa {
73
107
  }
74
108
  export interface Response {
75
109
  description: string;
76
- name: string;
110
+ name: string | number;
77
111
  produces?: string[];
78
112
  schema?: Type;
79
- examples?: Array<{
80
- [exampleName: string]: Swagger.Example3;
81
- }>;
113
+ examples?: Example[];
82
114
  exampleLabels?: Array<string | undefined>;
83
115
  headers?: HeaderType;
84
116
  }
@@ -1,6 +1,8 @@
1
1
  import { Config, RoutesConfig } from '../config';
2
+ import type { Tsoa } from '../metadataGeneration/tsoa';
2
3
  export interface AdditionalProps {
3
4
  noImplicitAdditionalProperties: Exclude<Config['noImplicitAdditionalProperties'], undefined>;
4
5
  bodyCoercion: Exclude<RoutesConfig['bodyCoercion'], undefined>;
5
6
  maxValidationErrorSize?: number;
7
+ validation?: Tsoa.ValidationContext;
6
8
  }
@@ -0,0 +1,13 @@
1
+ import type { Tsoa } from '../metadataGeneration/tsoa';
2
+ export type RuntimeSchemaAdapterResult<T = unknown> = {
3
+ ok: true;
4
+ value: T;
5
+ } | {
6
+ ok: false;
7
+ failure: Tsoa.ValidationFailure;
8
+ };
9
+ export interface RuntimeSchemaAdapter {
10
+ kind: Tsoa.ExternalValidatorKind;
11
+ validate(value: unknown, schema: unknown, context: Tsoa.ValidationContext): RuntimeSchemaAdapterResult;
12
+ }
13
+ export declare function validateExternalSchema(kind: Tsoa.ExternalValidatorKind, schema: unknown, value: unknown, context?: Tsoa.ValidationContext): RuntimeSchemaAdapterResult;
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateExternalSchema = validateExternalSchema;
4
+ let superstructModule;
5
+ function isMissingOptionalModuleError(error) {
6
+ return error instanceof Error && error.code === 'MODULE_NOT_FOUND';
7
+ }
8
+ function loadOptionalModule(moduleName) {
9
+ let resolvedModuleName;
10
+ try {
11
+ resolvedModuleName = require.resolve(moduleName);
12
+ }
13
+ catch (error) {
14
+ if (!isMissingOptionalModuleError(error)) {
15
+ throw error;
16
+ }
17
+ throw new Error(`External validator '${moduleName}' is not installed. Install it in your application to use @Validate with that schema kind.`);
18
+ }
19
+ return require(resolvedModuleName);
20
+ }
21
+ function normalizePath(input) {
22
+ if (!Array.isArray(input)) {
23
+ return typeof input === 'string' ? input : '';
24
+ }
25
+ return input
26
+ .filter(segment => segment !== undefined && segment !== null && segment !== '')
27
+ .map(segment => (typeof segment === 'number' ? `$${segment}` : String(segment)))
28
+ .join('.');
29
+ }
30
+ function normalizeJoiPath(input) {
31
+ if (!Array.isArray(input)) {
32
+ return typeof input === 'string' ? input : '';
33
+ }
34
+ return input.map(segment => (typeof segment === 'number' ? `$${segment}` : String(segment))).join('.');
35
+ }
36
+ function maybeMessageKey(message) {
37
+ if (typeof message !== 'string' || message.length === 0) {
38
+ return undefined;
39
+ }
40
+ return /^[A-Za-z0-9_.-]+$/.test(message) && message.includes('.') ? message : undefined;
41
+ }
42
+ function finalizeFailure(failure, context) {
43
+ const translatedIssues = failure.issues.map(issue => {
44
+ const messageKey = issue.messageKey || maybeMessageKey(issue.message);
45
+ const translatedMessage = messageKey && context.translate ? context.translate(messageKey, issue.messageParams) : issue.message;
46
+ return {
47
+ ...issue,
48
+ ...(messageKey ? { messageKey } : {}),
49
+ ...(translatedMessage ? { message: translatedMessage } : {}),
50
+ };
51
+ });
52
+ const translatedFailure = {
53
+ ...failure,
54
+ issues: translatedIssues,
55
+ summaryMessage: translatedIssues.find(issue => issue.message)?.message || failure.summaryMessage,
56
+ };
57
+ return context.errorFormatter ? context.errorFormatter(translatedFailure) : translatedFailure;
58
+ }
59
+ function buildFailure(source, issues, fallbackSummary, context) {
60
+ return finalizeFailure({
61
+ source,
62
+ issues,
63
+ summaryMessage: issues.find(issue => issue.message)?.message || fallbackSummary,
64
+ }, context);
65
+ }
66
+ const zodAdapter = {
67
+ kind: 'zod',
68
+ validate(value, schema, context) {
69
+ const zodSchema = schema;
70
+ if (typeof zodSchema.safeParse !== 'function') {
71
+ throw new TypeError('Expected a Zod schema with safeParse().');
72
+ }
73
+ const result = zodSchema.safeParse(value);
74
+ if (result.success) {
75
+ return { ok: true, value: result.data };
76
+ }
77
+ const issues = (result.error?.issues || []).map(issue => {
78
+ const entry = issue;
79
+ return {
80
+ path: normalizePath(entry.path),
81
+ code: typeof entry.code === 'string' ? entry.code : 'invalid',
82
+ message: typeof entry.message === 'string' ? entry.message : undefined,
83
+ source: 'zod',
84
+ raw: issue,
85
+ };
86
+ });
87
+ return { ok: false, failure: buildFailure('zod', issues, 'Zod validation failed.', context) };
88
+ },
89
+ };
90
+ const joiAdapter = {
91
+ kind: 'joi',
92
+ validate(value, schema, context) {
93
+ const joiSchema = schema;
94
+ if (typeof joiSchema.validate !== 'function') {
95
+ throw new TypeError('Expected a Joi schema with validate().');
96
+ }
97
+ const result = joiSchema.validate(value, { abortEarly: false });
98
+ if (!result.error) {
99
+ return { ok: true, value: result.value };
100
+ }
101
+ const issues = (result.error.details || []).map(detail => {
102
+ const entry = detail;
103
+ return {
104
+ path: normalizeJoiPath(entry.path),
105
+ code: typeof entry.type === 'string' ? entry.type : 'invalid',
106
+ message: typeof entry.message === 'string' ? entry.message : undefined,
107
+ messageParams: entry.context,
108
+ source: 'joi',
109
+ raw: detail,
110
+ };
111
+ });
112
+ return { ok: false, failure: buildFailure('joi', issues, 'Joi validation failed.', context) };
113
+ },
114
+ };
115
+ const yupAdapter = {
116
+ kind: 'yup',
117
+ validate(value, schema, context) {
118
+ const yupSchema = schema;
119
+ if (typeof yupSchema.validateSync !== 'function') {
120
+ throw new TypeError('Expected a Yup schema with validateSync().');
121
+ }
122
+ try {
123
+ return { ok: true, value: yupSchema.validateSync(value, { abortEarly: false }) };
124
+ }
125
+ catch (error) {
126
+ const validationError = error;
127
+ const errors = validationError.inner && validationError.inner.length > 0 ? validationError.inner : [validationError];
128
+ const issues = errors.map(entry => {
129
+ const yupEntry = entry;
130
+ return {
131
+ path: typeof yupEntry.path === 'string' ? yupEntry.path : '',
132
+ code: typeof yupEntry.type === 'string' ? yupEntry.type : 'invalid',
133
+ message: typeof yupEntry.message === 'string' ? yupEntry.message : undefined,
134
+ messageParams: yupEntry.params,
135
+ source: 'yup',
136
+ raw: entry,
137
+ };
138
+ });
139
+ return { ok: false, failure: buildFailure('yup', issues, 'Yup validation failed.', context) };
140
+ }
141
+ },
142
+ };
143
+ const superstructAdapter = {
144
+ kind: 'superstruct',
145
+ validate(value, schema, context) {
146
+ const { validate } = superstructModule ?? (superstructModule = loadOptionalModule('superstruct'));
147
+ const [error, result] = validate(value, schema);
148
+ if (!error) {
149
+ return { ok: true, value: result };
150
+ }
151
+ const structError = error;
152
+ const failures = typeof structError.failures === 'function' ? Array.from(structError.failures()) : [structError];
153
+ const issues = failures.map(entry => {
154
+ const failure = entry;
155
+ let code = 'invalid';
156
+ if (typeof failure.refinement === 'string') {
157
+ code = failure.refinement;
158
+ }
159
+ else if (typeof failure.type === 'string') {
160
+ code = failure.type;
161
+ }
162
+ return {
163
+ path: normalizePath(failure.path),
164
+ code,
165
+ message: typeof failure.message === 'string' ? failure.message : undefined,
166
+ source: 'superstruct',
167
+ raw: entry,
168
+ };
169
+ });
170
+ return { ok: false, failure: buildFailure('superstruct', issues, 'Superstruct validation failed.', context) };
171
+ },
172
+ };
173
+ function getIoTsDecodeResult(schema, value) {
174
+ const codec = schema;
175
+ if (typeof codec.decode !== 'function') {
176
+ throw new TypeError('Expected an io-ts codec with decode().');
177
+ }
178
+ return codec.decode(value);
179
+ }
180
+ function getIoTsSummary(decoded) {
181
+ try {
182
+ const reporterModule = loadOptionalModule('io-ts/PathReporter');
183
+ const reporter = reporterModule.PathReporter;
184
+ if (reporter && typeof reporter.report === 'function') {
185
+ return reporter.report(decoded).join('; ');
186
+ }
187
+ }
188
+ catch {
189
+ // Ignore reporter loading issues and fall back to a generic summary.
190
+ }
191
+ return 'io-ts validation failed.';
192
+ }
193
+ const ioTsAdapter = {
194
+ kind: 'io-ts',
195
+ validate(value, schema, context) {
196
+ const decoded = getIoTsDecodeResult(schema, value);
197
+ if (decoded?._tag === 'Right') {
198
+ return { ok: true, value: decoded.right };
199
+ }
200
+ const validationErrors = (decoded?._tag === 'Left' ? decoded.left : []);
201
+ const issues = validationErrors.map(entry => {
202
+ const validationError = entry;
203
+ const contextPath = (validationError.context || [])
204
+ .slice(1)
205
+ .map(item => item.key)
206
+ .filter((segment) => !!segment);
207
+ const finalType = validationError.context?.[validationError.context.length - 1]?.type?.name;
208
+ const message = typeof validationError.message === 'string' ? validationError.message : undefined;
209
+ const messageKey = maybeMessageKey(message);
210
+ return {
211
+ path: contextPath.join('.'),
212
+ code: typeof finalType === 'string' ? finalType : 'invalid',
213
+ ...(message ? { message } : {}),
214
+ ...(messageKey ? { messageKey } : {}),
215
+ source: 'io-ts',
216
+ raw: entry,
217
+ };
218
+ });
219
+ return { ok: false, failure: buildFailure('io-ts', issues, getIoTsSummary(decoded), context) };
220
+ },
221
+ };
222
+ const adapterRegistry = {
223
+ 'io-ts': ioTsAdapter,
224
+ joi: joiAdapter,
225
+ superstruct: superstructAdapter,
226
+ yup: yupAdapter,
227
+ zod: zodAdapter,
228
+ };
229
+ function validateExternalSchema(kind, schema, value, context = {}) {
230
+ return adapterRegistry[kind].validate(value, schema, context);
231
+ }
232
+ //# sourceMappingURL=externalValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalValidation.js","sourceRoot":"","sources":["../../src/routeGeneration/externalValidation.ts"],"names":[],"mappings":";;AA+RA,wDAEC;AA3QD,IAAI,iBAAgD,CAAA;AAEpD,SAAS,4BAA4B,CAAC,KAAc;IAClD,OAAO,KAAK,YAAY,KAAK,IAAK,KAAyB,CAAC,IAAI,KAAK,kBAAkB,CAAA;AACzF,CAAC;AAED,SAAS,kBAAkB,CAAI,UAAkB;IAC/C,IAAI,kBAA0B,CAAA;IAE9B,IAAI,CAAC;QACH,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,MAAM,KAAK,CAAA;QACb,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,4FAA4F,CAAC,CAAA;IAChJ,CAAC;IAED,OAAO,OAAO,CAAC,kBAAkB,CAAM,CAAA;AACzC,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/C,CAAC;IAED,OAAO,KAAK;SACT,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,KAAK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AY,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,CAAA;IAChG,CAAC;CACF,CAAA;AAED,MAAM,eAAe,GAA6D;IAChF,OAAO,EAAE,WAAW;IACpB,GAAG,EAAE,UAAU;IACf,WAAW,EAAE,kBAAkB;IAC/B,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,UAAU;CAChB,CAAA;AAED,SAAgB,sBAAsB,CAAC,IAAgC,EAAE,MAAe,EAAE,KAAc,EAAE,UAAkC,EAAE;IAC5I,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAC/D,CAAC"}
@@ -1,28 +1,87 @@
1
1
  import { AdditionalProps } from './additionalProps';
2
2
  import { TsoaRoute } from './tsoa-route';
3
- export declare function ValidateParam(property: TsoaRoute.PropertySchema, value: any, generatedModels: TsoaRoute.Models, name: string | undefined, fieldErrors: FieldErrors, isBodyParam: boolean, parent: string | undefined, config: AdditionalProps): any;
3
+ export interface ParameterValidationMetadata {
4
+ controllerClass?: object;
5
+ methodName?: string;
6
+ parameterIndex?: number;
7
+ }
8
+ type ValidateNestedObjectLiteralOptions = {
9
+ name: string;
10
+ value: unknown;
11
+ fieldErrors: FieldErrors;
12
+ isBodyParam: boolean;
13
+ nestedProperties: {
14
+ [name: string]: TsoaRoute.PropertySchema;
15
+ } | undefined;
16
+ additionalProperties: TsoaRoute.PropertySchema | boolean | undefined;
17
+ parent: string;
18
+ metadata?: ParameterValidationMetadata;
19
+ };
20
+ type ValidateNestedObjectLiteralTupleArgs = [
21
+ string,
22
+ unknown,
23
+ FieldErrors,
24
+ boolean,
25
+ {
26
+ [name: string]: TsoaRoute.PropertySchema;
27
+ } | undefined,
28
+ TsoaRoute.PropertySchema | boolean | undefined,
29
+ string?,
30
+ ParameterValidationMetadata?
31
+ ];
32
+ type ValidateArrayOptions = {
33
+ name: string;
34
+ value: unknown;
35
+ fieldErrors: FieldErrors;
36
+ isBodyParam: boolean;
37
+ schema?: TsoaRoute.PropertySchema;
38
+ validators?: ArrayValidator;
39
+ parent: string;
40
+ metadata?: ParameterValidationMetadata;
41
+ };
42
+ type ValidateArrayTupleArgs = [string, unknown, FieldErrors, boolean, TsoaRoute.PropertySchema?, ArrayValidator?, string?, ParameterValidationMetadata?];
43
+ export declare function ValidateParam<TValue>(property: TsoaRoute.PropertySchema, value: TValue, generatedModels: TsoaRoute.Models, name: string | undefined, fieldErrors: FieldErrors, isBodyParam: boolean, parent: string | undefined, config: AdditionalProps, metadata?: ParameterValidationMetadata): TValue;
4
44
  export declare class ValidationService {
5
45
  private readonly models;
6
46
  private readonly config;
7
47
  private validationStack;
8
48
  constructor(models: TsoaRoute.Models, config: AdditionalProps);
9
- ValidateParam(property: TsoaRoute.PropertySchema, rawValue: any, name: string | undefined, fieldErrors: FieldErrors, isBodyParam: boolean, parent?: string): any;
10
- hasCorrectJsType(value: any, type: 'object' | 'boolean' | 'number' | 'string', isBodyParam: boolean): boolean;
11
- validateNestedObjectLiteral(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, nestedProperties: {
12
- [name: string]: TsoaRoute.PropertySchema;
13
- } | undefined, additionalProperties: TsoaRoute.PropertySchema | boolean | undefined, parent: string): any;
14
- validateInt(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: IntegerValidator, parent?: string): number | undefined;
15
- validateFloat(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: FloatValidator, parent?: string): number | undefined;
49
+ private isRecord;
50
+ private buildChildPath;
51
+ ValidateParam<TValue>(property: TsoaRoute.PropertySchema, rawValue: TValue, name: string | undefined, fieldErrors: FieldErrors, isBodyParam: boolean, parent?: string, metadata?: ParameterValidationMetadata): TValue;
52
+ private handleUndefinedValue;
53
+ private getRequiredFieldMessage;
54
+ private validateResolvedProperty;
55
+ private validateExternal;
56
+ private getRuntimeExternalValidatorMetadata;
57
+ private projectExternalFailureToFieldErrors;
58
+ hasCorrectJsType(value: unknown, type: 'object' | 'boolean' | 'number' | 'string', isBodyParam: boolean): boolean;
59
+ validateNestedObjectLiteral(...args: [ValidateNestedObjectLiteralOptions]): unknown;
60
+ /**
61
+ * @deprecated Use the object overload instead.
62
+ */
63
+ validateNestedObjectLiteral(...args: ValidateNestedObjectLiteralTupleArgs): unknown;
64
+ private normalizeValidateNestedObjectLiteralArgs;
65
+ validateInt(name: string, value: unknown, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: IntegerValidator, parent?: string): number | undefined;
66
+ validateFloat(name: string, value: unknown, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: FloatValidator, parent?: string): number | undefined;
16
67
  validateEnum(name: string, value: unknown, fieldErrors: FieldErrors, members?: Array<string | number | boolean | null>, parent?: string): unknown;
17
- validateDate(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: DateValidator, parent?: string): Date | undefined;
18
- validateDateTime(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: DateTimeValidator, parent?: string): Date | undefined;
19
- validateString(name: string, value: any, fieldErrors: FieldErrors, validators?: StringValidator, parent?: string): string | undefined;
20
- validateBool(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: BooleanValidator, parent?: string): any;
21
- validateUndefined(name: string, value: any, fieldErrors: FieldErrors, parent?: string): undefined;
22
- validateArray(name: string, value: any[], fieldErrors: FieldErrors, isBodyParam: boolean, schema?: TsoaRoute.PropertySchema, validators?: ArrayValidator, parent?: string): any[] | undefined;
23
- validateBuffer(_name: string, value: string): Buffer<ArrayBuffer>;
24
- validateUnion(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, property: TsoaRoute.PropertySchema, parent?: string): any;
25
- validateIntersection(name: string, value: any, fieldErrors: FieldErrors, isBodyParam: boolean, subSchemas: TsoaRoute.PropertySchema[] | undefined, parent?: string): any;
68
+ validateDate(name: string, value: unknown, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: DateValidator, parent?: string): Date | undefined;
69
+ validateDateTime(name: string, value: unknown, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: DateTimeValidator, parent?: string): Date | undefined;
70
+ validateString(name: string, value: unknown, fieldErrors: FieldErrors, validators?: StringValidator, parent?: string): string | undefined;
71
+ validateBool(name: string, value: unknown, fieldErrors: FieldErrors, isBodyParam: boolean, validators?: BooleanValidator, parent?: string): boolean | undefined;
72
+ validateUndefined(name: string, value: unknown, fieldErrors: FieldErrors, parent?: string): undefined;
73
+ validateArray(options: ValidateArrayOptions): unknown[] | undefined;
74
+ /**
75
+ * @deprecated Use the object overload instead.
76
+ */
77
+ validateArray(...args: ValidateArrayTupleArgs): unknown[] | undefined;
78
+ private normalizeValidateArrayArgs;
79
+ private getArrayValidatorError;
80
+ private hasDuplicateArrayItems;
81
+ private buildIssueFieldPath;
82
+ validateBuffer(name: string, value: unknown, fieldErrors: FieldErrors, parent?: string): Buffer | undefined;
83
+ validateUnion<TValue>(name: string, value: TValue, fieldErrors: FieldErrors, isBodyParam: boolean, property: TsoaRoute.PropertySchema, parent?: string, metadata?: ParameterValidationMetadata): TValue;
84
+ validateIntersection<TValue>(name: string, value: TValue, fieldErrors: FieldErrors, isBodyParam: boolean, subSchemas: TsoaRoute.PropertySchema[] | undefined, parent?: string, metadata?: ParameterValidationMetadata): TValue;
26
85
  private toModelLike;
27
86
  /**
28
87
  * combine all schemas once, ignoring order ie
@@ -45,14 +104,15 @@ export declare class ValidationService {
45
104
  private getAllCombinations;
46
105
  private combineProperties;
47
106
  private getExcessPropertiesFor;
48
- validateModel(input: {
107
+ validateModel<TValue>(input: {
49
108
  name: string;
50
- value: any;
109
+ value: TValue;
51
110
  modelDefinition: TsoaRoute.ModelSchema;
52
111
  fieldErrors: FieldErrors;
53
112
  isBodyParam: boolean;
54
113
  parent?: string;
55
- }): any;
114
+ metadata?: ParameterValidationMetadata;
115
+ }): TValue;
56
116
  /**
57
117
  * Creates a new ValidationService instance with specific configuration
58
118
  * @param overrides Configuration overrides
@@ -99,6 +159,14 @@ export interface IntegerValidator {
99
159
  value: number;
100
160
  errorMsg?: string;
101
161
  };
162
+ exclusiveMinimum?: {
163
+ value: number;
164
+ errorMsg?: string;
165
+ };
166
+ exclusiveMaximum?: {
167
+ value: number;
168
+ errorMsg?: string;
169
+ };
102
170
  }
103
171
  export interface FloatValidator {
104
172
  isFloat?: {
@@ -115,6 +183,14 @@ export interface FloatValidator {
115
183
  value: number;
116
184
  errorMsg?: string;
117
185
  };
186
+ exclusiveMinimum?: {
187
+ value: number;
188
+ errorMsg?: string;
189
+ };
190
+ exclusiveMaximum?: {
191
+ value: number;
192
+ errorMsg?: string;
193
+ };
118
194
  }
119
195
  export interface DateValidator {
120
196
  isDate?: {
@@ -188,7 +264,7 @@ export type Validator = IntegerValidator | FloatValidator | DateValidator | Date
188
264
  export interface FieldErrors {
189
265
  [name: string]: {
190
266
  message: string;
191
- value?: any;
267
+ value?: unknown;
192
268
  };
193
269
  }
194
270
  export interface Exception extends Error {
@@ -201,3 +277,4 @@ export declare class ValidateError extends Error implements Exception {
201
277
  name: string;
202
278
  constructor(fields: FieldErrors, message: string);
203
279
  }
280
+ export {};