@8select/serverless-plugin-api-docs
Version:
serverless plugin that generates docs function to return swagger ui
64 lines (54 loc) • 1.59 kB
JavaScript
const packagePath = 'node_modules/@8select/serverless-plugin-api-docs'
class ServerlessPlugin {
constructor(serverless, options) {
this.serverless = serverless
this.options = options
this.config = this.serverless.service.custom.documentation
this.hooks = {
'package:initialize': this.createDocs.bind(this),
}
}
createDocs() {
const name = `${this.serverless.service.serviceObject.name}-${this.options.stage}-docs`
const handlerPath = `${packagePath}/docs.js`
const functionName = this.config.name || 'docs'
const docsFunction = {
[functionName]: {
name,
memorySize: 128,
timeout: 30,
handler: `${packagePath}/docs.handler`,
events: [
{
http: {
method: 'GET',
path: 'docs',
cors: true,
},
},
],
package: {
include: [handlerPath],
},
environment: {
CONTENT_URL: this.config.contentUrl,
HOST_URL: {
'Fn::Join': [
'',
[
{
Ref: 'ApiGatewayRestApi',
},
`.execute-api.${this.serverless.service.provider.region}.amazonaws.com/`,
],
],
},
},
},
}
this.serverless.service.functions = Object.assign(this.serverless.service.functions, {}, docsFunction)
this.serverless.cli.log(`GET /${functionName} function successfull added`)
}
}
module.exports = ServerlessPlugin