Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ See the Serverless documentation for more information on [resource naming](https
### Download documentation from AWS API Gateway

To download the deployed documentation you just need to use `serverless downloadDocumentation --outputFileName=filename.ext`.
For `yml` or `yaml` extensions application/yaml content will be downloaded from AWS. In any other case - application/json.
For `yml` or `yaml` extensions application/yaml content will be downloaded from AWS. In any other case - application/json.
Optional argument --extensions ['integrations', 'apigateway', 'authorizers', 'postman']. Defaults to 'integrations'.

## Contribution

Expand Down
13 changes: 13 additions & 0 deletions src/downloadDocumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = {
stageName: this.serverless.service.provider.stage,
restApiId: restApiId,
exportType: 'swagger',
parameters: {
extensions: extensionType(this.options.extensions),
},
accepts: createAWSContentType(this.options.outputFileName),
});
}).then((response) => {
Expand Down Expand Up @@ -45,3 +48,13 @@ function createAWSContentType(outputFileName) {
return awsContentType;
}

function extensionType(extensionArg) {
const possibleExtensions = ['integrations', 'apigateway', 'authorizers', 'postman'];

if (possibleExtensions.includes(extensionArg)) {
return extensionArg;
} else {
return 'integrations';
}
}

34 changes: 34 additions & 0 deletions src/downloadDocumentation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ describe('ServerlessAWSDocumentation', function () {
stageName: 'testStage',
restApiId: 'testRestApiId',
exportType: 'swagger',
parameters: {
extensions: 'integrations',
},
accepts: 'application/json',
});
expect(objectUnderTest.fs.writeFileSync).toHaveBeenCalledWith('test.txt', 'some body');
Expand All @@ -71,6 +74,37 @@ describe('ServerlessAWSDocumentation', function () {
stageName: 'testStage',
restApiId: 'testRestApiId',
exportType: 'swagger',
parameters: {
extensions: 'integrations',
},
accepts: 'application/yaml',
});
expect(objectUnderTest.fs.writeFileSync).toHaveBeenCalledWith('test.yml', 'some body');

done();
});
});

it('should successfully download documentation, yaml extension, using an extensions argument', (done) => {
objectUnderTest.options = {
outputFileName: 'test.yml',
extensions: 'apigateway',
};
objectUnderTest._getRestApiId = () => {
return Promise.resolve('testRestApiId')
};

objectUnderTest.serverless.providers.aws.request.and.returnValue(Promise.resolve({
body: 'some body',
}));
return objectUnderTest.downloadDocumentation().then(() => {
expect(objectUnderTest.serverless.providers.aws.request).toHaveBeenCalledWith('APIGateway', 'getExport', {
stageName: 'testStage',
restApiId: 'testRestApiId',
exportType: 'swagger',
parameters: {
extensions: 'apigateway',
},
accepts: 'application/yaml',
});
expect(objectUnderTest.fs.writeFileSync).toHaveBeenCalledWith('test.yml', 'some body');
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class ServerlessAWSDocumentation {
],
options: {
outputFileName: {
required: true,
required: true,
},
extensions: {
required: false,
},
},
}
Expand Down