Skip to content

Commit a32ea1f

Browse files
author
Thiago Bustamante
committed
fix open api 3 generation
1 parent 3262d90 commit a32ea1f

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ basePath | string | Base API path; e.g. the 'v1' in https://myapi.com/v1
224224
consumes | [string] | Default consumes property for the entire API
225225
description | string | API description; defaults to npm package description
226226
entryFile | string or string[] | The entry point to your API (it is possible to use glob patters)
227-
ouptupFormat | 'swagger_2' or 'openapi_3' | Inform if the generated spec will be in swagger 2.0 format or i open api 3.0
227+
ouptupFormat | 'Swagger_2' or 'OpenApi_3' | Inform if the generated spec will be in swagger 2.0 format or i open api 3.0
228228
host | string | The hostname to be informed in the generated swagger file
229229
license | string | API license number; defaults to npm package license
230230
name | string | API name; defaults to npm package name

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-rest-swagger",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Generate Swagger files from a typescript-rest project",
55
"keywords": [
66
"typescript",
@@ -96,4 +96,4 @@
9696
"node": ">=6.0.0"
9797
},
9898
"engineStrict": true
99-
}
99+
}

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as _ from 'lodash';
88
import { isAbsolute, join } from 'path';
99
import * as ts from 'typescript';
1010
import * as YAML from 'yamljs';
11-
import { Config, SwaggerConfig } from './config';
11+
import { Config, Specification, SwaggerConfig } from './config';
1212
import { MetadataGenerator } from './metadata/metadataGenerator';
1313
import { SpecGenerator } from './swagger/generator';
1414

@@ -98,7 +98,7 @@ function validateSwaggerConfig(conf: SwaggerConfig): SwaggerConfig {
9898
conf.description = conf.description || descriptionDefault;
9999
conf.license = conf.license || licenseDefault;
100100
conf.yaml = conf.yaml === false ? false : true;
101-
conf.ouptupFormat = conf.ouptupFormat === 'openapi_3' ? conf.ouptupFormat : 'swagger_2';
101+
conf.ouptupFormat = conf.ouptupFormat ? Specification[conf.ouptupFormat] : Specification.Swagger_2;
102102

103103
return conf;
104104
}

src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export interface Config {
77
swagger: SwaggerConfig;
88
}
99

10+
export enum Specification {
11+
Swagger_2 = "Swagger_2",
12+
OpenApi_3 = "OpenApi_3"
13+
}
14+
1015
export interface SwaggerConfig {
1116
/**
1217
* Support the output to be an yaml file
@@ -26,7 +31,7 @@ export interface SwaggerConfig {
2631
/**
2732
* Inform if the generated spec will be in swagger 2.0 format or i open api 3.0
2833
*/
29-
ouptupFormat?: 'swagger_2' | 'openapi_3';
34+
ouptupFormat?: Specification;
3035

3136
/**
3237
* API host, expressTemplate.g. localhost:3000 or https://myapi.com

src/swagger/generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
44
import * as mkdirp from 'mkdirp';
55
import * as pathUtil from 'path';
66
import * as YAML from 'yamljs';
7-
import { SwaggerConfig } from '../config';
7+
import { Specification, SwaggerConfig } from '../config';
88
import {
99
ArrayType, EnumerateType, Metadata, Method, ObjectType, Parameter,
1010
Property, ReferenceType, ResponseType, Type
@@ -21,7 +21,7 @@ export class SpecGenerator {
2121
this.debugger('Swagger Config: %j', this.config);
2222
this.debugger('Services Metadata: %j', this.metadata);
2323
let spec: any = this.getSwaggerSpec();
24-
if (this.config.ouptupFormat === 'openapi_3') {
24+
if (this.config.ouptupFormat === Specification.OpenApi_3) {
2525
spec = await this.convertToOpenApiSpec(spec);
2626
}
2727
return new Promise<void>((resolve, reject) => {

0 commit comments

Comments
 (0)