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

Commit

Permalink
feat: remove "aws-sdk" dependency (#33)
Browse files Browse the repository at this point in the history
closes #25

BREAKING CHANGE:
Removes compatibility to Serverless 1.3 and lower
  • Loading branch information
tchock authored Apr 4, 2017
1 parent d337cb7 commit 49c0132
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 407 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-aws-documentation",
"version": "0.6.0",
"version": "0.7.0",
"description": "Serverless 1.0 plugin to add documentation and models to the serverless generated API Gateway",
"main": "src/index.js",
"scripts": {
Expand All @@ -15,11 +15,9 @@
"codecov": "^1.0.1",
"eslint": "^3.11.1",
"istanbul": "^0.4.5",
"jasmine": "^2.5.2",
"proxyquire": "^1.7.10"
"jasmine": "^2.5.2"
},
"dependencies": {
"aws-sdk": "^2.7.12",
"object-hash": "^1.1.7"
}
}
4 changes: 0 additions & 4 deletions src/aws.js

This file was deleted.

35 changes: 19 additions & 16 deletions src/documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function _mapToObj(map) {

var autoVersion;

module.exports = function(AWS) {
module.exports = function() {
return {
_createDocumentationPart: function _createDocumentationPart(part, def, knownLocation) {
const location = part.locationProps.reduce((loc, property) => {
Expand Down Expand Up @@ -75,12 +75,11 @@ module.exports = function(AWS) {
},

_updateDocumentation: function _updateDocumentation() {
const apiGateway = new AWS.APIGateway(this.serverless.providers.aws.getCredentials());
return apiGateway.getDocumentationVersion({
const aws = this.serverless.providers.aws;
return aws.request('APIGateway', 'getDocumentationVersion', {
restApiId: this.restApiId,
documentationVersion: this.getDocumentationVersion(),
}).promise()
.then(() => {
}).then(() => {
const msg = 'documentation version already exists, skipping upload';
console.info('-------------------');
console.info(msg);
Expand All @@ -92,26 +91,30 @@ module.exports = function(AWS) {

return Promise.reject(err);
})
.then(() => apiGateway.getDocumentationParts({
restApiId: this.restApiId,
limit: 9999,
}).promise())
.then(results => results.items.map(part => apiGateway.deleteDocumentationPart({
documentationPartId: part.id,
restApiId: this.restApiId,
}).promise()))
.then(() =>
aws.request('APIGateway', 'getDocumentationParts', {
restApiId: this.restApiId,
limit: 9999,
})
)
.then(results => results.items.map(
part => aws.request('APIGateway', 'deleteDocumentationPart', {
documentationPartId: part.id,
restApiId: this.restApiId,
})
))
.then(promises => Promise.all(promises))
.then(() => this.documentationParts.reduce((promise, part) => {
return promise.then(() => {
part.properties = JSON.stringify(part.properties);
return apiGateway.createDocumentationPart(part).promise();
return aws.request('APIGateway', 'createDocumentationPart', part);
});
}, Promise.resolve()))
.then(() => apiGateway.createDocumentationVersion({
.then(() => aws.request('APIGateway', 'createDocumentationVersion', {
restApiId: this.restApiId,
documentationVersion: this.getDocumentationVersion(),
stageName: this.options.stage,
}).promise());
}));
},

getGlobalDocumentationParts: function getGlobalDocumentationParts() {
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const documentation = require('./documentation');
const models = require('./models');
const aws = require('./aws.js')();

class ServerlessAWSDocumentation {
constructor(serverless, options) {
Expand All @@ -10,7 +9,7 @@ class ServerlessAWSDocumentation {
this.provider = 'aws'

Object.assign(this, models);
Object.assign(this, documentation(aws));
Object.assign(this, documentation());

this.customVars = this.serverless.variables.service.custom;
const naming = this.serverless.providers.aws.naming;
Expand Down
Loading

0 comments on commit 49c0132

Please sign in to comment.