Skip to content

Commit 17729ec

Browse files
Merge pull request #21 from ProtocolNebula/feature/9-support-swagger-1
Feature/9 support swagger 1
2 parents d4b1ad9 + 2d69887 commit 17729ec

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- Support for https remote files
11-
- Support for Swagger 2 files (added [swagger2openapi](https://github.com/Mermade/oas-kit/) which converts the file to OpenAPI V3)
11+
- Added **but not used** [swagger2openapi](https://github.com/Mermade/oas-kit/) to future validations (and first method to convert Swagger 2 to OpenAPI V3 with this library)
12+
- Support for `Swagger 1` and `Swagger 2 (Open API)` files (using [api-spec-converter](https://github.com/LucyBot-Inc/api-spec-converter) which converts the file to `OpenAPI V3`.
1213

1314
### Changed
1415
- APIs: If no `tags` provided, the URL is splitted and used as `tags`.
15-
-
16+
1617
## [2.3.2] - 2021-01-09
1718
### Addded
1819
- `--config-file` parameter

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)