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

Commit e0c8e35

Browse files
traviskeenantchock
authored andcommitted
Adding the ability to specify an extensions type for output. (#96)
* Adding the ability to specify an extensions type for output. * Update the README.md
1 parent b3edff8 commit e0c8e35

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ See the Serverless documentation for more information on [resource naming](https
301301
### Download documentation from AWS API Gateway
302302

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

306307
## Contribution
307308

src/downloadDocumentation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module.exports = {
99
stageName: this.serverless.service.provider.stage,
1010
restApiId: restApiId,
1111
exportType: 'swagger',
12+
parameters: {
13+
extensions: extensionType(this.options.extensions),
14+
},
1215
accepts: createAWSContentType(this.options.outputFileName),
1316
});
1417
}).then((response) => {
@@ -45,3 +48,13 @@ function createAWSContentType(outputFileName) {
4548
return awsContentType;
4649
}
4750

51+
function extensionType(extensionArg) {
52+
const possibleExtensions = ['integrations', 'apigateway', 'authorizers', 'postman'];
53+
54+
if (possibleExtensions.includes(extensionArg)) {
55+
return extensionArg;
56+
} else {
57+
return 'integrations';
58+
}
59+
}
60+

src/downloadDocumentation.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ describe('ServerlessAWSDocumentation', function () {
4747
stageName: 'testStage',
4848
restApiId: 'testRestApiId',
4949
exportType: 'swagger',
50+
parameters: {
51+
extensions: 'integrations',
52+
},
5053
accepts: 'application/json',
5154
});
5255
expect(objectUnderTest.fs.writeFileSync).toHaveBeenCalledWith('test.txt', 'some body');
@@ -71,6 +74,37 @@ describe('ServerlessAWSDocumentation', function () {
7174
stageName: 'testStage',
7275
restApiId: 'testRestApiId',
7376
exportType: 'swagger',
77+
parameters: {
78+
extensions: 'integrations',
79+
},
80+
accepts: 'application/yaml',
81+
});
82+
expect(objectUnderTest.fs.writeFileSync).toHaveBeenCalledWith('test.yml', 'some body');
83+
84+
done();
85+
});
86+
});
87+
88+
it('should successfully download documentation, yaml extension, using an extensions argument', (done) => {
89+
objectUnderTest.options = {
90+
outputFileName: 'test.yml',
91+
extensions: 'apigateway',
92+
};
93+
objectUnderTest._getRestApiId = () => {
94+
return Promise.resolve('testRestApiId')
95+
};
96+
97+
objectUnderTest.serverless.providers.aws.request.and.returnValue(Promise.resolve({
98+
body: 'some body',
99+
}));
100+
return objectUnderTest.downloadDocumentation().then(() => {
101+
expect(objectUnderTest.serverless.providers.aws.request).toHaveBeenCalledWith('APIGateway', 'getExport', {
102+
stageName: 'testStage',
103+
restApiId: 'testRestApiId',
104+
exportType: 'swagger',
105+
parameters: {
106+
extensions: 'apigateway',
107+
},
74108
accepts: 'application/yaml',
75109
});
76110
expect(objectUnderTest.fs.writeFileSync).toHaveBeenCalledWith('test.yml', 'some body');

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ class ServerlessAWSDocumentation {
4040
],
4141
options: {
4242
outputFileName: {
43-
required: true,
43+
required: true,
44+
},
45+
extensions: {
46+
required: false,
4447
},
4548
},
4649
}

0 commit comments

Comments
 (0)