Skip to content

Commit

Permalink
Merge pull request #1060 from FoalTS/openapi-security-requirements
Browse files Browse the repository at this point in the history
Show security requirements, servers and external doc of sub-controllers in Swagger auto-generated document
  • Loading branch information
LoicPoullain authored Apr 7, 2022
2 parents a8f939b + 9b47528 commit 18d0a2d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion packages/core/src/core/routes/make-controller-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] };
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/routes/make-controller-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 18d0a2d

Please sign in to comment.