From b8e086858bfaeb4dba8765231f74282fa70ceb29 Mon Sep 17 00:00:00 2001 From: Justin Lyons Date: Tue, 26 Feb 2019 11:47:40 -0500 Subject: [PATCH 1/5] Adding yaml and json to oas30 and swagger docs --- .idea/aws.xml | 11 ++ .idea/codeStyles/Project.xml | 26 +++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/encodings.xml | 4 + .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/misc.xml | 13 ++ .idea/modules.xml | 8 + .idea/serverless-export-swagger.iml | 12 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 158 +++++++++++++++++++ src/index.js | 66 +++++++- 11 files changed, 313 insertions(+), 2 deletions(-) create mode 100644 .idea/aws.xml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/serverless-export-swagger.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/aws.xml b/.idea/aws.xml new file mode 100644 index 0000000..1ea8305 --- /dev/null +++ b/.idea/aws.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..fa043ab --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,26 @@ + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..03d9549 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..838cad6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + ApexVCS + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2f45d35 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/serverless-export-swagger.iml b/.idea/serverless-export-swagger.iml new file mode 100644 index 0000000..6f63a63 --- /dev/null +++ b/.idea/serverless-export-swagger.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..594dfe5 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + getswagger + key + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1551198262428 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 55a348d0037107ba738aa968e6cebe06afd61bb9 Mon Sep 17 00:00:00 2001 From: Justin Lyons Date: Wed, 27 Feb 2019 09:46:51 -0500 Subject: [PATCH 4/5] Add new options from serverless to allow choice of openapi and yaml files. Renamed getBucketAndKey to getServerlessOptions. --- README.md | 3 +++ package.json | 2 +- src/index.js | 27 ++++++++++++++++----------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 34de199..afc2931 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,7 @@ custom: s3KeyName: 'swagger/api.json' # optional, default: private acl: public-read + #optional settings to upload yaml and openapi files. + uploadOpenAPI: true + uploadYaml: true ``` diff --git a/package.json b/package.json index 64b7c5b..e2d8cc5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-export-swagger", - "version": "2.0.0", + "version": "2.0.1", "description": "export swagger definition to s3 ", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 76f04e2..0ad8def 100644 --- a/src/index.js +++ b/src/index.js @@ -101,14 +101,16 @@ const uploadSwaggerToS3 = async function uploadSwaggerToS3(swagger, bucket, key, }).promise() } -const getBucketAndKey = function getBucketAndKey(serverless) { +const getServerlessOptions = function getServerlessOptions(serverless) { const bucket = serverless.service.custom.swaggerDestinations.s3BucketName const key = serverless.service.custom.swaggerDestinations.s3KeyName + const openapi = serverless.service.custom.swaggerDestinations.uploadOpenAPI + const yaml = serverless.service.custom.swaggerDestinations.uploadYaml if (!bucket || !key) { throw new Error('ExportSwagger: Bucket name and key are required fields') } - return { bucket, key } -}; + return { bucket, key, openapi, yaml } +} const exportApi = async function exportApi(serverless) { const provider = serverless.getProvider('aws') @@ -116,20 +118,23 @@ const exportApi = async function exportApi(serverless) { const region = provider.getRegion() const stage = provider.getStage() const serviceName = serverless.service.getServiceName() - const { bucket, key } = getBucketAndKey(serverless) + const { bucket, key, openapi, yaml } = getServerlessOptions(serverless) const apiName = await getApiName(serviceName, stage, region, awsCredentials) const swagger = await getSwagger(apiName, stage, region, awsCredentials) const swaggeryaml = await getSwaggerYaml(apiName, stage, region, awsCredentials) const oas30 = await getOpenapi(apiName, stage, region, awsCredentials) const oas30yaml = await getOpenapiYaml(apiName, stage, region, awsCredentials) - var swaggerKey = key+'-swagger.json' + const swaggerKey = `${key}-swagger.json` await uploadSwaggerToS3(swagger, bucket, swaggerKey, region, awsCredentials) - var oas30Key = key+'-oas30.json' - await uploadSwaggerToS3(oas30, bucket, oas30Key, region, awsCredentials) - var swaggerYamlKey = key+'-swagger.yaml' - await uploadSwaggerToS3(swaggeryaml, bucket, swaggerYamlKey, region, awsCredentials) - var oas30YamlKey = key+'-oas30.yaml' - await uploadSwaggerToS3(oas30yaml, bucket, oas30YamlKey, region, awsCredentials) + if (typeof openapi !== 'undefined') { + const oas30Key = `${key}-oas30.json` + await uploadSwaggerToS3(oas30, bucket, oas30Key, region, awsCredentials) } + if (typeof yaml !== 'undefined') { + const swaggerYamlKey = `${key}-swagger.yaml` + await uploadSwaggerToS3(swaggeryaml, bucket, swaggerYamlKey, region, awsCredentials) } + if (typeof openapi !== 'undefined' && typeof yaml !== 'undefined') { + const oas30YamlKey = `${key}-oas30.yaml` + await uploadSwaggerToS3(oas30yaml, bucket, oas30YamlKey, region, awsCredentials) } serverless.cli.consoleLog('ExportSwagger: Files uploaded to s3.') } From 30574c54285c9299cfe8ca45b1b4bc6c2779b5c8 Mon Sep 17 00:00:00 2001 From: Justin Lyons Date: Wed, 27 Feb 2019 09:56:09 -0500 Subject: [PATCH 5/5] Fix Readme to not use file type --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index afc2931..3d620ab 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ plugins: custom: swaggerDestinations: s3BucketName: 'bucket-name' - s3KeyName: 'swagger/api.json' + s3KeyName: 'swagger/api' # optional, default: private acl: public-read #optional settings to upload yaml and openapi files.