Skip to content

Commit

Permalink
feat: add option to change project title (#80)
Browse files Browse the repository at this point in the history
* add option to change project title

* change markdown file

* unit tests modified

* add suggested changes
  • Loading branch information
jecs27 authored Jul 5, 2022
1 parent 54fddb4 commit 9dea3b6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ All config options are optional. Defaults are shown in the table below.
```yaml
custom:
autoswagger:
title: 'string'
apiType: 'http' | 'httpApi'
generateSwaggerOnDeploy: true | false
typefiles: ['./src/types/typefile1.d.ts', './src/subfolder/helper.d.ts']
Expand All @@ -52,6 +53,7 @@ custom:
| Option | Description | Default | Example |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------- |
| `generateSwaggerOnDeploy` | Boolean which indicates whether to generate a new swagger file on deployment | `true` | |
| `title` | String to overwrite the project title with a custom one | Serverless service name | |
| `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']` | |
| `swaggerFiles` | Array of string which will merge custom json OpenApi 2.0 files to the generated swagger | `[]` | |
| `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` |
Expand Down
3 changes: 2 additions & 1 deletion src/ServerlessAutoSwagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default class ServerlessAutoSwagger {
if (autoswagger.basePath) this.swagger.basePath = autoswagger.basePath;
if (autoswagger.host) this.swagger.host = autoswagger.host;
if (autoswagger.schemes) this.swagger.schemes = autoswagger.schemes;
if (autoswagger.title) this.swagger.info.title = autoswagger.title;

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

generateSwagger = async () => {
this.gatherSwaggerOverrides();
await this.gatherTypes();
this.gatherSwaggerOverrides();
this.generateSecurity();
this.generatePaths();

Expand Down
1 change: 1 addition & 0 deletions src/types/serverless-plugin.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface AutoSwaggerCustomConfig {
basePath?: string;
host?: string;
schemes?: SwaggerScheme[];
title?: string;
excludeStages?: string[];
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/swagger.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Swagger {

// Info Section
export interface Info {
title: string;
title?: string;
description?: string;
version: string;
termsOfService?: string;
Expand Down
3 changes: 2 additions & 1 deletion tests/ServerlessAutoSwagger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ describe('ServerlessAutoSwagger', () => {
{
basePath: '/bp',
host: 'some-host',
title: 'My API Title',
schemes: ['ws'],
swaggerFiles: [fileName],
}
Expand All @@ -832,7 +833,7 @@ describe('ServerlessAutoSwagger', () => {

expect(serverlessAutoSwagger.swagger).toEqual({
definitions: expect.any(Object),
info: expect.any(Object),
info: { title: 'My API Title', version: '1' },
paths: expect.any(Object),
securityDefinitions: expect.any(Object),
swagger: '2.0',
Expand Down

0 comments on commit 9dea3b6

Please sign in to comment.