diff --git a/packages/core/src/core/routes/make-controller-routes.spec.ts b/packages/core/src/core/routes/make-controller-routes.spec.ts index 683d91ecec..2341c56f5f 100644 --- a/packages/core/src/core/routes/make-controller-routes.spec.ts +++ b/packages/core/src/core/routes/make-controller-routes.spec.ts @@ -887,7 +887,51 @@ describe('makeControllerRoutes', () => { } as IApiPaths); }); - it('but with not the root servers, security requirements and externalDocs in the paths.', () => { + it('with the sub-controllers\' servers, security requirements and externalDocs in the paths.', () => { + const server: IApiServer = { url: 'http://example.com' }; + const externalDocs: IApiExternalDocumentation = { url: 'http://example.com/docs' }; + const securityRequirement: IApiSecurityRequirement = { a: [ 'b' ] }; + + @ApiServer(server) + @ApiExternalDoc(externalDocs) + @ApiSecurityRequirement(securityRequirement) + class UserController { + @Get('/foo') + foo(){} + } + + @ApiInfo(infoMetadata) + class ApiController { + subControllers = [ + controller('/users', UserController), + ] + } + + class AppController { + subControllers = [ + controller('/api', ApiController) + ]; + } + + Array.from(makeControllerRoutes(AppController, services)); + const document = openApi.getDocument(ApiController); + strictEqual(document.servers, undefined); + strictEqual(document.externalDocs, undefined); + strictEqual(document.security, undefined); + + deepStrictEqual(document.paths, { + '/users/foo': { + get: { + externalDocs, + responses: {}, + security: [ securityRequirement ], + servers: [ server ], + } + } + }); + }); + + it('but without the root servers, security requirements and externalDocs in the paths.', () => { const server: IApiServer = { url: 'http://example.com' }; const externalDocs: IApiExternalDocumentation = { url: 'http://example.com/docs' }; const securityRequirement: IApiSecurityRequirement = { a: [ 'b' ] }; diff --git a/packages/core/src/core/routes/make-controller-routes.ts b/packages/core/src/core/routes/make-controller-routes.ts index 4679740c97..4452b888e7 100644 --- a/packages/core/src/core/routes/make-controller-routes.ts +++ b/packages/core/src/core/routes/make-controller-routes.ts @@ -95,7 +95,7 @@ export function* makeControllerRoutes( const controllerComponents = openapi ? getApiComponents(controllerClass, controller) : {}; const controllerOperation = openapi ? getApiCompleteOperation(controllerClass, controller) : { responses: {} }; const controllerTags = openapi ? getApiTags(controllerClass) : undefined; - if (openapi) { + if (openapi && info) { delete controllerOperation.servers; delete controllerOperation.externalDocs; delete controllerOperation.security;