Fix swagger to openapi convertion

Removing async await implementation and using callback implementation instead.
Fixin the related tests
This commit is contained in:
Erik Mendoza
2022-04-28 16:38:18 -05:00
parent bd33ad10b0
commit fa623d32c0
3 changed files with 123 additions and 122 deletions

View File

@@ -6,25 +6,24 @@ const { convertSwaggerToOpenapi } = require('../../lib/swaggerUtils/swaggerToOpe
utils = require('../../lib/swaggerUtils/schemaUtilsSwagger'),
expect = require('chai').expect;
describe('Test swaggerToOpenapi method', async function() {
it('Should convert a swagger file to an openapi', async function() {
describe('Test swaggerToOpenapi method', function() {
it('Should convert a swagger file to an openapi', function() {
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_JSON + '/sampleswagger.json'),
fileData = fs.readFileSync(fileSource, 'utf8'),
parsedSpec = utils.parseSpec(fileData);
let result = await convertSwaggerToOpenapi(parsedSpec.openapi);
expect(result.openapi.openapi).to.be.equal('3.0.0');
convertSwaggerToOpenapi(utils, parsedSpec.openapi, (error, openapi) => {
expect(error).to.be.null;
expect(openapi.openapi).to.be.equal('3.0.0');
});
});
it('Should throw an error when swagger file is not complete', async function() {
it('Should throw an error when swagger file is not complete', function() {
const fileSource = path.join(__dirname, SWAGGER_20_INVALID_FOLDER_JSON + '/invalid_no_info.json'),
fileData = fs.readFileSync(fileSource, 'utf8'),
parsedSpec = utils.parseSpec(fileData);
try {
await convertSwaggerToOpenapi(parsedSpec.openapi);
expect.fail();
}
catch (error) {
convertSwaggerToOpenapi(utils, parsedSpec.openapi, (error, openapi) => {
expect(error.message).to.be.equal('Unsupported swagger/OpenAPI version: undefined');
}
expect(openapi).to.be.undefined;
});
});
});