Skip to content

Commit

Permalink
Fix Duplicated declaration.
Browse files Browse the repository at this point in the history
  • Loading branch information
tripodsgames committed Aug 14, 2020
1 parent edab77b commit ceee1a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions dist/server/server-container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export declare class ServerContainer {
serviceFactory: ServiceFactory;
paramConverters: Map<Function, ParameterConverter>;
router: express.Router;
resolvedPaths: Map<string, express.Router>;
private debugger;
private upload;
private serverClasses;
Expand Down
7 changes: 6 additions & 1 deletion dist/server/server-container.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/server/server-container.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/server/server-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ServerContainer {
public serviceFactory: ServiceFactory = new DefaultServiceFactory();
public paramConverters: Map<Function, ParameterConverter> = new Map<Function, ParameterConverter>();
public router: express.Router;
public resolvedPaths: Map<string, express.Router> = new Map<string, express.Router>();

private debugger = {
build: debug('typescript-rest:server-container:build'),
Expand All @@ -66,6 +67,7 @@ export class ServerContainer {
return serviceClass;
}

// HERE
public registerServiceMethod(target: Function, methodName: string): ServiceMethod {
if (methodName) {
this.pathsResolved = false;
Expand Down Expand Up @@ -257,8 +259,10 @@ export class ServerContainer {
declaredHttpMethods = new Set<HttpMethod>();
this.paths.set(resolvedPath, declaredHttpMethods);
}
if (declaredHttpMethods.has(serviceMethod.httpMethod)) {
if (declaredHttpMethods.has(serviceMethod.httpMethod) && this.resolvedPaths.get(resolvedPath) === this.router) {
throw Error(`Duplicated declaration for path [${resolvedPath}], method [${serviceMethod.httpMethod}].`);
} else {
this.resolvedPaths.set(resolvedPath, this.router);
}
declaredHttpMethods.add(serviceMethod.httpMethod);
serviceMethod.resolvedPath = resolvedPath;
Expand Down

0 comments on commit ceee1a9

Please sign in to comment.