Skip to content

Commit

Permalink
feat: add 'x-visibility' extension property to OpenAPI spec
Browse files Browse the repository at this point in the history
Add `x-visibility` extension property to OpenAPI spec.
  • Loading branch information
Hage Yaapa authored and hacksparrow committed Oct 24, 2018
1 parent 22024f7 commit 5634e18
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/rest/src/router/routing-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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']})
Expand Down

0 comments on commit 5634e18

Please sign in to comment.