Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function givenNumberOfRoutes(base: string, num: number) {
const spec = anOpenApiSpec();
let i = 0;
while (i < num) {
// Add 1/4 paths with vars
if (i % 4 === 0) {
spec.withOperationReturningString(
'get',
`${base}/group${i}/{version}`,
`greet${i}`,
);
} else {
spec.withOperationReturningString(
'get',
`${base}/group${i}/version_${i}`,
`greet${i}`,
);
}
it('returns spec defined via @api()', () => {
const expectedSpec = anOpenApiSpec()
.withOperationReturningString('get', '/greet', 'greet')
.build();
@api(expectedSpec)
class MyController {
greet() {
return 'Hello world!';
}
}
const actualSpec = getControllerSpec(MyController);
expect(actualSpec).to.eql(expectedSpec);
});
it('preserves routes specified in app.api()', () => {
function status() {}
server.api(
anOpenApiSpec()
.withOperation('get', '/status', {
'x-operation': status,
responses: {},
})
.build(),
);
function greet() {}
server.route('get', '/greet', {responses: {}}, greet);
const spec = server.getApiSpec();
expect(spec.paths).to.eql({
'/greet': {
get: {
responses: {},
},
it('finds simple "GET /hello/world" endpoint', () => {
const spec = anOpenApiSpec()
.withOperationReturningString('get', '/hello/{msg}', 'greet')
.withOperationReturningString('get', '/hello/world', 'greetWorld')
.build();
class TestController {}
const table = givenRoutingTable();
table.registerController(spec, TestController);
const request = givenRequest({
method: 'get',
url: '/hello/world',
});
const route = table.find(request);
expect(route)
async function givenAppWithController() {
await givenAnApplication();
app.bind('application.name').to('SequenceApp');
const apispec = anOpenApiSpec()
.withOperation('get', '/name', {
'x-operation-name': 'getName',
responses: {
'200': {
schema: {
type: 'string',
},
description: '',
},
},
})
.build();
@api(apispec)
class InfoController {
constructor(@inject('application.name') public appName: string) {}
function givenControllerInApp() {
const apispec = anOpenApiSpec()
.withOperation('get', '/whoAmI', {
'x-operation-name': 'whoAmI',
responses: {
'200': {
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor(
function givenControllerInApp() {
const apispec = anOpenApiSpec()
.withOperation('get', '/whoAmI', {
'x-operation-name': 'whoAmI',
responses: {
'200': {
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor(@inject(SecurityBindings.USER) private user: UserProfile) {}
function givenControllerInApp() {
const apispec = anOpenApiSpec()
.withOperation('get', '/whoAmI', {
'x-operation-name': 'whoAmI',
responses: {
'200': {
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor() {}
function givenControllerInApp() {
const apispec = anOpenApiSpec()
.withOperation('get', '/whoAmI', {
'x-operation-name': 'whoAmI',
responses: {
'200': {
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor(