@tsoa/runtime
Advanced tools
Comparing version 4.0.0-beta.0 to 4.0.0-rc.1
@@ -129,2 +129,12 @@ import { Swagger } from './swagger/swagger'; | ||
/** | ||
* Template string for generating operation ids. | ||
* This should be a valid handlebars template and is provided | ||
* with the following context: | ||
* - 'controllerName' - String name of controller class. | ||
* - 'method' - Tsoa.Method object. | ||
* | ||
* @default '{{titleCase method.name}}' | ||
*/ | ||
operationIdTemplate?: string; | ||
/** | ||
* Security Definitions Object | ||
@@ -131,0 +141,0 @@ * A declaration of the security schemes available to be used in the |
@@ -5,3 +5,3 @@ "use strict"; | ||
function CustomAttribute(_name, _value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -8,0 +8,0 @@ }; |
@@ -8,3 +8,3 @@ "use strict"; | ||
function Deprecated() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -11,0 +11,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function Example(exampleModel, exampleLabel) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -8,0 +8,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function Extension(_name, _value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -8,0 +8,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function Options(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -12,3 +12,3 @@ }; | ||
function Get(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -19,3 +19,3 @@ }; | ||
function Post(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -26,3 +26,3 @@ }; | ||
function Put(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -33,3 +33,3 @@ }; | ||
function Patch(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -40,3 +40,3 @@ }; | ||
function Delete(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -47,3 +47,3 @@ }; | ||
function Head(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -50,0 +50,0 @@ }; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchMiddlewares = exports.Middlewares = void 0; | ||
var TSOA_MIDDLEWARES = Symbol('@tsoa:middlewares'); | ||
const TSOA_MIDDLEWARES = Symbol('@tsoa:middlewares'); | ||
/** | ||
@@ -40,7 +15,3 @@ * Helper function to create a decorator | ||
function decorator(fn) { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return (...args) => { | ||
// class decorator | ||
@@ -53,3 +24,3 @@ if (args.length === 1) { | ||
// method decorator | ||
var descriptor = args[2]; | ||
const descriptor = args[2]; | ||
if (descriptor.value) { | ||
@@ -66,11 +37,7 @@ fn(descriptor.value); | ||
*/ | ||
function Middlewares() { | ||
var mws = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
mws[_i] = arguments[_i]; | ||
} | ||
return decorator(function (target) { | ||
function Middlewares(...mws) { | ||
return decorator(target => { | ||
if (mws) { | ||
var current = fetchMiddlewares(target); | ||
Reflect.defineMetadata(TSOA_MIDDLEWARES, __spreadArray(__spreadArray([], __read(current), false), __read(mws), false), target); | ||
const current = fetchMiddlewares(target); | ||
Reflect.defineMetadata(TSOA_MIDDLEWARES, [...current, ...mws], target); | ||
} | ||
@@ -77,0 +44,0 @@ }); |
@@ -5,3 +5,3 @@ "use strict"; | ||
function OperationId(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -8,0 +8,0 @@ }; |
@@ -9,3 +9,3 @@ "use strict"; | ||
function Body() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -21,3 +21,3 @@ }; | ||
function BodyProp(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -31,3 +31,3 @@ }; | ||
function Request() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -43,3 +43,3 @@ }; | ||
function Path(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -55,3 +55,3 @@ }; | ||
function Query(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -67,3 +67,3 @@ }; | ||
function Header(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -77,3 +77,3 @@ }; | ||
function Inject() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -89,3 +89,3 @@ }; | ||
function UploadedFile(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -101,3 +101,3 @@ }; | ||
function UploadedFiles(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -113,3 +113,3 @@ }; | ||
function FormField(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -127,3 +127,3 @@ }; | ||
function Consumes(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -130,0 +130,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function SuccessResponse(name, description, produces) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -12,3 +12,3 @@ }; | ||
function Response(name, description, example, produces) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -24,3 +24,3 @@ }; | ||
function Res() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -37,3 +37,3 @@ }; | ||
function Produces(value) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -40,0 +40,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function Route(name) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -15,3 +15,3 @@ }; | ||
function Hidden() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -18,0 +18,0 @@ }; |
@@ -8,3 +8,3 @@ "use strict"; | ||
function NoSecurity() { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -18,3 +18,3 @@ }; | ||
function Security(name, scopes) { | ||
return function () { | ||
return () => { | ||
return; | ||
@@ -21,0 +21,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Tags = void 0; | ||
function Tags() { | ||
var values = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
values[_i] = arguments[_i]; | ||
} | ||
return function () { | ||
function Tags(...values) { | ||
return () => { | ||
return; | ||
@@ -11,0 +7,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Controller = void 0; | ||
var Controller = /** @class */ (function () { | ||
function Controller() { | ||
class Controller { | ||
constructor() { | ||
this.statusCode = undefined; | ||
this.headers = {}; | ||
} | ||
Controller.prototype.setStatus = function (statusCode) { | ||
setStatus(statusCode) { | ||
this.statusCode = statusCode; | ||
}; | ||
Controller.prototype.getStatus = function () { | ||
} | ||
getStatus() { | ||
return this.statusCode; | ||
}; | ||
Controller.prototype.setHeader = function (name, value) { | ||
} | ||
setHeader(name, value) { | ||
this.headers[name] = value; | ||
}; | ||
Controller.prototype.getHeader = function (name) { | ||
} | ||
getHeader(name) { | ||
return this.headers[name]; | ||
}; | ||
Controller.prototype.getHeaders = function () { | ||
} | ||
getHeaders() { | ||
return this.headers; | ||
}; | ||
return Controller; | ||
}()); | ||
} | ||
} | ||
exports.Controller = Controller; | ||
//# sourceMappingURL=controller.js.map |
@@ -21,3 +21,3 @@ /// <reference types="node" /> | ||
validateArray(name: string, value: any[], fieldErrors: FieldErrors, swaggerConfig: AdditionalProps, schema?: TsoaRoute.PropertySchema, validators?: ArrayValidator, parent?: string): any[] | undefined; | ||
validateBuffer(name: string, value: string): Buffer; | ||
validateBuffer(_name: string, value: string): Buffer; | ||
validateUnion(name: string, value: any, fieldErrors: FieldErrors, swaggerConfig: AdditionalProps, property: TsoaRoute.PropertySchema, parent?: string): any; | ||
@@ -24,0 +24,0 @@ validateIntersection(name: string, value: any, fieldErrors: FieldErrors, swaggerConfig: AdditionalProps, subSchemas: TsoaRoute.PropertySchema[] | undefined, parent?: string): any; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ValidateError = exports.ValidationService = exports.ValidateParam = void 0; | ||
var validator_1 = require("validator"); | ||
var assertNever_1 = require("../utils/assertNever"); | ||
var tsoa_route_1 = require("./tsoa-route"); | ||
const validator_1 = require("validator"); | ||
const assertNever_1 = require("../utils/assertNever"); | ||
const tsoa_route_1 = require("./tsoa-route"); | ||
// for backwards compatibility with custom templates | ||
function ValidateParam(property, value, generatedModels, name, fieldErrors, parent, swaggerConfig) { | ||
if (name === void 0) { name = ''; } | ||
if (parent === void 0) { parent = ''; } | ||
function ValidateParam(property, value, generatedModels, name = '', fieldErrors, parent = '', swaggerConfig) { | ||
return new ValidationService(generatedModels).ValidateParam(property, value, name, fieldErrors, parent, swaggerConfig); | ||
} | ||
exports.ValidateParam = ValidateParam; | ||
var ValidationService = /** @class */ (function () { | ||
function ValidationService(models) { | ||
class ValidationService { | ||
constructor(models) { | ||
this.models = models; | ||
} | ||
ValidationService.prototype.ValidateParam = function (property, rawValue, name, fieldErrors, parent, minimalSwaggerConfig) { | ||
ValidateParam(property, rawValue, name = '', fieldErrors, parent = '', minimalSwaggerConfig) { | ||
var _a; | ||
if (name === void 0) { name = ''; } | ||
if (parent === void 0) { parent = ''; } | ||
var value = rawValue; | ||
let value = rawValue; | ||
// If undefined is alowed type, we can move to value validation | ||
if (value === undefined && property.dataType !== 'undefined') { | ||
// If there's either default value or datatype is union with undefined valid, we can just set it and move to validation | ||
if (property.default !== undefined || (property.dataType === 'union' && ((_a = property.subSchemas) === null || _a === void 0 ? void 0 : _a.some(function (p) { return p.dataType === 'undefined'; })))) { | ||
if (property.default !== undefined || (property.dataType === 'union' && ((_a = property.subSchemas) === null || _a === void 0 ? void 0 : _a.some(p => p.dataType === 'undefined')))) { | ||
value = property.default; | ||
@@ -93,9 +27,9 @@ } | ||
// If value can be typed as undefined, there's no need to check mandatoriness here. | ||
var message_1 = "'".concat(name, "' is required"); | ||
let message = `'${name}' is required`; | ||
if (property.validators) { | ||
var validators_1 = property.validators; | ||
Object.keys(validators_1).forEach(function (key) { | ||
var errorMsg = validators_1[key].errorMsg; | ||
const validators = property.validators; | ||
Object.keys(validators).forEach((key) => { | ||
const errorMsg = validators[key].errorMsg; | ||
if (key.startsWith('is') && errorMsg) { | ||
message_1 = errorMsg; | ||
message = errorMsg; | ||
} | ||
@@ -105,4 +39,4 @@ }); | ||
fieldErrors[parent + name] = { | ||
message: message_1, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
@@ -148,17 +82,16 @@ return; | ||
if (property.ref) { | ||
return this.validateModel({ name: name, value: value, modelDefinition: this.models[property.ref], fieldErrors: fieldErrors, parent: parent, minimalSwaggerConfig: minimalSwaggerConfig }); | ||
return this.validateModel({ name, value, modelDefinition: this.models[property.ref], fieldErrors, parent, minimalSwaggerConfig }); | ||
} | ||
return value; | ||
} | ||
}; | ||
ValidationService.prototype.validateNestedObjectLiteral = function (name, value, fieldErrors, swaggerConfig, nestedProperties, additionalProperties, parent) { | ||
var _this = this; | ||
} | ||
validateNestedObjectLiteral(name, value, fieldErrors, swaggerConfig, nestedProperties, additionalProperties, parent) { | ||
if (typeof value !== 'object' || value === null || Array.isArray(value)) { | ||
fieldErrors[parent + name] = { | ||
message: "invalid object", | ||
value: value, | ||
message: `invalid object`, | ||
value, | ||
}; | ||
return; | ||
} | ||
var previousErrors = Object.keys(fieldErrors).length; | ||
const previousErrors = Object.keys(fieldErrors).length; | ||
if (!nestedProperties) { | ||
@@ -170,8 +103,8 @@ throw new Error('internal tsoa error: ' + | ||
} | ||
var propHandling = swaggerConfig.noImplicitAdditionalProperties; | ||
const propHandling = swaggerConfig.noImplicitAdditionalProperties; | ||
if (propHandling !== 'ignore') { | ||
var excessProps = this.getExcessPropertiesFor({ dataType: 'refObject', properties: nestedProperties, additionalProperties: additionalProperties }, Object.keys(value), swaggerConfig); | ||
const excessProps = this.getExcessPropertiesFor({ dataType: 'refObject', properties: nestedProperties, additionalProperties }, Object.keys(value), swaggerConfig); | ||
if (excessProps.length > 0) { | ||
if (propHandling === 'silently-remove-extras') { | ||
excessProps.forEach(function (excessProp) { | ||
excessProps.forEach(excessProp => { | ||
delete value[excessProp]; | ||
@@ -182,7 +115,4 @@ }); | ||
fieldErrors[parent + name] = { | ||
message: "\"".concat(excessProps.join(','), "\" is an excess property and therefore is not allowed"), | ||
value: excessProps.reduce(function (acc, propName) { | ||
var _a; | ||
return (__assign((_a = {}, _a[propName] = value[propName], _a), acc)); | ||
}, {}), | ||
message: `"${excessProps.join(',')}" is an excess property and therefore is not allowed`, | ||
value: excessProps.reduce((acc, propName) => ({ [propName]: value[propName], ...acc }), {}), | ||
}; | ||
@@ -192,4 +122,4 @@ } | ||
} | ||
Object.keys(nestedProperties).forEach(function (key) { | ||
var validatedProp = _this.ValidateParam(nestedProperties[key], value[key], key, fieldErrors, parent + name + '.', swaggerConfig); | ||
Object.keys(nestedProperties).forEach(key => { | ||
const validatedProp = this.ValidateParam(nestedProperties[key], value[key], key, fieldErrors, parent + name + '.', swaggerConfig); | ||
// Add value from validator if it's not undefined or if value is required and unfedined is valid type | ||
@@ -201,5 +131,5 @@ if (validatedProp !== undefined || (nestedProperties[key].dataType === 'undefined' && nestedProperties[key].required)) { | ||
if (typeof additionalProperties === 'object' && typeof value === 'object') { | ||
var keys = Object.keys(value).filter(function (key) { return typeof nestedProperties[key] === 'undefined'; }); | ||
keys.forEach(function (key) { | ||
var validatedProp = _this.ValidateParam(additionalProperties, value[key], key, fieldErrors, parent + name + '.', swaggerConfig); | ||
const keys = Object.keys(value).filter(key => typeof nestedProperties[key] === 'undefined'); | ||
keys.forEach(key => { | ||
const validatedProp = this.ValidateParam(additionalProperties, value[key], key, fieldErrors, parent + name + '.', swaggerConfig); | ||
// Add value from validator if it's not undefined or if value is required and unfedined is valid type | ||
@@ -215,7 +145,6 @@ if (validatedProp !== undefined || (additionalProperties.dataType === 'undefined' && additionalProperties.required)) { | ||
return value; | ||
}; | ||
ValidationService.prototype.validateInt = function (name, value, fieldErrors, validators, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateInt(name, value, fieldErrors, validators, parent = '') { | ||
if (!validator_1.default.isInt(String(value))) { | ||
var message = "invalid integer number"; | ||
let message = `invalid integer number`; | ||
if (validators) { | ||
@@ -230,8 +159,8 @@ if (validators.isInt && validators.isInt.errorMsg) { | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
} | ||
var numberValue = validator_1.default.toInt(String(value), 10); | ||
const numberValue = validator_1.default.toInt(String(value), 10); | ||
if (!validators) { | ||
@@ -243,4 +172,4 @@ return numberValue; | ||
fieldErrors[parent + name] = { | ||
message: validators.minimum.errorMsg || "min ".concat(validators.minimum.value), | ||
value: value, | ||
message: validators.minimum.errorMsg || `min ${validators.minimum.value}`, | ||
value, | ||
}; | ||
@@ -253,4 +182,4 @@ return; | ||
fieldErrors[parent + name] = { | ||
message: validators.maximum.errorMsg || "max ".concat(validators.maximum.value), | ||
value: value, | ||
message: validators.maximum.errorMsg || `max ${validators.maximum.value}`, | ||
value, | ||
}; | ||
@@ -261,7 +190,6 @@ return; | ||
return numberValue; | ||
}; | ||
ValidationService.prototype.validateFloat = function (name, value, fieldErrors, validators, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateFloat(name, value, fieldErrors, validators, parent = '') { | ||
if (!validator_1.default.isFloat(String(value))) { | ||
var message = 'invalid float number'; | ||
let message = 'invalid float number'; | ||
if (validators) { | ||
@@ -276,8 +204,8 @@ if (validators.isFloat && validators.isFloat.errorMsg) { | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
} | ||
var numberValue = validator_1.default.toFloat(String(value)); | ||
const numberValue = validator_1.default.toFloat(String(value)); | ||
if (!validators) { | ||
@@ -289,4 +217,4 @@ return numberValue; | ||
fieldErrors[parent + name] = { | ||
message: validators.minimum.errorMsg || "min ".concat(validators.minimum.value), | ||
value: value, | ||
message: validators.minimum.errorMsg || `min ${validators.minimum.value}`, | ||
value, | ||
}; | ||
@@ -299,4 +227,4 @@ return; | ||
fieldErrors[parent + name] = { | ||
message: validators.maximum.errorMsg || "max ".concat(validators.maximum.value), | ||
value: value, | ||
message: validators.maximum.errorMsg || `max ${validators.maximum.value}`, | ||
value, | ||
}; | ||
@@ -307,18 +235,17 @@ return; | ||
return numberValue; | ||
}; | ||
ValidationService.prototype.validateEnum = function (name, value, fieldErrors, members, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateEnum(name, value, fieldErrors, members, parent = '') { | ||
if (!members || members.length === 0) { | ||
fieldErrors[parent + name] = { | ||
message: 'no member', | ||
value: value, | ||
value, | ||
}; | ||
return; | ||
} | ||
var enumMatchIndex = members.map(function (member) { return String(member); }).findIndex(function (member) { return validator_1.default.equals(member, String(value)); }); | ||
const enumMatchIndex = members.map(member => String(member)).findIndex(member => validator_1.default.equals(member, String(value))); | ||
if (enumMatchIndex === -1) { | ||
var membersInQuotes = members.map(function (member) { return (typeof member === 'string' ? "'".concat(member, "'") : String(member)); }); | ||
const membersInQuotes = members.map(member => (typeof member === 'string' ? `'${member}'` : String(member))); | ||
fieldErrors[parent + name] = { | ||
message: "should be one of the following; [".concat(membersInQuotes.join(','), "]"), | ||
value: value, | ||
message: `should be one of the following; [${membersInQuotes.join(',')}]`, | ||
value, | ||
}; | ||
@@ -328,14 +255,13 @@ return; | ||
return members[enumMatchIndex]; | ||
}; | ||
ValidationService.prototype.validateDate = function (name, value, fieldErrors, validators, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateDate(name, value, fieldErrors, validators, parent = '') { | ||
if (!validator_1.default.isISO8601(String(value), { strict: true })) { | ||
var message = validators && validators.isDate && validators.isDate.errorMsg ? validators.isDate.errorMsg : "invalid ISO 8601 date format, i.e. YYYY-MM-DD"; | ||
const message = validators && validators.isDate && validators.isDate.errorMsg ? validators.isDate.errorMsg : `invalid ISO 8601 date format, i.e. YYYY-MM-DD`; | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
} | ||
var dateValue = new Date(String(value)); | ||
const dateValue = new Date(String(value)); | ||
if (!validators) { | ||
@@ -345,7 +271,7 @@ return dateValue; | ||
if (validators.minDate && validators.minDate.value) { | ||
var minDate = new Date(validators.minDate.value); | ||
const minDate = new Date(validators.minDate.value); | ||
if (minDate.getTime() > dateValue.getTime()) { | ||
fieldErrors[parent + name] = { | ||
message: validators.minDate.errorMsg || "minDate '".concat(validators.minDate.value, "'"), | ||
value: value, | ||
message: validators.minDate.errorMsg || `minDate '${validators.minDate.value}'`, | ||
value, | ||
}; | ||
@@ -356,7 +282,7 @@ return; | ||
if (validators.maxDate && validators.maxDate.value) { | ||
var maxDate = new Date(validators.maxDate.value); | ||
const maxDate = new Date(validators.maxDate.value); | ||
if (maxDate.getTime() < dateValue.getTime()) { | ||
fieldErrors[parent + name] = { | ||
message: validators.maxDate.errorMsg || "maxDate '".concat(validators.maxDate.value, "'"), | ||
value: value, | ||
message: validators.maxDate.errorMsg || `maxDate '${validators.maxDate.value}'`, | ||
value, | ||
}; | ||
@@ -367,14 +293,13 @@ return; | ||
return dateValue; | ||
}; | ||
ValidationService.prototype.validateDateTime = function (name, value, fieldErrors, validators, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateDateTime(name, value, fieldErrors, validators, parent = '') { | ||
if (!validator_1.default.isISO8601(String(value), { strict: true })) { | ||
var message = validators && validators.isDateTime && validators.isDateTime.errorMsg ? validators.isDateTime.errorMsg : "invalid ISO 8601 datetime format, i.e. YYYY-MM-DDTHH:mm:ss"; | ||
const message = validators && validators.isDateTime && validators.isDateTime.errorMsg ? validators.isDateTime.errorMsg : `invalid ISO 8601 datetime format, i.e. YYYY-MM-DDTHH:mm:ss`; | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
} | ||
var datetimeValue = new Date(String(value)); | ||
const datetimeValue = new Date(String(value)); | ||
if (!validators) { | ||
@@ -384,7 +309,7 @@ return datetimeValue; | ||
if (validators.minDate && validators.minDate.value) { | ||
var minDate = new Date(validators.minDate.value); | ||
const minDate = new Date(validators.minDate.value); | ||
if (minDate.getTime() > datetimeValue.getTime()) { | ||
fieldErrors[parent + name] = { | ||
message: validators.minDate.errorMsg || "minDate '".concat(validators.minDate.value, "'"), | ||
value: value, | ||
message: validators.minDate.errorMsg || `minDate '${validators.minDate.value}'`, | ||
value, | ||
}; | ||
@@ -395,7 +320,7 @@ return; | ||
if (validators.maxDate && validators.maxDate.value) { | ||
var maxDate = new Date(validators.maxDate.value); | ||
const maxDate = new Date(validators.maxDate.value); | ||
if (maxDate.getTime() < datetimeValue.getTime()) { | ||
fieldErrors[parent + name] = { | ||
message: validators.maxDate.errorMsg || "maxDate '".concat(validators.maxDate.value, "'"), | ||
value: value, | ||
message: validators.maxDate.errorMsg || `maxDate '${validators.maxDate.value}'`, | ||
value, | ||
}; | ||
@@ -406,14 +331,13 @@ return; | ||
return datetimeValue; | ||
}; | ||
ValidationService.prototype.validateString = function (name, value, fieldErrors, validators, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateString(name, value, fieldErrors, validators, parent = '') { | ||
if (typeof value !== 'string') { | ||
var message = validators && validators.isString && validators.isString.errorMsg ? validators.isString.errorMsg : "invalid string value"; | ||
const message = validators && validators.isString && validators.isString.errorMsg ? validators.isString.errorMsg : `invalid string value`; | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
} | ||
var stringValue = String(value); | ||
const stringValue = String(value); | ||
if (!validators) { | ||
@@ -425,4 +349,4 @@ return stringValue; | ||
fieldErrors[parent + name] = { | ||
message: validators.minLength.errorMsg || "minLength ".concat(validators.minLength.value), | ||
value: value, | ||
message: validators.minLength.errorMsg || `minLength ${validators.minLength.value}`, | ||
value, | ||
}; | ||
@@ -435,4 +359,4 @@ return; | ||
fieldErrors[parent + name] = { | ||
message: validators.maxLength.errorMsg || "maxLength ".concat(validators.maxLength.value), | ||
value: value, | ||
message: validators.maxLength.errorMsg || `maxLength ${validators.maxLength.value}`, | ||
value, | ||
}; | ||
@@ -445,4 +369,4 @@ return; | ||
fieldErrors[parent + name] = { | ||
message: validators.pattern.errorMsg || "Not match in '".concat(validators.pattern.value, "'"), | ||
value: value, | ||
message: validators.pattern.errorMsg || `Not match in '${validators.pattern.value}'`, | ||
value, | ||
}; | ||
@@ -453,5 +377,4 @@ return; | ||
return stringValue; | ||
}; | ||
ValidationService.prototype.validateBool = function (name, value, fieldErrors, validators, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateBool(name, value, fieldErrors, validators, parent = '') { | ||
if (value === undefined || value === null) { | ||
@@ -469,37 +392,34 @@ return false; | ||
} | ||
var message = validators && validators.isArray && validators.isArray.errorMsg ? validators.isArray.errorMsg : "invalid boolean value"; | ||
const message = validators && validators.isArray && validators.isArray.errorMsg ? validators.isArray.errorMsg : `invalid boolean value`; | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
}; | ||
ValidationService.prototype.validateUndefined = function (name, value, fieldErrors, parent) { | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateUndefined(name, value, fieldErrors, parent = '') { | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
var message = 'invalid undefined value'; | ||
const message = 'invalid undefined value'; | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
}; | ||
ValidationService.prototype.validateArray = function (name, value, fieldErrors, swaggerConfig, schema, validators, parent) { | ||
var _this = this; | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateArray(name, value, fieldErrors, swaggerConfig, schema, validators, parent = '') { | ||
if (!schema || value === undefined) { | ||
var message = validators && validators.isArray && validators.isArray.errorMsg ? validators.isArray.errorMsg : "invalid array"; | ||
const message = validators && validators.isArray && validators.isArray.errorMsg ? validators.isArray.errorMsg : `invalid array`; | ||
fieldErrors[parent + name] = { | ||
message: message, | ||
value: value, | ||
message, | ||
value, | ||
}; | ||
return; | ||
} | ||
var arrayValue = []; | ||
var previousErrors = Object.keys(fieldErrors).length; | ||
let arrayValue = []; | ||
const previousErrors = Object.keys(fieldErrors).length; | ||
if (Array.isArray(value)) { | ||
arrayValue = value.map(function (elementValue, index) { | ||
return _this.ValidateParam(schema, elementValue, "$".concat(index), fieldErrors, name + '.', swaggerConfig); | ||
arrayValue = value.map((elementValue, index) => { | ||
return this.ValidateParam(schema, elementValue, `$${index}`, fieldErrors, name + '.', swaggerConfig); | ||
}); | ||
@@ -519,4 +439,4 @@ } | ||
fieldErrors[parent + name] = { | ||
message: validators.minItems.errorMsg || "minItems ".concat(validators.minItems.value), | ||
value: value, | ||
message: validators.minItems.errorMsg || `minItems ${validators.minItems.value}`, | ||
value, | ||
}; | ||
@@ -529,4 +449,4 @@ return; | ||
fieldErrors[parent + name] = { | ||
message: validators.maxItems.errorMsg || "maxItems ".concat(validators.maxItems.value), | ||
value: value, | ||
message: validators.maxItems.errorMsg || `maxItems ${validators.maxItems.value}`, | ||
value, | ||
}; | ||
@@ -537,4 +457,4 @@ return; | ||
if (validators.uniqueItems) { | ||
var unique = arrayValue.some(function (elem, index, arr) { | ||
var indexOf = arr.indexOf(elem); | ||
const unique = arrayValue.some((elem, index, arr) => { | ||
const indexOf = arr.indexOf(elem); | ||
return indexOf > -1 && indexOf !== index; | ||
@@ -544,4 +464,4 @@ }); | ||
fieldErrors[parent + name] = { | ||
message: validators.uniqueItems.errorMsg || "required unique array", | ||
value: value, | ||
message: validators.uniqueItems.errorMsg || `required unique array`, | ||
value, | ||
}; | ||
@@ -552,9 +472,7 @@ return; | ||
return arrayValue; | ||
}; | ||
ValidationService.prototype.validateBuffer = function (name, value) { | ||
} | ||
validateBuffer(_name, value) { | ||
return Buffer.from(value); | ||
}; | ||
ValidationService.prototype.validateUnion = function (name, value, fieldErrors, swaggerConfig, property, parent) { | ||
var e_1, _a; | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateUnion(name, value, fieldErrors, swaggerConfig, property, parent = '') { | ||
if (!property.subSchemas) { | ||
@@ -565,33 +483,21 @@ throw new Error('internal tsoa error: ' + | ||
} | ||
var subFieldErrors = []; | ||
try { | ||
for (var _b = __values(property.subSchemas), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var subSchema = _c.value; | ||
var subFieldError = {}; | ||
// Clean value if it's not undefined or use undefined directly if it's undefined. | ||
// Value can be undefined if undefined is allowed datatype of the union | ||
var validateableValue = value ? JSON.parse(JSON.stringify(value)) : value; | ||
var cleanValue = this.ValidateParam(__assign(__assign({}, subSchema), { validators: __assign(__assign({}, property.validators), subSchema.validators) }), validateableValue, name, subFieldError, parent, swaggerConfig); | ||
subFieldErrors.push(subFieldError); | ||
if (Object.keys(subFieldError).length === 0) { | ||
return cleanValue; | ||
} | ||
const subFieldErrors = []; | ||
for (const subSchema of property.subSchemas) { | ||
const subFieldError = {}; | ||
// Clean value if it's not undefined or use undefined directly if it's undefined. | ||
// Value can be undefined if undefined is allowed datatype of the union | ||
const validateableValue = value ? JSON.parse(JSON.stringify(value)) : value; | ||
const cleanValue = this.ValidateParam({ ...subSchema, validators: { ...property.validators, ...subSchema.validators } }, validateableValue, name, subFieldError, parent, swaggerConfig); | ||
subFieldErrors.push(subFieldError); | ||
if (Object.keys(subFieldError).length === 0) { | ||
return cleanValue; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
fieldErrors[parent + name] = { | ||
message: "Could not match the union against any of the items. Issues: ".concat(JSON.stringify(subFieldErrors)), | ||
value: value, | ||
message: `Could not match the union against any of the items. Issues: ${JSON.stringify(subFieldErrors)}`, | ||
value, | ||
}; | ||
return; | ||
}; | ||
ValidationService.prototype.validateIntersection = function (name, value, fieldErrors, swaggerConfig, subSchemas, parent) { | ||
var _this = this; | ||
if (parent === void 0) { parent = ''; } | ||
} | ||
validateIntersection(name, value, fieldErrors, swaggerConfig, subSchemas, parent = '') { | ||
if (!subSchemas) { | ||
@@ -602,23 +508,26 @@ throw new Error('internal tsoa error: ' + | ||
} | ||
var subFieldErrors = []; | ||
var cleanValues = {}; | ||
subSchemas.forEach(function (subSchema) { | ||
var subFieldError = {}; | ||
var cleanValue = _this.ValidateParam(subSchema, JSON.parse(JSON.stringify(value)), name, subFieldError, parent, { noImplicitAdditionalProperties: 'silently-remove-extras' }); | ||
cleanValues = __assign(__assign({}, cleanValues), cleanValue); | ||
const subFieldErrors = []; | ||
let cleanValues = {}; | ||
subSchemas.forEach(subSchema => { | ||
const subFieldError = {}; | ||
const cleanValue = this.ValidateParam(subSchema, JSON.parse(JSON.stringify(value)), name, subFieldError, parent, { noImplicitAdditionalProperties: 'silently-remove-extras' }); | ||
cleanValues = { | ||
...cleanValues, | ||
...cleanValue, | ||
}; | ||
subFieldErrors.push(subFieldError); | ||
}); | ||
var filtered = subFieldErrors.filter(function (subFieldError) { return Object.keys(subFieldError).length !== 0; }); | ||
const filtered = subFieldErrors.filter(subFieldError => Object.keys(subFieldError).length !== 0); | ||
if (filtered.length > 0) { | ||
fieldErrors[parent + name] = { | ||
message: "Could not match the intersection against every type. Issues: ".concat(JSON.stringify(filtered)), | ||
value: value, | ||
message: `Could not match the intersection against every type. Issues: ${JSON.stringify(filtered)}`, | ||
value, | ||
}; | ||
return; | ||
} | ||
var schemas = this.selfIntersectionExcludingCombinations(subSchemas.map(function (subSchema) { return _this.toModelLike(subSchema); })); | ||
var getRequiredPropError = function (schema) { | ||
var requiredPropError = {}; | ||
_this.validateModel({ | ||
name: name, | ||
const schemas = this.selfIntersectionExcludingCombinations(subSchemas.map(subSchema => this.toModelLike(subSchema))); | ||
const getRequiredPropError = (schema) => { | ||
const requiredPropError = {}; | ||
this.validateModel({ | ||
name, | ||
value: JSON.parse(JSON.stringify(value)), | ||
@@ -633,5 +542,5 @@ modelDefinition: schema, | ||
}; | ||
var schemasWithRequiredProps = schemas.filter(function (schema) { return Object.keys(getRequiredPropError(schema)).length === 0; }); | ||
const schemasWithRequiredProps = schemas.filter(schema => Object.keys(getRequiredPropError(schema)).length === 0); | ||
if (swaggerConfig.noImplicitAdditionalProperties === 'ignore') { | ||
return __assign(__assign({}, value), cleanValues); | ||
return { ...value, ...cleanValues }; | ||
} | ||
@@ -644,4 +553,4 @@ if (swaggerConfig.noImplicitAdditionalProperties === 'silently-remove-extras') { | ||
fieldErrors[parent + name] = { | ||
message: "Could not match intersection against any of the possible combinations: ".concat(JSON.stringify(schemas.map(function (s) { return Object.keys(s.properties); }))), | ||
value: value, | ||
message: `Could not match intersection against any of the possible combinations: ${JSON.stringify(schemas.map(s => Object.keys(s.properties)))}`, | ||
value, | ||
}; | ||
@@ -651,3 +560,3 @@ return; | ||
} | ||
if (schemasWithRequiredProps.length > 0 && schemasWithRequiredProps.some(function (schema) { return _this.getExcessPropertiesFor(schema, Object.keys(value), swaggerConfig).length === 0; })) { | ||
if (schemasWithRequiredProps.length > 0 && schemasWithRequiredProps.some(schema => this.getExcessPropertiesFor(schema, Object.keys(value), swaggerConfig).length === 0)) { | ||
return cleanValues; | ||
@@ -657,12 +566,11 @@ } | ||
fieldErrors[parent + name] = { | ||
message: "Could not match intersection against any of the possible combinations: ".concat(JSON.stringify(schemas.map(function (s) { return Object.keys(s.properties); }))), | ||
value: value, | ||
message: `Could not match intersection against any of the possible combinations: ${JSON.stringify(schemas.map(s => Object.keys(s.properties)))}`, | ||
value, | ||
}; | ||
return; | ||
} | ||
}; | ||
ValidationService.prototype.toModelLike = function (schema) { | ||
var _this = this; | ||
} | ||
toModelLike(schema) { | ||
if (schema.ref) { | ||
var model = this.models[schema.ref]; | ||
const model = this.models[schema.ref]; | ||
if (model.dataType === 'refObject') { | ||
@@ -672,6 +580,6 @@ return [model]; | ||
else if (model.dataType === 'refAlias') { | ||
return __spreadArray([], __read(this.toModelLike(model.type)), false); | ||
return [...this.toModelLike(model.type)]; | ||
} | ||
else if (model.dataType === 'refEnum') { | ||
throw new Error("Can't transform an enum into a model like structure because it does not have properties."); | ||
throw new Error(`Can't transform an enum into a model like structure because it does not have properties.`); | ||
} | ||
@@ -686,8 +594,8 @@ else { | ||
else if (schema.subSchemas && schema.dataType === 'intersection') { | ||
var modelss = schema.subSchemas.map(function (subSchema) { return _this.toModelLike(subSchema); }); | ||
const modelss = schema.subSchemas.map(subSchema => this.toModelLike(subSchema)); | ||
return this.selfIntersectionExcludingCombinations(modelss); | ||
} | ||
else if (schema.subSchemas && schema.dataType === 'union') { | ||
var modelss = schema.subSchemas.map(function (subSchema) { return _this.toModelLike(subSchema); }); | ||
return modelss.reduce(function (acc, models) { return __spreadArray(__spreadArray([], __read(acc), false), __read(models), false); }, []); | ||
const modelss = schema.subSchemas.map(subSchema => this.toModelLike(subSchema)); | ||
return modelss.reduce((acc, models) => [...acc, ...models], []); | ||
} | ||
@@ -698,3 +606,3 @@ else { | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -713,26 +621,25 @@ * combine all schemas once without backwards combinations ie | ||
*/ | ||
ValidationService.prototype.selfIntersectionExcludingCombinations = function (modelSchemass) { | ||
var res = []; | ||
for (var outerIndex = 0; outerIndex < modelSchemass.length; outerIndex++) { | ||
var currentCollector = __assign({}, modelSchemass[outerIndex][0]); | ||
for (var innerIndex = outerIndex + 1; innerIndex < modelSchemass.length; innerIndex++) { | ||
currentCollector = __assign({}, this.intersectRefObjectModelSchemas([currentCollector], modelSchemass[innerIndex])[0]); | ||
selfIntersectionExcludingCombinations(modelSchemass) { | ||
const res = []; | ||
for (let outerIndex = 0; outerIndex < modelSchemass.length; outerIndex++) { | ||
let currentCollector = { ...modelSchemass[outerIndex][0] }; | ||
for (let innerIndex = outerIndex + 1; innerIndex < modelSchemass.length; innerIndex++) { | ||
currentCollector = { ...this.intersectRefObjectModelSchemas([currentCollector], modelSchemass[innerIndex])[0] }; | ||
if (innerIndex - outerIndex > 1) { | ||
res.push(currentCollector); | ||
} | ||
var currentCombination = this.intersectRefObjectModelSchemas(modelSchemass[outerIndex], modelSchemass[innerIndex]); | ||
res.push.apply(res, __spreadArray([], __read(currentCombination), false)); | ||
const currentCombination = this.intersectRefObjectModelSchemas(modelSchemass[outerIndex], modelSchemass[innerIndex]); | ||
res.push(...currentCombination); | ||
} | ||
} | ||
return res; | ||
}; | ||
ValidationService.prototype.intersectRefObjectModelSchemas = function (a, b) { | ||
var _this = this; | ||
return a.reduce(function (acc, aModel) { return __spreadArray(__spreadArray([], __read(acc), false), __read(b.reduce(function (acc, bModel) { return __spreadArray(__spreadArray([], __read(acc), false), [_this.combineProperties(aModel, bModel)], false); }, [])), false); }, []); | ||
}; | ||
ValidationService.prototype.combineProperties = function (a, b) { | ||
return { dataType: 'refObject', properties: __assign(__assign({}, a.properties), b.properties), additionalProperties: a.additionalProperties || b.additionalProperties || false }; | ||
}; | ||
ValidationService.prototype.getExcessPropertiesFor = function (modelDefinition, properties, config) { | ||
var modelProperties = new Set(Object.keys(modelDefinition.properties)); | ||
} | ||
intersectRefObjectModelSchemas(a, b) { | ||
return a.reduce((acc, aModel) => [...acc, ...b.reduce((acc, bModel) => [...acc, this.combineProperties(aModel, bModel)], [])], []); | ||
} | ||
combineProperties(a, b) { | ||
return { dataType: 'refObject', properties: { ...a.properties, ...b.properties }, additionalProperties: a.additionalProperties || b.additionalProperties || false }; | ||
} | ||
getExcessPropertiesFor(modelDefinition, properties, config) { | ||
const modelProperties = new Set(Object.keys(modelDefinition.properties)); | ||
if (modelDefinition.additionalProperties) { | ||
@@ -745,9 +652,8 @@ return []; | ||
else { | ||
return __spreadArray([], __read(properties), false).filter(function (property) { return !modelProperties.has(property); }); | ||
return [...properties].filter(property => !modelProperties.has(property)); | ||
} | ||
}; | ||
ValidationService.prototype.validateModel = function (input) { | ||
var _this = this; | ||
var name = input.name, value = input.value, modelDefinition = input.modelDefinition, fieldErrors = input.fieldErrors, _a = input.parent, parent = _a === void 0 ? '' : _a, swaggerConfig = input.minimalSwaggerConfig; | ||
var previousErrors = Object.keys(fieldErrors).length; | ||
} | ||
validateModel(input) { | ||
const { name, value, modelDefinition, fieldErrors, parent = '', minimalSwaggerConfig: swaggerConfig } = input; | ||
const previousErrors = Object.keys(fieldErrors).length; | ||
if (modelDefinition) { | ||
@@ -760,16 +666,15 @@ if (modelDefinition.dataType === 'refEnum') { | ||
} | ||
var fieldPath_1 = parent + name; | ||
const fieldPath = parent + name; | ||
if (typeof value !== 'object' || value === null || Array.isArray(value)) { | ||
fieldErrors[fieldPath_1] = { | ||
message: "invalid object", | ||
value: value, | ||
fieldErrors[fieldPath] = { | ||
message: `invalid object`, | ||
value, | ||
}; | ||
return; | ||
} | ||
var properties = modelDefinition.properties || {}; | ||
var keysOnPropertiesModelDefinition_1 = new Set(Object.keys(properties)); | ||
var allPropertiesOnData_1 = new Set(Object.keys(value)); | ||
Object.entries(properties).forEach(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], property = _b[1]; | ||
var validatedParam = _this.ValidateParam(property, value[key], key, fieldErrors, fieldPath_1 + '.', swaggerConfig); | ||
const properties = modelDefinition.properties || {}; | ||
const keysOnPropertiesModelDefinition = new Set(Object.keys(properties)); | ||
const allPropertiesOnData = new Set(Object.keys(value)); | ||
Object.entries(properties).forEach(([key, property]) => { | ||
const validatedParam = this.ValidateParam(property, value[key], key, fieldErrors, fieldPath + '.', swaggerConfig); | ||
// Add value from validator if it's not undefined or if value is required and unfedined is valid type | ||
@@ -780,15 +685,15 @@ if (validatedParam !== undefined || (property.dataType === 'undefined' && property.required)) { | ||
}); | ||
var isAnExcessProperty_1 = function (objectKeyThatMightBeExcess) { | ||
return allPropertiesOnData_1.has(objectKeyThatMightBeExcess) && !keysOnPropertiesModelDefinition_1.has(objectKeyThatMightBeExcess); | ||
const isAnExcessProperty = (objectKeyThatMightBeExcess) => { | ||
return allPropertiesOnData.has(objectKeyThatMightBeExcess) && !keysOnPropertiesModelDefinition.has(objectKeyThatMightBeExcess); | ||
}; | ||
var additionalProperties_1 = modelDefinition.additionalProperties; | ||
if (additionalProperties_1 === true || (0, tsoa_route_1.isDefaultForAdditionalPropertiesAllowed)(additionalProperties_1)) { | ||
const additionalProperties = modelDefinition.additionalProperties; | ||
if (additionalProperties === true || (0, tsoa_route_1.isDefaultForAdditionalPropertiesAllowed)(additionalProperties)) { | ||
// then don't validate any of the additional properties | ||
} | ||
else if (additionalProperties_1 === false) { | ||
Object.keys(value).forEach(function (key) { | ||
if (isAnExcessProperty_1(key)) { | ||
else if (additionalProperties === false) { | ||
Object.keys(value).forEach((key) => { | ||
if (isAnExcessProperty(key)) { | ||
if (swaggerConfig.noImplicitAdditionalProperties === 'throw-on-extras') { | ||
fieldErrors["".concat(fieldPath_1, ".").concat(key)] = { | ||
message: "\"".concat(key, "\" is an excess property and therefore is not allowed"), | ||
fieldErrors[`${fieldPath}.${key}`] = { | ||
message: `"${key}" is an excess property and therefore is not allowed`, | ||
value: key, | ||
@@ -810,12 +715,12 @@ }; | ||
else { | ||
Object.keys(value).forEach(function (key) { | ||
if (isAnExcessProperty_1(key)) { | ||
var validatedValue = _this.ValidateParam(additionalProperties_1, value[key], key, fieldErrors, fieldPath_1 + '.', swaggerConfig); | ||
Object.keys(value).forEach((key) => { | ||
if (isAnExcessProperty(key)) { | ||
const validatedValue = this.ValidateParam(additionalProperties, value[key], key, fieldErrors, fieldPath + '.', swaggerConfig); | ||
// Add value from validator if it's not undefined or if value is required and unfedined is valid type | ||
if (validatedValue !== undefined || (additionalProperties_1.dataType === 'undefined' && additionalProperties_1.required)) { | ||
if (validatedValue !== undefined || (additionalProperties.dataType === 'undefined' && additionalProperties.required)) { | ||
value[key] = validatedValue; | ||
} | ||
else { | ||
fieldErrors["".concat(fieldPath_1, ".").concat(key)] = { | ||
message: "No matching model found in additionalProperties to validate ".concat(key), | ||
fieldErrors[`${fieldPath}.${key}`] = { | ||
message: `No matching model found in additionalProperties to validate ${key}`, | ||
value: key, | ||
@@ -832,20 +737,16 @@ }; | ||
return value; | ||
}; | ||
return ValidationService; | ||
}()); | ||
} | ||
} | ||
exports.ValidationService = ValidationService; | ||
var ValidateError = /** @class */ (function (_super) { | ||
__extends(ValidateError, _super); | ||
function ValidateError(fields, message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.fields = fields; | ||
_this.message = message; | ||
_this.status = 400; | ||
_this.name = 'ValidateError'; | ||
Object.setPrototypeOf(_this, ValidateError.prototype); | ||
return _this; | ||
class ValidateError extends Error { | ||
constructor(fields, message) { | ||
super(message); | ||
this.fields = fields; | ||
this.message = message; | ||
this.status = 400; | ||
this.name = 'ValidateError'; | ||
Object.setPrototypeOf(this, ValidateError.prototype); | ||
} | ||
return ValidateError; | ||
}(Error)); | ||
} | ||
exports.ValidateError = ValidateError; | ||
//# sourceMappingURL=templateHelpers.js.map |
@@ -8,5 +8,5 @@ "use strict"; | ||
function assertNever(value) { | ||
throw new Error("Unhandled discriminated union member: ".concat(JSON.stringify(value))); | ||
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`); | ||
} | ||
exports.assertNever = assertNever; | ||
//# sourceMappingURL=assertNever.js.map |
{ | ||
"name": "@tsoa/runtime", | ||
"description": "Build swagger-compliant REST APIs using TypeScript and Node", | ||
"version": "4.0.0-beta.0", | ||
"version": "4.0.0-rc.1", | ||
"main": "./dist/index.js", | ||
@@ -49,3 +49,3 @@ "typings": "./dist/index.d.ts", | ||
}, | ||
"gitHead": "8d7eb53e83e7067ff10c6265b8131dd2777d8196" | ||
"gitHead": "ef5c643673091458981d9cb8115ba7616e7cee01" | ||
} |
@@ -153,2 +153,13 @@ import { Swagger } from './swagger/swagger'; | ||
/** | ||
* Template string for generating operation ids. | ||
* This should be a valid handlebars template and is provided | ||
* with the following context: | ||
* - 'controllerName' - String name of controller class. | ||
* - 'method' - Tsoa.Method object. | ||
* | ||
* @default '{{titleCase method.name}}' | ||
*/ | ||
operationIdTemplate?: string; | ||
/** | ||
* Security Definitions Object | ||
@@ -155,0 +166,0 @@ * A declaration of the security schemes available to be used in the |
@@ -478,3 +478,3 @@ import validator from 'validator'; | ||
public validateBuffer(name: string, value: string) { | ||
public validateBuffer(_name: string, value: string) { | ||
return Buffer.from(value); | ||
@@ -500,10 +500,3 @@ } | ||
const validateableValue = value ? JSON.parse(JSON.stringify(value)) : value; | ||
const cleanValue = this.ValidateParam( | ||
{ ...subSchema, validators: { ...property.validators, ...subSchema.validators } }, | ||
validateableValue, | ||
name, | ||
subFieldError, | ||
parent, | ||
swaggerConfig, | ||
); | ||
const cleanValue = this.ValidateParam({ ...subSchema, validators: { ...property.validators, ...subSchema.validators } }, validateableValue, name, subFieldError, parent, swaggerConfig); | ||
subFieldErrors.push(subFieldError); | ||
@@ -510,0 +503,0 @@ |
@@ -10,4 +10,4 @@ { | ||
"composite": true, | ||
"target": "es5", | ||
"lib": ["es6", "es2017.object", "dom"], | ||
"target": "ES2019", | ||
"lib": ["ES2019"], | ||
"typeRoots": ["node_modules/@types", "./typings"], | ||
@@ -14,0 +14,0 @@ "downlevelIteration": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
105
0
4
210189
4430