Skip to content

Commit 9dea3b6

Browse files
authored
feat: add option to change project title (#80)
* add option to change project title * change markdown file * unit tests modified * add suggested changes
1 parent 54fddb4 commit 9dea3b6

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ All config options are optional. Defaults are shown in the table below.
3636
```yaml
3737
custom:
3838
autoswagger:
39+
title: 'string'
3940
apiType: 'http' | 'httpApi'
4041
generateSwaggerOnDeploy: true | false
4142
typefiles: ['./src/types/typefile1.d.ts', './src/subfolder/helper.d.ts']
@@ -52,6 +53,7 @@ custom:
5253
| Option | Description | Default | Example |
5354
| ------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------- |
5455
| `generateSwaggerOnDeploy` | Boolean which indicates whether to generate a new swagger file on deployment | `true` | |
56+
| `title` | String to overwrite the project title with a custom one | Serverless service name | |
5557
| `typefiles` | Array of strings which defines where to find the typescript types to use for the request and response bodies | `['./src/types/api-types.d.ts']` | |
5658
| `swaggerFiles` | Array of string which will merge custom json OpenApi 2.0 files to the generated swagger | `[]` | |
5759
| `swaggerPath` | String for customize swagger path. Your new swagger UI will be available at `https://{your-url-domain}/{swaggerPath}` | `swagger` | `my-swagger` => `https://{your-url-domain}/my-swagger` |

src/ServerlessAutoSwagger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export default class ServerlessAutoSwagger {
106106
if (autoswagger.basePath) this.swagger.basePath = autoswagger.basePath;
107107
if (autoswagger.host) this.swagger.host = autoswagger.host;
108108
if (autoswagger.schemes) this.swagger.schemes = autoswagger.schemes;
109+
if (autoswagger.title) this.swagger.info.title = autoswagger.title;
109110

110111
// There must be at least one or this `if` will be false
111112
if (autoswagger.swaggerFiles?.length) this.gatherSwaggerFiles(autoswagger.swaggerFiles);
@@ -197,8 +198,8 @@ export default class ServerlessAutoSwagger {
197198
};
198199

199200
generateSwagger = async () => {
200-
this.gatherSwaggerOverrides();
201201
await this.gatherTypes();
202+
this.gatherSwaggerOverrides();
202203
this.generateSecurity();
203204
this.generatePaths();
204205

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface AutoSwaggerCustomConfig {
3939
basePath?: string;
4040
host?: string;
4141
schemes?: SwaggerScheme[];
42+
title?: string;
4243
excludeStages?: string[];
4344
}
4445

src/types/swagger.types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface Swagger {
1515

1616
// Info Section
1717
export interface Info {
18-
title: string;
18+
title?: string;
1919
description?: string;
2020
version: string;
2121
termsOfService?: string;

tests/ServerlessAutoSwagger.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ describe('ServerlessAutoSwagger', () => {
820820
{
821821
basePath: '/bp',
822822
host: 'some-host',
823+
title: 'My API Title',
823824
schemes: ['ws'],
824825
swaggerFiles: [fileName],
825826
}
@@ -832,7 +833,7 @@ describe('ServerlessAutoSwagger', () => {
832833

833834
expect(serverlessAutoSwagger.swagger).toEqual({
834835
definitions: expect.any(Object),
835-
info: expect.any(Object),
836+
info: { title: 'My API Title', version: '1' },
836837
paths: expect.any(Object),
837838
securityDefinitions: expect.any(Object),
838839
swagger: '2.0',

0 commit comments

Comments
 (0)