Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

Commit 49c0132

Browse files
authored
feat: remove "aws-sdk" dependency (#33)
closes #25 BREAKING CHANGE: Removes compatibility to Serverless 1.3 and lower
1 parent d337cb7 commit 49c0132

File tree

6 files changed

+405
-407
lines changed

6 files changed

+405
-407
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-aws-documentation",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Serverless 1.0 plugin to add documentation and models to the serverless generated API Gateway",
55
"main": "src/index.js",
66
"scripts": {
@@ -15,11 +15,9 @@
1515
"codecov": "^1.0.1",
1616
"eslint": "^3.11.1",
1717
"istanbul": "^0.4.5",
18-
"jasmine": "^2.5.2",
19-
"proxyquire": "^1.7.10"
18+
"jasmine": "^2.5.2"
2019
},
2120
"dependencies": {
22-
"aws-sdk": "^2.7.12",
2321
"object-hash": "^1.1.7"
2422
}
2523
}

src/aws.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/documentation.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function _mapToObj(map) {
2828

2929
var autoVersion;
3030

31-
module.exports = function(AWS) {
31+
module.exports = function() {
3232
return {
3333
_createDocumentationPart: function _createDocumentationPart(part, def, knownLocation) {
3434
const location = part.locationProps.reduce((loc, property) => {
@@ -75,12 +75,11 @@ module.exports = function(AWS) {
7575
},
7676

7777
_updateDocumentation: function _updateDocumentation() {
78-
const apiGateway = new AWS.APIGateway(this.serverless.providers.aws.getCredentials());
79-
return apiGateway.getDocumentationVersion({
78+
const aws = this.serverless.providers.aws;
79+
return aws.request('APIGateway', 'getDocumentationVersion', {
8080
restApiId: this.restApiId,
8181
documentationVersion: this.getDocumentationVersion(),
82-
}).promise()
83-
.then(() => {
82+
}).then(() => {
8483
const msg = 'documentation version already exists, skipping upload';
8584
console.info('-------------------');
8685
console.info(msg);
@@ -92,26 +91,30 @@ module.exports = function(AWS) {
9291

9392
return Promise.reject(err);
9493
})
95-
.then(() => apiGateway.getDocumentationParts({
96-
restApiId: this.restApiId,
97-
limit: 9999,
98-
}).promise())
99-
.then(results => results.items.map(part => apiGateway.deleteDocumentationPart({
100-
documentationPartId: part.id,
101-
restApiId: this.restApiId,
102-
}).promise()))
94+
.then(() =>
95+
aws.request('APIGateway', 'getDocumentationParts', {
96+
restApiId: this.restApiId,
97+
limit: 9999,
98+
})
99+
)
100+
.then(results => results.items.map(
101+
part => aws.request('APIGateway', 'deleteDocumentationPart', {
102+
documentationPartId: part.id,
103+
restApiId: this.restApiId,
104+
})
105+
))
103106
.then(promises => Promise.all(promises))
104107
.then(() => this.documentationParts.reduce((promise, part) => {
105108
return promise.then(() => {
106109
part.properties = JSON.stringify(part.properties);
107-
return apiGateway.createDocumentationPart(part).promise();
110+
return aws.request('APIGateway', 'createDocumentationPart', part);
108111
});
109112
}, Promise.resolve()))
110-
.then(() => apiGateway.createDocumentationVersion({
113+
.then(() => aws.request('APIGateway', 'createDocumentationVersion', {
111114
restApiId: this.restApiId,
112115
documentationVersion: this.getDocumentationVersion(),
113116
stageName: this.options.stage,
114-
}).promise());
117+
}));
115118
},
116119

117120
getGlobalDocumentationParts: function getGlobalDocumentationParts() {

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
const documentation = require('./documentation');
33
const models = require('./models');
4-
const aws = require('./aws.js')();
54

65
class ServerlessAWSDocumentation {
76
constructor(serverless, options) {
@@ -10,7 +9,7 @@ class ServerlessAWSDocumentation {
109
this.provider = 'aws'
1110

1211
Object.assign(this, models);
13-
Object.assign(this, documentation(aws));
12+
Object.assign(this, documentation());
1413

1514
this.customVars = this.serverless.variables.service.custom;
1615
const naming = this.serverless.providers.aws.naming;

0 commit comments

Comments
 (0)