Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {}
async getName(): Promise {
return this.appName;
}
}
givenControllerInServer(InfoController);
}
/* ===== HELPERS ===== */
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(AuthenticationBindings.CURRENT_USER) private user: UserProfile,
) {}
@authenticate('BasicStrategy')
async whoAmI(): Promise {
return this.user.id;
}
}
app.controller(MyController);
}
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(AuthenticationBindings.CURRENT_USER) private user: UserProfile,
) {}
@authenticate(AUTH_STRATEGY_NAME)
async whoAmI(): Promise {
return this.user.id;
}
}
app.controller(MyController);
}
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) {}
@authenticate(AUTH_STRATEGY_NAME)
async whoAmI(): Promise {
return this.user[securityId];
}
}
app.controller(MyController);
}
function givenControllerInApp() {
const apispec = anOpenApiSpec()
.withOperation('get', '/whoAmI', {
'x-operation-name': 'whoAmI',
responses: {
'200': {
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor() {}
@authenticate('basic')
async whoAmI(
@inject(SecurityBindings.USER) userProfile: UserProfile,
): Promise {
if (!userProfile) return 'userProfile is undefined';
if (!userProfile[securityId]) return 'userProfile id is undefined';
return userProfile[securityId];
}
}
app.controller(MyController);
}