Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 'x-visibility' extension property to OpenAPI spec #1896

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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': {
bajtos marked this conversation as resolved.
Show resolved Hide resolved
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: {}},
bajtos marked this conversation as resolved.
Show resolved Hide resolved
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