From c30a31c8ca79ae7534616713e2e6a53b0b394e33 Mon Sep 17 00:00:00 2001 From: Jared Evans Date: Thu, 18 May 2023 22:52:53 +0100 Subject: [PATCH 1/2] improve being able to use with serverless 1 (though you shouldn't) --- src/openAPIGenerator.js | 50 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/openAPIGenerator.js b/src/openAPIGenerator.js index 65a2392..65d8386 100644 --- a/src/openAPIGenerator.js +++ b/src/openAPIGenerator.js @@ -71,30 +71,38 @@ class OpenAPIGenerator { this.customVars = this.serverless.variables.service.custom; - this.serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', { - properties: { - documentation: { type: 'object' }, - }, - required: ['documentation'], - }); + if (this.getServerlessVersion() > 1) { + this.serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', { + properties: { + documentation: { type: 'object' }, + }, + required: ['documentation'], + }); - this.serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'httpApi', { - properties: { - documentation: { type: 'object' }, - }, - required: ['documentation'], - }); - - this.serverless.configSchemaHandler.defineFunctionProperties('aws', { - properties: { - summary: {type: 'string'}, - servers: {anyOf: [{type:'object'}, {type:'array'}]}, - } - }) + + this.serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'httpApi', { + properties: { + documentation: { type: 'object' }, + }, + required: ['documentation'], + }); + + + this.serverless.configSchemaHandler.defineFunctionProperties('aws', { + properties: { + summary: {type: 'string'}, + servers: {anyOf: [{type:'object'}, {type:'array'}]}, + } + }) + } + } + + getServerlessVersion() { + return this.serverless.version[0]; } log(str, type = this.defaultLog) { - switch(this.serverless.version[0]) { + switch(this.getServerlessVersion()) { case '2': let colouredString = str if (type === 'error') { @@ -111,7 +119,7 @@ class OpenAPIGenerator { break default: - process.stdout.write(str.join(' ')) + process.stdout.write(str) break } } From d12d2d362579da874082365dcd904773fbe89b70 Mon Sep 17 00:00:00 2001 From: Jared Evans Date: Thu, 18 May 2023 22:53:06 +0100 Subject: [PATCH 2/2] fix serverless 1 config --- test/serverless-tests/serverless 1/serverless.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/serverless-tests/serverless 1/serverless.yml b/test/serverless-tests/serverless 1/serverless.yml index 6b5d3f5..1e59978 100644 --- a/test/serverless-tests/serverless 1/serverless.yml +++ b/test/serverless-tests/serverless 1/serverless.yml @@ -13,7 +13,7 @@ functions: handler: handler.create events: - http: - path: create + path: create/{username} method: post documentation: summary: Create User