Skip to content

Commit 3e3aae7

Browse files
committed
Merge branch 'master' of github.com:lukeautry/tsoa into ts-4.1
2 parents 1ecc7d8 + 5de342b commit 3e3aae7

36 files changed

+428
-63
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
2-
packages/**/dist
2+
dist
33
.eslintrc.js

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "3.3.0",
2+
"version": "3.4.0",
33
"npmClient": "yarn",
44
"useWorkspaces": true,
55
"command": {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "tsoa-monorepo",
33
"description": "Build swagger-compliant REST APIs using TypeScript and Node",
4-
"version": "3.2.1",
54
"private": true,
65
"keywords": [
76
"typescript",

packages/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tsoa/cli",
33
"description": "Build swagger-compliant REST APIs using TypeScript and Node",
4-
"version": "3.3.0",
4+
"version": "3.4.0",
55
"main": "./dist/index.js",
66
"typings": "./dist/index.d.ts",
77
"keywords": [
@@ -28,7 +28,7 @@
2828
"author": "Luke Autry <lukeautry@gmail.com> (http://www.lukeautry.com)",
2929
"license": "MIT",
3030
"dependencies": {
31-
"@tsoa/runtime": "^3.3.0",
31+
"@tsoa/runtime": "^3.4.0",
3232
"deepmerge": "^4.2.2",
3333
"fs-extra": "^8.1.0",
3434
"glob": "^7.1.6",

packages/cli/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './module/generate-spec';
22
export * from './module/generate-routes';
3+
export { Config } from '@tsoa/runtime';
34
export { runCLI, ExtendedRoutesConfig, ExtendedSpecConfig } from './cli';

packages/cli/src/metadataGeneration/typeResolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ export class TypeResolver {
295295
}
296296
}
297297

298+
if (ts.isParenthesizedTypeNode(this.typeNode)) {
299+
return new TypeResolver(this.typeNode.type, this.current, this.typeNode, this.context, this.referencer).resolve();
300+
}
301+
298302
if (this.typeNode.kind !== ts.SyntaxKind.TypeReference) {
299303
throw new GenerateMetadataError(`Unknown type: ${ts.SyntaxKind[this.typeNode.kind]}`, this.typeNode);
300304
}
@@ -775,7 +779,7 @@ export class TypeResolver {
775779
}
776780

777781
const modelTypeDeclaration = node as UsableDeclaration | ts.EnumMember;
778-
return (modelTypeDeclaration.name as ts.Identifier).text === typeName;
782+
return (modelTypeDeclaration.name as ts.Identifier)?.text === typeName;
779783
}) as Array<Exclude<UsableDeclaration | ts.EnumMember, ts.PropertySignature>>;
780784

781785
if (!modelTypes.length) {

packages/cli/src/module/generate-spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { SpecGenerator2 } from '../swagger/specGenerator2';
77
import { SpecGenerator3 } from '../swagger/specGenerator3';
88
import { fsExists, fsMkDir, fsWriteFile } from '../utils/fs';
99

10+
export const getSwaggerOutputPath = (swaggerConfig: ExtendedSpecConfig) => {
11+
const ext = swaggerConfig.yaml ? 'yaml' : 'json';
12+
const specFileBaseName = swaggerConfig.specFileBaseName || 'swagger';
13+
14+
return `${swaggerConfig.outputDirectory}/${specFileBaseName}.${ext}`;
15+
};
16+
1017
export const generateSpec = async (
1118
swaggerConfig: ExtendedSpecConfig,
1219
compilerOptions?: ts.CompilerOptions,
@@ -36,9 +43,9 @@ export const generateSpec = async (
3643
if (swaggerConfig.yaml) {
3744
data = YAML.stringify(JSON.parse(data), 10);
3845
}
39-
const ext = swaggerConfig.yaml ? 'yaml' : 'json';
4046

41-
await fsWriteFile(`${swaggerConfig.outputDirectory}/swagger.${ext}`, data, { encoding: 'utf8' });
47+
const outputPath = getSwaggerOutputPath(swaggerConfig);
48+
await fsWriteFile(outputPath, data, { encoding: 'utf8' });
4249

4350
return metadata;
4451
};

packages/cli/src/routeGeneration/templates/express.hbs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { expressAuthentication } from '{{authenticationModule}}';
1111
{{/if}}
1212
{{#if iocModule}}
1313
import { iocContainer } from '{{iocModule}}';
14+
import { IocContainer, IocContainerFactory } from '@tsoa/runtime';
1415
{{/if}}
1516
import * as express from 'express';
1617

@@ -44,7 +45,7 @@ const validationService = new ValidationService(models);
4445

4546
// 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
4647

47-
export function RegisterRoutes(app: express.Express) {
48+
export function RegisterRoutes(app: express.Router) {
4849
// ###########################################################################################################
4950
// 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
5051
// Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa
@@ -72,7 +73,9 @@ export function RegisterRoutes(app: express.Express) {
7273
}
7374

7475
{{#if ../../iocModule}}
75-
const controller: any = iocContainer.get<{{../name}}>({{../name}});
76+
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
77+
78+
const controller: any = container.get<{{../name}}>({{../name}});
7679
if (typeof controller['setStatus'] === 'function') {
7780
controller.setStatus(undefined);
7881
}

packages/cli/src/routeGeneration/templates/hapi.hbs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { hapiAuthentication } from '{{authenticationModule}}';
1111
{{/if}}
1212
{{#if iocModule}}
1313
import { iocContainer } from '{{iocModule}}';
14+
import { IocContainer, IocContainerFactory } from '@tsoa/runtime';
1415
{{/if}}
1516
import { boomify, Payload } from '@hapi/boom';
1617

@@ -85,7 +86,9 @@ export function RegisterRoutes(server: any) {
8586
}
8687

8788
{{#if ../../iocModule}}
88-
const controller: any = iocContainer.get<{{../name}}>({{../name}});
89+
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
90+
91+
const controller: any = container.get<{{../name}}>({{../name}});
8992
if (typeof controller['setStatus'] === 'function') {
9093
controller.setStatus(undefined);
9194
}

packages/cli/src/routeGeneration/templates/koa.hbs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { koaAuthentication } from '{{authenticationModule}}';
1515
{{/if}}
1616
{{#if iocModule}}
1717
import { iocContainer } from '{{iocModule}}';
18+
import { IocContainer, IocContainerFactory } from '@tsoa/runtime';
1819
{{/if}}
1920
import * as KoaRouter from '@koa/router';
2021

@@ -75,7 +76,9 @@ export function RegisterRoutes(router: KoaRouter) {
7576
}
7677

7778
{{#if ../../iocModule}}
78-
const controller: any = iocContainer.get<{{../name}}>({{../name}});
79+
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
80+
81+
const controller: any = container.get<{{../name}}>({{../name}});
7982
if (typeof controller['setStatus'] === 'function') {
8083
controller.setStatus(undefined);
8184
}

0 commit comments

Comments
 (0)