Skip to content

Commit

Permalink
Nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
HoldYourWaffle committed Aug 24, 2019
1 parent 879c29c commit f5fa9e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"lint-staged": {
"*.{js,ts}": [
"prettier --write",
"git add"
"prettier --write",
"git add"
]
},
"scripts": {
Expand All @@ -41,7 +41,7 @@
"postversion": "git push origin master && git push --follow-tags",
"pretest": "cross-env NODE_ENV=tsoa_test ts-node ./tests/prepare.ts",
"loading-msg-for-tests": "echo '... starting a test run to ensure quality. Note this takes some time as tests do not run in parallel (by design) ...' ",
"test": "node ensureYarn.js && tsc -p ./tests/tsconfig.json --noEmit && yarn loading-msg-for-tests && cross-env NODE_ENV=tsoa_test mocha **/*.spec.ts --exit --require ts-node/register --timeout 5000",
"test": "node ensureYarn.js && tsc -p ./tests/tsconfig.json --noEmit && yarn loading-msg-for-tests && cross-env NODE_ENV=tsoa_test mocha **/*.spec.ts --exit --require ts-node/register --timeout 5000",
"pre-commit": "yarn lint && yarn test",
"tsc": "tsc"
},
Expand Down
9 changes: 5 additions & 4 deletions src/metadataGeneration/typeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class TypeResolver {
refName: refNameWithGenerics,
} as Tsoa.ReferenceType;

referenceType.properties = (referenceType.properties as Tsoa.Property[]).concat(properties);
referenceType.properties = referenceType.properties!.concat(properties);
localReferenceTypeCache[refNameWithGenerics] = referenceType;

if (example) {
Expand Down Expand Up @@ -630,14 +630,15 @@ export class TypeResolver {
}

// Class model
// XXX syntax kind is never checked?
const classDeclaration = node as ts.ClassDeclaration;
const properties = classDeclaration.members
.filter(member => {
const ignore = isIgnored(member);
return !ignore;
})
.filter(member => member.kind === ts.SyntaxKind.PropertyDeclaration)
.filter(member => this.hasPublicModifier(member)) as Array<ts.PropertyDeclaration | ts.ParameterDeclaration>;
.filter((member) => member.kind === ts.SyntaxKind.PropertyDeclaration)
.filter((member) => this.hasPublicModifier(member)) as Array<ts.PropertyDeclaration | ts.ParameterDeclaration>; // ParameterDeclaration because properties can be defined by constructor parameters

const classConstructor = classDeclaration.members.find(member => member.kind === ts.SyntaxKind.Constructor) as ts.ConstructorDeclaration;

Expand Down Expand Up @@ -713,7 +714,7 @@ export class TypeResolver {
const baseEntityName = t.expression as ts.EntityName;
const referenceType = this.getReferenceType(baseEntityName);
if (referenceType.properties) {
referenceType.properties.forEach(property => properties.push(property));
properties.push(...referenceType.properties);
}
});
});
Expand Down
14 changes: 6 additions & 8 deletions src/routeGeneration/routeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ export class RouteGenerator {
}

private buildContent(middlewareTemplate: string, pathTransformer: (path: string) => string) {
handlebars.registerHelper('json', (context: any) => {
return JSON.stringify(context);
});
const additionalPropsHelper = (additionalProperties: TsoaRoute.ModelSchema['additionalProperties']) => {
handlebars.registerHelper('json', (context: any) => JSON.stringify(context));

handlebars.registerHelper('additionalPropsHelper', (additionalProperties: TsoaRoute.ModelSchema['additionalProperties']) => {
if (additionalProperties) {
// Then the model for this type explicitly allows additional properties and thus we should assign that
return JSON.stringify(additionalProperties);
Expand All @@ -75,8 +74,7 @@ export class RouteGenerator {
} else {
return assertNever(this.minimalSwaggerConfig.noImplicitAdditionalProperties);
}
};
handlebars.registerHelper('additionalPropsHelper', additionalPropsHelper);
});

const routesTemplate = handlebars.compile(middlewareTemplate, { noEscape: true });
const authenticationModule = this.options.authenticationModule ? this.getRelativeImportPath(this.options.authenticationModule) : undefined;
Expand Down Expand Up @@ -178,12 +176,12 @@ export class RouteGenerator {

private buildParameterSchema(source: Tsoa.Parameter): TsoaRoute.ParameterSchema {
const property = this.buildProperty(source.type);
const parameter = {
const parameter: TsoaRoute.ParameterSchema = {
default: source.default,
in: source.in,
name: source.name,
required: source.required ? true : undefined,
} as TsoaRoute.ParameterSchema;
};
const parameterSchema = Object.assign(parameter, property);

if (Object.keys(source.validators).length > 0) {
Expand Down

0 comments on commit f5fa9e2

Please sign in to comment.