From 5634e187355b6afe611749852530d21422a18bc8 Mon Sep 17 00:00:00 2001 From: Hage Yaapa Date: Mon, 22 Oct 2018 16:43:10 +0530 Subject: [PATCH] feat: add 'x-visibility' extension property to OpenAPI spec Add `x-visibility` extension property to OpenAPI spec. --- packages/rest/src/router/routing-table.ts | 1 + .../rest.server.open-api-spec.unit.ts | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/packages/rest/src/router/routing-table.ts b/packages/rest/src/router/routing-table.ts index cbc09ec926c8..59dbbcc6c4c3 100644 --- a/packages/rest/src/router/routing-table.ts +++ b/packages/rest/src/router/routing-table.ts @@ -156,6 +156,7 @@ export class RoutingTable { const paths: PathObject = {}; for (const route of this._router.list()) { + if (route.spec['x-visibility'] === 'undocumented') continue; if (!paths[route.path]) { paths[route.path] = {}; } diff --git a/packages/rest/test/unit/rest.server/rest.server.open-api-spec.unit.ts b/packages/rest/test/unit/rest.server/rest.server.open-api-spec.unit.ts index 0fe7a523eb8a..52b53f624ffe 100644 --- a/packages/rest/test/unit/rest.server/rest.server.open-api-spec.unit.ts +++ b/packages/rest/test/unit/rest.server/rest.server.open-api-spec.unit.ts @@ -86,6 +86,27 @@ describe('RestServer.getApiSpec()', () => { }); }); + it('ignores routes marked as "x-visibility" via app.route(route)', () => { + function greet() {} + function meet() {} + server.route( + 'get', + '/greet', + {'x-visibility': 'undocumented', responses: {}, spec: {}}, + greet, + ); + server.route('get', '/meet', {responses: {}, spec: {}}, meet); + const spec = server.getApiSpec(); + expect(spec.paths).to.eql({ + '/meet': { + get: { + responses: {}, + spec: {}, + }, + }, + }); + }); + it('returns routes registered via app.route(..., Controller, method)', () => { class MyController { greet() {} @@ -113,6 +134,46 @@ describe('RestServer.getApiSpec()', () => { }); }); + it('ignores routes marked as "x-visibility" via app.route(..., Controller, method)', () => { + class GreetController { + greet() {} + } + + class MeetController { + meet() {} + } + + server.route( + 'get', + '/greet', + {'x-visibility': 'undocumented', responses: {}}, + GreetController, + createControllerFactoryForClass(GreetController), + 'greet', + ); + + server.route( + 'get', + '/meet', + {responses: {}}, + MeetController, + createControllerFactoryForClass(MeetController), + 'meet', + ); + + const spec = server.getApiSpec(); + expect(spec.paths).to.eql({ + '/meet': { + get: { + responses: {}, + 'x-controller-name': 'MeetController', + 'x-operation-name': 'meet', + tags: ['MeetController'], + }, + }, + }); + }); + it('honors tags in the operation spec', () => { class MyController { @get('/greet', {responses: {'200': {description: ''}}, tags: ['MyTag']})