Skip to content

Commit ffa9d1c

Browse files
feat: add custom host option (#79)
* Update package.json * try * Update package.json * added host * added host * added option to set custom host * added option to set custom host * Update ServerlessAutoSwagger.test.ts * Update README.md * Update README.md * Update tests/ServerlessAutoSwagger.test.ts Co-authored-by: Brandon Faulkner <[email protected]>
1 parent 3ccd039 commit ffa9d1c

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ custom:
4444
apiKeyHeaders: ['Authorization', 'anyOtherName']
4545
useStage: true | false
4646
basePath: '/string'
47+
host: 'http://some-host'
4748
schemes: ['http', 'https', 'ws', 'wss']
4849
excludeStages: ['production', 'anyOtherStage']
4950
```
@@ -58,6 +59,7 @@ custom:
5859
| `apiKeyHeaders` | Array of strings used to define API keys used in auth headers | `[]` | `apiKeyHeaders: ['Authorization', 'x-api-key']` |
5960
| `useStage` | Boolean to either use current stage in beginning of path or not | `false` | `true` => `dev/swagger` for stage `dev` |
6061
| `basePath` | String that can be prepended to every request. Should include leading `/` | - | `/some-base` => `http://localhost/some-base/my-endpoint` |
62+
| `host` | String that overrides the host. With this you can set your custom domain for your application endpoints | - | `http://some-host` => `{http://some-host}/my-endpoint` |
6163
| `schemes` | Array (containing one of `http`, `https`, `ws`, or `wss`) for specifying schemes | Scheme used to serve the API specification (reflecting Swagger's behavior) | |
6264
| `excludeStages` | Array of strings that contains stages in which Swagger UI and Swagger JSON lambdas should **not** be deployed in. | `[]` | |
6365

src/ServerlessAutoSwagger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export default class ServerlessAutoSwagger {
104104
const autoswagger = this.serverless.service.custom?.autoswagger ?? {};
105105

106106
if (autoswagger.basePath) this.swagger.basePath = autoswagger.basePath;
107+
if (autoswagger.host) this.swagger.host = autoswagger.host;
107108
if (autoswagger.schemes) this.swagger.schemes = autoswagger.schemes;
108109

109110
// There must be at least one or this `if` will be false

src/schemas/custom-properties.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"basePath": {
2020
"type": "string"
2121
},
22+
"host": {
23+
"type": "string"
24+
},
2225
"excludeStages": {
2326
"default": [],
2427
"items": {

src/types/serverless-plugin.types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface AutoSwaggerCustomConfig {
3737
useStage?: boolean;
3838
swaggerPath?: string;
3939
basePath?: string;
40+
host?: string;
4041
schemes?: SwaggerScheme[];
4142
excludeStages?: string[];
4243
}

tests/ServerlessAutoSwagger.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ describe('ServerlessAutoSwagger', () => {
819819
],
820820
{
821821
basePath: '/bp',
822+
host: 'some-host',
822823
schemes: ['ws'],
823824
swaggerFiles: [fileName],
824825
}
@@ -837,6 +838,7 @@ describe('ServerlessAutoSwagger', () => {
837838
swagger: '2.0',
838839
schemes: ['ws'],
839840
basePath: '/bp',
841+
host: 'some-host',
840842
...swaggerDoc,
841843
});
842844
});

0 commit comments

Comments
 (0)