Skip to content

Commit 09c983d

Browse files
Added support for Swagger 1:
- api-spec-converter installed - Now swagger 2 is converted using api-spec-converter instead swagger2openapi
1 parent d4b1ad9 commit 09c983d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"email": "project@hostname.com"
5757
},
5858
"dependencies": {
59+
"api-spec-converter": "^2.11.2",
5960
"case": "^1.6.1",
6061
"fs-extra": "^7.0.1",
6162
"fs": "0.0.1-security",

src/services/parsers/file-reader.service.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,32 @@ export class FileReaderService {
7272
return document;
7373
case '2':
7474
console.info('Convertin to OpenAPI V3');
75-
const converter = require('swagger2openapi');
76-
const converted = await converter.convertObj(document, {
77-
patch: true,
78-
warnOnly: true,
79-
});
80-
return converted.openapi;
75+
return this.convertFile('swagger_2', document);
76+
case '1':
77+
return this.convertFile('swagger_1', document);
8178
default:
8279
throw 'This OpenAPi/Swagger version is not compatible with this tool';
8380
}
8481
}
8582

83+
/**
84+
* Convert from file definition to OpenAPI V3
85+
* @param from
86+
* @param document
87+
* @url https://github.com/LucyBot-Inc/api-spec-converter
88+
*/
89+
private async convertFile(
90+
from: string,
91+
document: any,
92+
): Promise<OpenAPIV3.Document> {
93+
const Converter = require('api-spec-converter');
94+
return Converter.convert({
95+
from,
96+
to: 'openapi_3',
97+
source: 'https://api.gettyimages.com/swagger/api-docs',
98+
});
99+
}
100+
86101
private async prepareFile(): Promise<void> {
87102
let extension = fileExtension(this.path);
88103
if (!fileIsJSON(this.path) && !fileIsYAML(this.path)) {

0 commit comments

Comments
 (0)