tsoa
This commit is contained in:
12
node_modules/@tsoa/cli/dist/routeGeneration/defaultRouteGenerator.d.ts
generated
vendored
Normal file
12
node_modules/@tsoa/cli/dist/routeGeneration/defaultRouteGenerator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ExtendedRoutesConfig } from '../cli';
|
||||
import { Tsoa } from '@tsoa/runtime';
|
||||
import { AbstractRouteGenerator } from './routeGenerator';
|
||||
export declare class DefaultRouteGenerator extends AbstractRouteGenerator<ExtendedRoutesConfig> {
|
||||
pathTransformerFn: (path: string) => string;
|
||||
template: string;
|
||||
constructor(metadata: Tsoa.Metadata, options: ExtendedRoutesConfig);
|
||||
GenerateCustomRoutes(): Promise<void>;
|
||||
GenerateRoutes(middlewareTemplate: string): Promise<void>;
|
||||
protected pathTransformer(path: string): string;
|
||||
buildContent(middlewareTemplate: string): string;
|
||||
}
|
||||
117
node_modules/@tsoa/cli/dist/routeGeneration/defaultRouteGenerator.js
generated
vendored
Normal file
117
node_modules/@tsoa/cli/dist/routeGeneration/defaultRouteGenerator.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultRouteGenerator = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const handlebars = __importStar(require("handlebars"));
|
||||
const path = __importStar(require("path"));
|
||||
const runtime_1 = require("@tsoa/runtime");
|
||||
const fs_1 = require("../utils/fs");
|
||||
const pathUtils_1 = require("../utils/pathUtils");
|
||||
const routeGenerator_1 = require("./routeGenerator");
|
||||
class DefaultRouteGenerator extends routeGenerator_1.AbstractRouteGenerator {
|
||||
constructor(metadata, options) {
|
||||
super(metadata, options);
|
||||
this.pathTransformerFn = pathUtils_1.convertBracesPathParams;
|
||||
switch (options.middleware) {
|
||||
case 'hapi':
|
||||
this.template = path.join(__dirname, '..', 'routeGeneration/templates/hapi.hbs');
|
||||
this.pathTransformerFn = (path) => path;
|
||||
break;
|
||||
case 'koa':
|
||||
this.template = path.join(__dirname, '..', 'routeGeneration/templates/koa.hbs');
|
||||
break;
|
||||
case 'express':
|
||||
default:
|
||||
this.template = path.join(__dirname, '..', 'routeGeneration/templates/express.hbs');
|
||||
}
|
||||
if (options.middlewareTemplate) {
|
||||
this.template = options.middlewareTemplate;
|
||||
}
|
||||
}
|
||||
async GenerateCustomRoutes() {
|
||||
const data = await (0, fs_1.fsReadFile)(path.join(this.template));
|
||||
const file = data.toString();
|
||||
return await this.GenerateRoutes(file);
|
||||
}
|
||||
async GenerateRoutes(middlewareTemplate) {
|
||||
const allowedExtensions = this.options.esm ? ['.ts', '.mts', '.cts'] : ['.ts'];
|
||||
if (!fs.lstatSync(this.options.routesDir).isDirectory()) {
|
||||
throw new Error(`routesDir should be a directory`);
|
||||
}
|
||||
else if (this.options.routesFileName !== undefined) {
|
||||
const ext = path.extname(this.options.routesFileName);
|
||||
if (!allowedExtensions.includes(ext)) {
|
||||
throw new Error(`routesFileName should be a valid typescript file.`);
|
||||
}
|
||||
}
|
||||
const fileName = `${this.options.routesDir}/${this.options.routesFileName || 'routes.ts'}`;
|
||||
const content = this.buildContent(middlewareTemplate);
|
||||
if (await this.shouldWriteFile(fileName, content)) {
|
||||
await (0, fs_1.fsWriteFile)(fileName, content);
|
||||
}
|
||||
}
|
||||
pathTransformer(path) {
|
||||
return this.pathTransformerFn(path);
|
||||
}
|
||||
buildContent(middlewareTemplate) {
|
||||
handlebars.registerHelper('json', (context) => {
|
||||
return JSON.stringify(context);
|
||||
});
|
||||
const additionalPropsHelper = (additionalProperties) => {
|
||||
if (additionalProperties) {
|
||||
// Then the model for this type explicitly allows additional properties and thus we should assign that
|
||||
return JSON.stringify(additionalProperties);
|
||||
}
|
||||
else if (this.options.noImplicitAdditionalProperties === 'silently-remove-extras') {
|
||||
return JSON.stringify(false);
|
||||
}
|
||||
else if (this.options.noImplicitAdditionalProperties === 'throw-on-extras') {
|
||||
return JSON.stringify(false);
|
||||
}
|
||||
else if (this.options.noImplicitAdditionalProperties === 'ignore') {
|
||||
return JSON.stringify(true);
|
||||
}
|
||||
else {
|
||||
return (0, runtime_1.assertNever)(this.options.noImplicitAdditionalProperties);
|
||||
}
|
||||
};
|
||||
handlebars.registerHelper('additionalPropsHelper', additionalPropsHelper);
|
||||
const routesTemplate = handlebars.compile(middlewareTemplate, { noEscape: true });
|
||||
return routesTemplate(this.buildContext());
|
||||
}
|
||||
}
|
||||
exports.DefaultRouteGenerator = DefaultRouteGenerator;
|
||||
//# sourceMappingURL=defaultRouteGenerator.js.map
|
||||
1
node_modules/@tsoa/cli/dist/routeGeneration/defaultRouteGenerator.js.map
generated
vendored
Normal file
1
node_modules/@tsoa/cli/dist/routeGeneration/defaultRouteGenerator.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"defaultRouteGenerator.js","sourceRoot":"","sources":["../../src/routeGeneration/defaultRouteGenerator.ts"],"names":[],"mappings":"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"}
|
||||
56
node_modules/@tsoa/cli/dist/routeGeneration/routeGenerator.d.ts
generated
vendored
Normal file
56
node_modules/@tsoa/cli/dist/routeGeneration/routeGenerator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import { ExtendedRoutesConfig } from '../cli';
|
||||
import { Tsoa, TsoaRoute } from '@tsoa/runtime';
|
||||
export declare abstract class AbstractRouteGenerator<Config extends ExtendedRoutesConfig> {
|
||||
protected readonly metadata: Tsoa.Metadata;
|
||||
protected readonly options: Config;
|
||||
constructor(metadata: Tsoa.Metadata, options: Config);
|
||||
/**
|
||||
* This is the entrypoint for a generator to create a custom set of routes
|
||||
*/
|
||||
abstract GenerateCustomRoutes(): Promise<void>;
|
||||
buildModels(): TsoaRoute.Models;
|
||||
protected pathTransformer(path: string): string;
|
||||
protected buildContext(): {
|
||||
authenticationModule: string | undefined;
|
||||
basePath: string;
|
||||
canImportByAlias: boolean;
|
||||
controllers: {
|
||||
actions: {
|
||||
fullPath: string;
|
||||
method: string;
|
||||
name: string;
|
||||
parameters: {
|
||||
[name: string]: TsoaRoute.ParameterSchema;
|
||||
};
|
||||
path: string;
|
||||
uploadFile: boolean;
|
||||
uploadFileName: {
|
||||
name: string;
|
||||
maxCount: number | undefined;
|
||||
multiple: boolean;
|
||||
}[];
|
||||
security: Tsoa.Security[];
|
||||
successStatus: string | number;
|
||||
}[];
|
||||
modulePath: string;
|
||||
name: string;
|
||||
path: string;
|
||||
}[];
|
||||
environment: NodeJS.ProcessEnv;
|
||||
iocModule: string | undefined;
|
||||
minimalSwaggerConfig: {
|
||||
noImplicitAdditionalProperties: "ignore" | "throw-on-extras" | "silently-remove-extras";
|
||||
bodyCoercion: boolean;
|
||||
};
|
||||
models: TsoaRoute.Models;
|
||||
useFileUploads: boolean;
|
||||
multerOpts: Config["multerOpts"];
|
||||
useSecurity: boolean;
|
||||
esm: boolean | undefined;
|
||||
};
|
||||
protected getRelativeImportPath(fileLocation: string): string;
|
||||
protected buildPropertySchema(source: Tsoa.Property): TsoaRoute.PropertySchema;
|
||||
protected buildParameterSchema(source: Tsoa.Parameter): TsoaRoute.ParameterSchema;
|
||||
protected buildProperty(type: Tsoa.Type): TsoaRoute.PropertySchema;
|
||||
protected shouldWriteFile(fileName: string, content: string): Promise<boolean>;
|
||||
}
|
||||
255
node_modules/@tsoa/cli/dist/routeGeneration/routeGenerator.js
generated
vendored
Normal file
255
node_modules/@tsoa/cli/dist/routeGeneration/routeGenerator.js
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AbstractRouteGenerator = void 0;
|
||||
const path = __importStar(require("path"));
|
||||
const runtime_1 = require("@tsoa/runtime");
|
||||
const internalTypeGuards_1 = require("../utils/internalTypeGuards");
|
||||
const pathUtils_1 = require("../utils/pathUtils");
|
||||
const fs_1 = require("../utils/fs");
|
||||
class AbstractRouteGenerator {
|
||||
constructor(metadata, options) {
|
||||
this.metadata = metadata;
|
||||
this.options = options;
|
||||
}
|
||||
buildModels() {
|
||||
const models = {};
|
||||
Object.keys(this.metadata.referenceTypeMap).forEach(name => {
|
||||
const referenceType = this.metadata.referenceTypeMap[name];
|
||||
let model;
|
||||
if (referenceType.dataType === 'refEnum') {
|
||||
const refEnumModel = {
|
||||
dataType: 'refEnum',
|
||||
enums: referenceType.enums,
|
||||
};
|
||||
model = refEnumModel;
|
||||
}
|
||||
else if (referenceType.dataType === 'refObject') {
|
||||
const propertySchemaDictionary = {};
|
||||
referenceType.properties.forEach(property => {
|
||||
propertySchemaDictionary[property.name] = this.buildPropertySchema(property);
|
||||
});
|
||||
const refObjModel = {
|
||||
dataType: 'refObject',
|
||||
properties: propertySchemaDictionary,
|
||||
};
|
||||
if (referenceType.additionalProperties) {
|
||||
refObjModel.additionalProperties = this.buildProperty(referenceType.additionalProperties);
|
||||
}
|
||||
else if (this.options.noImplicitAdditionalProperties !== 'ignore') {
|
||||
refObjModel.additionalProperties = false;
|
||||
}
|
||||
else {
|
||||
// Since Swagger allows "excess properties" (to use a TypeScript term) by default
|
||||
refObjModel.additionalProperties = true;
|
||||
}
|
||||
model = refObjModel;
|
||||
}
|
||||
else if (referenceType.dataType === 'refAlias') {
|
||||
const refType = {
|
||||
dataType: 'refAlias',
|
||||
type: {
|
||||
...this.buildProperty(referenceType.type),
|
||||
validators: referenceType.validators,
|
||||
default: referenceType.default,
|
||||
},
|
||||
};
|
||||
model = refType;
|
||||
}
|
||||
else {
|
||||
model = (0, runtime_1.assertNever)(referenceType);
|
||||
}
|
||||
models[name] = model;
|
||||
});
|
||||
return models;
|
||||
}
|
||||
pathTransformer(path) {
|
||||
return (0, pathUtils_1.convertBracesPathParams)(path);
|
||||
}
|
||||
buildContext() {
|
||||
const authenticationModule = this.options.authenticationModule ? this.getRelativeImportPath(this.options.authenticationModule) : undefined;
|
||||
const iocModule = this.options.iocModule ? this.getRelativeImportPath(this.options.iocModule) : undefined;
|
||||
// Left in for backwards compatibility, previously if we're working locally then tsoa runtime code wasn't an importable module but now it is.
|
||||
const canImportByAlias = true;
|
||||
const normalisedBasePath = (0, pathUtils_1.normalisePath)(this.options.basePath, '/');
|
||||
return {
|
||||
authenticationModule,
|
||||
basePath: normalisedBasePath,
|
||||
canImportByAlias,
|
||||
controllers: this.metadata.controllers.map(controller => {
|
||||
const normalisedControllerPath = this.pathTransformer((0, pathUtils_1.normalisePath)(controller.path, '/'));
|
||||
return {
|
||||
actions: controller.methods.map(method => {
|
||||
const parameterObjs = {};
|
||||
method.parameters.forEach(parameter => {
|
||||
parameterObjs[parameter.parameterName] = this.buildParameterSchema(parameter);
|
||||
});
|
||||
const normalisedMethodPath = this.pathTransformer((0, pathUtils_1.normalisePath)(method.path, '/'));
|
||||
const normalisedFullPath = (0, pathUtils_1.normalisePath)(`${normalisedBasePath}${normalisedControllerPath}${normalisedMethodPath}`, '/', '', false);
|
||||
const uploadFilesWithDifferentFieldParameter = method.parameters.filter(parameter => parameter.type.dataType === 'file' || (parameter.type.dataType === 'array' && parameter.type.elementType.dataType === 'file'));
|
||||
return {
|
||||
fullPath: normalisedFullPath,
|
||||
method: method.method.toLowerCase(),
|
||||
name: method.name,
|
||||
parameters: parameterObjs,
|
||||
path: normalisedMethodPath,
|
||||
uploadFile: uploadFilesWithDifferentFieldParameter.length > 0,
|
||||
uploadFileName: uploadFilesWithDifferentFieldParameter.map(parameter => ({
|
||||
name: parameter.name,
|
||||
maxCount: parameter.type.dataType === 'file' ? 1 : undefined,
|
||||
multiple: parameter.type.dataType === 'array' && parameter.type.elementType.dataType === 'file',
|
||||
})),
|
||||
security: method.security,
|
||||
successStatus: method.successStatus ? method.successStatus : 'undefined',
|
||||
};
|
||||
}),
|
||||
modulePath: this.getRelativeImportPath(controller.location),
|
||||
name: controller.name,
|
||||
path: normalisedControllerPath,
|
||||
};
|
||||
}),
|
||||
environment: process.env,
|
||||
iocModule,
|
||||
minimalSwaggerConfig: { noImplicitAdditionalProperties: this.options.noImplicitAdditionalProperties, bodyCoercion: this.options.bodyCoercion },
|
||||
models: this.buildModels(),
|
||||
useFileUploads: this.metadata.controllers.some(controller => controller.methods.some(method => !!method.parameters.find(parameter => {
|
||||
if (parameter.type.dataType === 'file') {
|
||||
return true;
|
||||
}
|
||||
else if (parameter.type.dataType === 'array' && parameter.type.elementType.dataType === 'file') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}))),
|
||||
multerOpts: {
|
||||
limits: {
|
||||
fileSize: 8388608, // 8mb
|
||||
},
|
||||
...this.options.multerOpts,
|
||||
},
|
||||
useSecurity: this.metadata.controllers.some(controller => controller.methods.some(method => !!method.security.length)),
|
||||
esm: this.options.esm,
|
||||
};
|
||||
}
|
||||
getRelativeImportPath(fileLocation) {
|
||||
const currentExt = path.extname(fileLocation);
|
||||
let newExtension = this.options.rewriteRelativeImportExtensions ? currentExt : '';
|
||||
if (this.options.esm && !this.options.rewriteRelativeImportExtensions) {
|
||||
switch (currentExt) {
|
||||
case '.ts':
|
||||
default:
|
||||
newExtension = '.js';
|
||||
break;
|
||||
case '.mts':
|
||||
newExtension = '.mjs';
|
||||
break;
|
||||
case '.cts':
|
||||
newExtension = '.cjs';
|
||||
break;
|
||||
}
|
||||
}
|
||||
fileLocation = fileLocation.replace(/\.(ts|mts|cts)$/, ''); // no ts extension in import
|
||||
return `./${path.relative(this.options.routesDir, fileLocation).replace(/\\/g, '/')}${newExtension}`;
|
||||
}
|
||||
buildPropertySchema(source) {
|
||||
const propertySchema = this.buildProperty(source.type);
|
||||
propertySchema.default = source.default;
|
||||
propertySchema.required = source.required ? true : undefined;
|
||||
if (Object.keys(source.validators).length > 0) {
|
||||
propertySchema.validators = source.validators;
|
||||
}
|
||||
return propertySchema;
|
||||
}
|
||||
buildParameterSchema(source) {
|
||||
const property = this.buildProperty(source.type);
|
||||
const parameter = {
|
||||
default: source.default,
|
||||
in: source.in,
|
||||
name: source.name,
|
||||
required: source.required ? true : undefined,
|
||||
};
|
||||
const parameterSchema = Object.assign(parameter, property);
|
||||
if (Object.keys(source.validators).length > 0) {
|
||||
parameterSchema.validators = source.validators;
|
||||
}
|
||||
return parameterSchema;
|
||||
}
|
||||
buildProperty(type) {
|
||||
const schema = {
|
||||
dataType: type.dataType,
|
||||
};
|
||||
if ((0, internalTypeGuards_1.isRefType)(type)) {
|
||||
schema.dataType = undefined;
|
||||
schema.ref = type.refName;
|
||||
}
|
||||
if (type.dataType === 'array') {
|
||||
const arrayType = type;
|
||||
if ((0, internalTypeGuards_1.isRefType)(arrayType.elementType)) {
|
||||
schema.array = {
|
||||
dataType: arrayType.elementType.dataType,
|
||||
ref: arrayType.elementType.refName,
|
||||
};
|
||||
}
|
||||
else {
|
||||
schema.array = this.buildProperty(arrayType.elementType);
|
||||
}
|
||||
}
|
||||
if (type.dataType === 'enum') {
|
||||
schema.enums = type.enums;
|
||||
}
|
||||
if (type.dataType === 'union' || type.dataType === 'intersection') {
|
||||
schema.subSchemas = type.types.map(type => this.buildProperty(type));
|
||||
}
|
||||
if (type.dataType === 'nestedObjectLiteral') {
|
||||
const objLiteral = type;
|
||||
schema.nestedProperties = objLiteral.properties.reduce((acc, prop) => {
|
||||
return { ...acc, [prop.name]: this.buildPropertySchema(prop) };
|
||||
}, {});
|
||||
schema.additionalProperties = objLiteral.additionalProperties && this.buildProperty(objLiteral.additionalProperties);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
async shouldWriteFile(fileName, content) {
|
||||
if (this.options.noWriteIfUnchanged) {
|
||||
if (await (0, fs_1.fsExists)(fileName)) {
|
||||
const existingContent = (await (0, fs_1.fsReadFile)(fileName)).toString();
|
||||
return content !== existingContent;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
exports.AbstractRouteGenerator = AbstractRouteGenerator;
|
||||
//# sourceMappingURL=routeGenerator.js.map
|
||||
1
node_modules/@tsoa/cli/dist/routeGeneration/routeGenerator.js.map
generated
vendored
Normal file
1
node_modules/@tsoa/cli/dist/routeGeneration/routeGenerator.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
221
node_modules/@tsoa/cli/dist/routeGeneration/templates/express.hbs
generated
vendored
Normal file
221
node_modules/@tsoa/cli/dist/routeGeneration/templates/express.hbs
generated
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
import type { TsoaRoute } from '@tsoa/runtime';
|
||||
import { fetchMiddlewares, ExpressTemplateService } from '@tsoa/runtime';
|
||||
{{#each controllers}}
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
import { {{name}} } from '{{modulePath}}';
|
||||
{{/each}}
|
||||
{{#if authenticationModule}}
|
||||
import { expressAuthentication } from '{{authenticationModule}}';
|
||||
// @ts-ignore - no great way to install types from subpackage
|
||||
{{/if}}
|
||||
{{#if iocModule}}
|
||||
import { iocContainer } from '{{iocModule}}';
|
||||
import type { IocContainer, IocContainerFactory } from '@tsoa/runtime';
|
||||
{{/if}}
|
||||
import type { Request as ExRequest, Response as ExResponse, RequestHandler, Router } from 'express';
|
||||
{{#if useFileUploads}}
|
||||
{{#if esm}}
|
||||
import multer from 'multer';
|
||||
{{else}}
|
||||
const multer = require('multer');
|
||||
{{/if}}
|
||||
|
||||
{{/if}}
|
||||
|
||||
{{#if authenticationModule}}
|
||||
const expressAuthenticationRecasted = expressAuthentication as (req: ExRequest, securityName: string, scopes?: string[], res?: ExResponse) => Promise<any>;
|
||||
{{/if}}
|
||||
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
const models: TsoaRoute.Models = {
|
||||
{{#each models}}
|
||||
"{{@key}}": {
|
||||
{{#if enums}}
|
||||
"dataType": "refEnum",
|
||||
"enums": {{{json enums}}},
|
||||
{{/if}}
|
||||
{{#if properties}}
|
||||
"dataType": "refObject",
|
||||
"properties": {
|
||||
{{#each properties}}
|
||||
"{{@key}}": {{{json this}}},
|
||||
{{/each}}
|
||||
},
|
||||
"additionalProperties": {{{json additionalProperties}}},
|
||||
{{/if}}
|
||||
{{#if type}}
|
||||
"dataType": "refAlias",
|
||||
"type": {{{json type}}},
|
||||
{{/if}}
|
||||
},
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
{{/each}}
|
||||
};
|
||||
const templateService = new ExpressTemplateService(models, {{{ json minimalSwaggerConfig}}});
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
|
||||
|
||||
|
||||
{{#if useFileUploads}}
|
||||
export function RegisterRoutes(app: Router,opts?:{multer?:ReturnType<typeof multer>}) {
|
||||
{{else}}
|
||||
export function RegisterRoutes(app: Router) {
|
||||
{{/if}}
|
||||
|
||||
// ###########################################################################################################
|
||||
// NOTE: If you do not see routes for all of your controllers in this file, then you might not have informed tsoa of where to look
|
||||
// Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa
|
||||
// ###########################################################################################################
|
||||
|
||||
{{#if useFileUploads}}
|
||||
const upload = opts?.multer || multer({{{json multerOpts}}});
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{#each controllers}}
|
||||
{{#each actions}}
|
||||
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
|
||||
{{#each parameters}}
|
||||
{{@key}}: {{{json this}}},
|
||||
{{/each}}
|
||||
};
|
||||
app.{{method}}('{{fullPath}}',
|
||||
{{#if security.length}}
|
||||
authenticateMiddleware({{json security}}),
|
||||
{{/if}}
|
||||
{{#if uploadFile}}
|
||||
upload.fields([
|
||||
{{#each uploadFileName}}
|
||||
{
|
||||
name: {{json name}},
|
||||
{{#if maxCount}}
|
||||
maxCount: {{maxCount}}
|
||||
{{/if}}
|
||||
}{{#if @last}}{{else}},{{/if}}
|
||||
{{/each}}
|
||||
]),
|
||||
{{/if}}
|
||||
...(fetchMiddlewares<RequestHandler>({{../name}})),
|
||||
...(fetchMiddlewares<RequestHandler>({{../name}}.prototype.{{name}})),
|
||||
|
||||
async function {{../name}}_{{name}}(request: ExRequest, response: ExResponse, next: any) {
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
let validatedArgs: any[] = [];
|
||||
try {
|
||||
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, response });
|
||||
|
||||
{{#if ../../iocModule}}
|
||||
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
|
||||
|
||||
const controller: any = await container.get<{{../name}}>({{../name}});
|
||||
if (typeof controller['setStatus'] === 'function') {
|
||||
controller.setStatus(undefined);
|
||||
}
|
||||
{{else}}
|
||||
const controller = new {{../name}}();
|
||||
{{/if}}
|
||||
|
||||
await templateService.apiHandler({
|
||||
methodName: '{{name}}',
|
||||
controller,
|
||||
response,
|
||||
next,
|
||||
validatedArgs,
|
||||
successStatus: {{successStatus}},
|
||||
});
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
{{/each}}
|
||||
{{/each}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
{{#if useSecurity}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
function authenticateMiddleware(security: TsoaRoute.Security[] = []) {
|
||||
return async function runAuthenticationMiddleware(request: any, response: any, next: any) {
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
// keep track of failed auth attempts so we can hand back the most
|
||||
// recent one. This behavior was previously existing so preserving it
|
||||
// here
|
||||
const failedAttempts: any[] = [];
|
||||
const pushAndRethrow = (error: any) => {
|
||||
failedAttempts.push(error);
|
||||
throw error;
|
||||
};
|
||||
|
||||
const secMethodOrPromises: Promise<any>[] = [];
|
||||
for (const secMethod of security) {
|
||||
if (Object.keys(secMethod).length > 1) {
|
||||
const secMethodAndPromises: Promise<any>[] = [];
|
||||
|
||||
for (const name in secMethod) {
|
||||
secMethodAndPromises.push(
|
||||
expressAuthenticationRecasted(request, name, secMethod[name], response)
|
||||
.catch(pushAndRethrow)
|
||||
);
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
secMethodOrPromises.push(Promise.all(secMethodAndPromises)
|
||||
.then(users => { return users[0]; }));
|
||||
} else {
|
||||
for (const name in secMethod) {
|
||||
secMethodOrPromises.push(
|
||||
expressAuthenticationRecasted(request, name, secMethod[name], response)
|
||||
.catch(pushAndRethrow)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
try {
|
||||
request['user'] = await Promise.any(secMethodOrPromises);
|
||||
|
||||
// Response was sent in middleware, abort
|
||||
if (response.writableEnded) {
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
catch(err) {
|
||||
// Show most recent error as response
|
||||
const error = failedAttempts.pop();
|
||||
error.status = error.status || 401;
|
||||
|
||||
// Response was sent in middleware, abort
|
||||
if (response.writableEnded) {
|
||||
return;
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
}
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
267
node_modules/@tsoa/cli/dist/routeGeneration/templates/hapi.hbs
generated
vendored
Normal file
267
node_modules/@tsoa/cli/dist/routeGeneration/templates/hapi.hbs
generated
vendored
Normal file
@@ -0,0 +1,267 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
import type { TsoaRoute } from '@tsoa/runtime';
|
||||
import { fetchMiddlewares, HapiTemplateService } from '@tsoa/runtime';
|
||||
{{#each controllers}}
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
import { {{name}} } from '{{modulePath}}';
|
||||
{{/each}}
|
||||
{{#if authenticationModule}}
|
||||
import { hapiAuthentication } from '{{authenticationModule}}';
|
||||
// @ts-ignore - no great way to install types from subpackage
|
||||
{{/if}}
|
||||
{{#if iocModule}}
|
||||
import { iocContainer } from '{{iocModule}}';
|
||||
import type { IocContainer, IocContainerFactory } from '@tsoa/runtime';
|
||||
{{/if}}
|
||||
import { boomify, isBoom, type Payload } from '@hapi/boom';
|
||||
import type { Request, ResponseToolkit, RouteOptionsPreAllOptions } from '@hapi/hapi';
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
const models: TsoaRoute.Models = {
|
||||
{{#each models}}
|
||||
"{{@key}}": {
|
||||
{{#if enums}}
|
||||
"dataType": "refEnum",
|
||||
"enums": {{{json enums}}},
|
||||
{{/if}}
|
||||
{{#if properties}}
|
||||
"dataType": "refObject",
|
||||
"properties": {
|
||||
{{#each properties}}
|
||||
"{{@key}}": {{{json this}}},
|
||||
{{/each}}
|
||||
},
|
||||
"additionalProperties": {{{json additionalProperties}}},
|
||||
{{/if}}
|
||||
{{#if type}}
|
||||
"dataType": "refAlias",
|
||||
"type": {{{json type}}},
|
||||
{{/if}}
|
||||
},
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
{{/each}}
|
||||
};
|
||||
const templateService = new HapiTemplateService(
|
||||
models,
|
||||
{{{ json minimalSwaggerConfig }}},
|
||||
{ boomify, isBoom },
|
||||
);
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
export function RegisterRoutes(server: any) {
|
||||
// ###########################################################################################################
|
||||
// NOTE: If you do not see routes for all of your controllers in this file, then you might not have informed tsoa of where to look
|
||||
// Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa
|
||||
// ###########################################################################################################
|
||||
{{#each controllers}}
|
||||
{{#each actions}}
|
||||
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
|
||||
{{#each parameters}}
|
||||
{{@key}}: {{{json this}}},
|
||||
{{/each}}
|
||||
};
|
||||
server.route({
|
||||
method: '{{method}}',
|
||||
path: '{{fullPath}}',
|
||||
options: {
|
||||
pre: [
|
||||
{{#if security.length}}
|
||||
{
|
||||
method: authenticateMiddleware({{json security}})
|
||||
},
|
||||
{{/if}}
|
||||
{{#if uploadFile}}
|
||||
{{#each uploadFileName}}
|
||||
{
|
||||
{{#if multiple}}
|
||||
method: fileUploadMiddleware('{{name}}', true)
|
||||
{{else}}
|
||||
method: fileUploadMiddleware('{{name}}', false)
|
||||
{{/if}}
|
||||
},
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
...(fetchMiddlewares<RouteOptionsPreAllOptions>({{../name}})),
|
||||
...(fetchMiddlewares<RouteOptionsPreAllOptions>({{../name}}.prototype.{{name}})),
|
||||
],
|
||||
{{#if uploadFile}}
|
||||
payload: {
|
||||
output: 'stream',
|
||||
parse: true,
|
||||
multipart: true,
|
||||
allow: 'multipart/form-data'
|
||||
},
|
||||
{{/if}}
|
||||
handler: {{#if ../../iocModule}}async {{/if}}function {{../name}}_{{name}}(request: Request, h: ResponseToolkit) {
|
||||
|
||||
let validatedArgs: any[] = [];
|
||||
try {
|
||||
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, h });
|
||||
} catch (err) {
|
||||
const error = err as any;
|
||||
if (isBoom(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const boomErr = boomify(error instanceof Error ? error : new Error(error.message), { statusCode: error.status || 500 });
|
||||
boomErr.output.statusCode = error.status || 500;
|
||||
boomErr.output.payload = {
|
||||
name: error.name,
|
||||
fields: error.fields,
|
||||
message: error.message,
|
||||
} as unknown as Payload;
|
||||
throw boomErr;
|
||||
}
|
||||
|
||||
{{#if ../../iocModule}}
|
||||
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
|
||||
|
||||
const controller: any = await container.get<{{../name}}>({{../name}});
|
||||
if (typeof controller['setStatus'] === 'function') {
|
||||
controller.setStatus(undefined);
|
||||
}
|
||||
{{else}}
|
||||
const controller = new {{../name}}();
|
||||
{{/if}}
|
||||
|
||||
return templateService.apiHandler({
|
||||
methodName: '{{name}}',
|
||||
controller,
|
||||
h,
|
||||
validatedArgs,
|
||||
successStatus: {{successStatus}},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
{{/each}}
|
||||
{{/each}}
|
||||
|
||||
{{#if useSecurity}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
function authenticateMiddleware(security: TsoaRoute.Security[] = []) {
|
||||
return async function runAuthenticationMiddleware(request: any, h: any) {
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
// keep track of failed auth attempts so we can hand back the most
|
||||
// recent one. This behavior was previously existing so preserving it
|
||||
// here
|
||||
const failedAttempts: any[] = [];
|
||||
const pushAndRethrow = (error: any) => {
|
||||
failedAttempts.push(error);
|
||||
throw error;
|
||||
};
|
||||
|
||||
const secMethodOrPromises: Promise<any>[] = [];
|
||||
for (const secMethod of security) {
|
||||
if (Object.keys(secMethod).length > 1) {
|
||||
const secMethodAndPromises: Promise<any>[] = [];
|
||||
|
||||
for (const name in secMethod) {
|
||||
secMethodAndPromises.push(
|
||||
hapiAuthentication(request, name, secMethod[name])
|
||||
.catch(pushAndRethrow)
|
||||
);
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
secMethodOrPromises.push(Promise.all(secMethodAndPromises)
|
||||
.then(users => { return users[0]; }));
|
||||
} else {
|
||||
for (const name in secMethod) {
|
||||
secMethodOrPromises.push(
|
||||
hapiAuthentication(request, name, secMethod[name])
|
||||
.catch(pushAndRethrow)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
try {
|
||||
request['user'] = await Promise.any(secMethodOrPromises);
|
||||
return request['user'];
|
||||
}
|
||||
catch(err) {
|
||||
// Show most recent error as response
|
||||
const error = failedAttempts.pop();
|
||||
if (isBoom(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const boomErr = boomify(error instanceof Error ? error : new Error(error.message), { statusCode: error.status || 500 });
|
||||
boomErr.output.statusCode = error.status || 401;
|
||||
boomErr.output.payload = {
|
||||
name: error.name,
|
||||
message: error.message,
|
||||
} as unknown as Payload;
|
||||
|
||||
throw boomErr;
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
}
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
{{#if useFileUploads}}
|
||||
function fileUploadMiddleware(fieldname: string, multiple: boolean = false) {
|
||||
return (request: Request, h: any) => {
|
||||
if (!request.payload[fieldname]) {
|
||||
return h.response(`${fieldname} is a required file(s).`).code(400);
|
||||
}
|
||||
|
||||
const calculateFileInfo = (reqFile: any) => new Promise((resolve, reject) => {
|
||||
const originalname = reqFile.hapi.filename;
|
||||
const headers = reqFile.hapi.headers;
|
||||
const contentTransferEncoding = headers['content-transfer-encoding'];
|
||||
const encoding = contentTransferEncoding &&
|
||||
contentTransferEncoding[0] &&
|
||||
contentTransferEncoding[0].toLowerCase() || '7bit';
|
||||
const mimetype = headers['content-type'] || 'text/plain';
|
||||
const buffer = reqFile._data
|
||||
return resolve({
|
||||
fieldname,
|
||||
originalname,
|
||||
buffer,
|
||||
encoding,
|
||||
mimetype,
|
||||
filename: originalname,
|
||||
size: buffer.toString().length,
|
||||
})
|
||||
});
|
||||
|
||||
if (!multiple) {
|
||||
return calculateFileInfo(request.payload[fieldname])
|
||||
.then(fileMetadata => {
|
||||
request.payload[fieldname] = fileMetadata;
|
||||
return h.continue;
|
||||
})
|
||||
.catch(err => h.response(err.toString()).code(500));
|
||||
} else {
|
||||
const promises = request.payload[fieldname].map((reqFile: any) => calculateFileInfo(reqFile));
|
||||
return Promise.all(promises)
|
||||
.then(filesMetadata => {
|
||||
request.payload[fieldname] = filesMetadata;
|
||||
return h.continue;
|
||||
})
|
||||
.catch(err => h.response(err.toString()).code(500));
|
||||
}
|
||||
};
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
218
node_modules/@tsoa/cli/dist/routeGeneration/templates/koa.hbs
generated
vendored
Normal file
218
node_modules/@tsoa/cli/dist/routeGeneration/templates/koa.hbs
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
import type { TsoaRoute } from '@tsoa/runtime';
|
||||
import { fetchMiddlewares, KoaTemplateService } from '@tsoa/runtime';
|
||||
{{#each controllers}}
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
import { {{name}} } from '{{modulePath}}';
|
||||
{{/each}}
|
||||
{{#if authenticationModule}}
|
||||
import { koaAuthentication } from '{{authenticationModule}}';
|
||||
// @ts-ignore - no great way to install types from subpackage
|
||||
{{/if}}
|
||||
{{#if iocModule}}
|
||||
import { iocContainer } from '{{iocModule}}';
|
||||
import type { IocContainer, IocContainerFactory } from '@tsoa/runtime';
|
||||
{{/if}}
|
||||
import type { Context, Next, Middleware, Request as KRequest, Response as KResponse } from 'koa';
|
||||
import type * as KoaRouter from '@koa/router';
|
||||
{{#if useFileUploads}}
|
||||
{{#if esm}}
|
||||
import multer from '@koa/multer';
|
||||
{{else}}
|
||||
const multer = require('@koa/multer');
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{#if authenticationModule}}
|
||||
const koaAuthenticationRecasted = koaAuthentication as (req: KRequest, securityName: string, scopes?: string[], res?: KResponse) => Promise<any>;
|
||||
{{/if}}
|
||||
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
const models: TsoaRoute.Models = {
|
||||
{{#each models}}
|
||||
"{{@key}}": {
|
||||
{{#if enums}}
|
||||
"dataType": "refEnum",
|
||||
"enums": {{{json enums}}},
|
||||
{{/if}}
|
||||
{{#if properties}}
|
||||
"dataType": "refObject",
|
||||
"properties": {
|
||||
{{#each properties}}
|
||||
"{{@key}}": {{{json this}}},
|
||||
{{/each}}
|
||||
},
|
||||
"additionalProperties": {{{json additionalProperties}}},
|
||||
{{/if}}
|
||||
{{#if type}}
|
||||
"dataType": "refAlias",
|
||||
"type": {{{json type}}},
|
||||
{{/if}}
|
||||
},
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
{{/each}}
|
||||
};
|
||||
const templateService = new KoaTemplateService(models, {{{ json minimalSwaggerConfig }}});
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
|
||||
{{#if useFileUploads}}
|
||||
export function RegisterRoutes(router: KoaRouter,opts?:{multer?:ReturnType<typeof multer>}) {
|
||||
{{else}}
|
||||
export function RegisterRoutes(router: KoaRouter) {
|
||||
{{/if}}
|
||||
|
||||
// ###########################################################################################################
|
||||
// NOTE: If you do not see routes for all of your controllers in this file, then you might not have informed tsoa of where to look
|
||||
// Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa
|
||||
// ###########################################################################################################
|
||||
|
||||
{{#if useFileUploads}}
|
||||
const upload = opts?.multer || multer({{{json multerOpts}}});
|
||||
{{/if}}
|
||||
|
||||
{{#each controllers}}
|
||||
{{#each actions}}
|
||||
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
|
||||
{{#each parameters}}
|
||||
{{@key}}: {{{json this}}},
|
||||
{{/each}}
|
||||
};
|
||||
router.{{method}}('{{fullPath}}',
|
||||
{{#if security.length}}
|
||||
authenticateMiddleware({{json security}}),
|
||||
{{/if}}
|
||||
{{#if uploadFile}}
|
||||
upload.fields([
|
||||
{{#each uploadFileName}}
|
||||
{
|
||||
name: {{json name}},
|
||||
{{#if maxCount}}
|
||||
maxCount: {{maxCount}}
|
||||
{{/if}}
|
||||
}{{#if @last}}{{else}},{{/if}}
|
||||
{{/each}}
|
||||
]),
|
||||
{{/if}}
|
||||
...(fetchMiddlewares<Middleware>({{../name}})),
|
||||
...(fetchMiddlewares<Middleware>({{../name}}.prototype.{{name}})),
|
||||
|
||||
async function {{../name}}_{{name}}(context: Context, next: Next) {
|
||||
|
||||
let validatedArgs: any[] = [];
|
||||
try {
|
||||
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, context, next });
|
||||
} catch (err) {
|
||||
const error = err as any;
|
||||
error.message ||= JSON.stringify({ fields: error.fields });
|
||||
context.status = error.status;
|
||||
context.throw(context.status, error.message, error);
|
||||
}
|
||||
|
||||
{{#if ../../iocModule}}
|
||||
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(context.request) : iocContainer;
|
||||
|
||||
const controller: any = await container.get<{{../name}}>({{../name}});
|
||||
if (typeof controller['setStatus'] === 'function') {
|
||||
controller.setStatus(undefined);
|
||||
}
|
||||
{{else}}
|
||||
const controller = new {{../name}}();
|
||||
{{/if}}
|
||||
|
||||
return templateService.apiHandler({
|
||||
methodName: '{{name}}',
|
||||
controller,
|
||||
context,
|
||||
validatedArgs,
|
||||
successStatus: {{successStatus}},
|
||||
});
|
||||
});
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
{{/each}}
|
||||
{{/each}}
|
||||
|
||||
{{#if useSecurity}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
function authenticateMiddleware(security: TsoaRoute.Security[] = []) {
|
||||
return async function runAuthenticationMiddleware(context: any, next: any) {
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
// keep track of failed auth attempts so we can hand back the most
|
||||
// recent one. This behavior was previously existing so preserving it
|
||||
// here
|
||||
const failedAttempts: any[] = [];
|
||||
const pushAndRethrow = (error: any) => {
|
||||
failedAttempts.push(error);
|
||||
throw error;
|
||||
};
|
||||
|
||||
const secMethodOrPromises: Promise<any>[] = [];
|
||||
for (const secMethod of security) {
|
||||
if (Object.keys(secMethod).length > 1) {
|
||||
const secMethodAndPromises: Promise<any>[] = [];
|
||||
|
||||
for (const name in secMethod) {
|
||||
secMethodAndPromises.push(
|
||||
koaAuthenticationRecasted(context.request, name, secMethod[name], context.response)
|
||||
.catch(pushAndRethrow)
|
||||
);
|
||||
}
|
||||
|
||||
secMethodOrPromises.push(Promise.all(secMethodAndPromises)
|
||||
.then(users => { return users[0]; }));
|
||||
} else {
|
||||
for (const name in secMethod) {
|
||||
secMethodOrPromises.push(
|
||||
koaAuthenticationRecasted(context.request, name, secMethod[name], context.response)
|
||||
.catch(pushAndRethrow)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
let success;
|
||||
try {
|
||||
const user = await Promise.any(secMethodOrPromises);
|
||||
success = true;
|
||||
context.request['user'] = user;
|
||||
}
|
||||
catch(err) {
|
||||
// Response was sent in middleware, abort
|
||||
if(context.response.body) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show most recent error as response
|
||||
const error = failedAttempts.pop();
|
||||
context.status = error.status || 401;
|
||||
context.throw(context.status, error.message, error);
|
||||
}
|
||||
|
||||
// Response was sent in middleware, abort
|
||||
if(context.response.body) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
await next();
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
}
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
}
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
Reference in New Issue
Block a user