add multiple versions support

add multiple versions support
This commit is contained in:
Luis Tejeda
2022-04-19 16:41:21 -05:00
committed by Erik Mendoza
parent 36e83721dd
commit 30cc74b720
7 changed files with 342 additions and 28 deletions

View File

@@ -3,11 +3,37 @@ var expect = require('chai').expect,
fs = require('fs'),
path = require('path'),
VALID_OPENAPI_PATH = '../data/valid_openapi',
VALID_OPENAPI_31_PATH = '../data/valid_openapi31X',
PET_STORE_SEPARATED = '../data/petstore separate yaml/spec',
PET_STORE_SEPARATED_JSON = '../data/petstore-separate/spec',
validPetstore = path.join(__dirname, VALID_OPENAPI_PATH + '/petstore.yaml'),
noauth = path.join(__dirname, VALID_OPENAPI_PATH + '/noauth.yaml');
noauth = path.join(__dirname, VALID_OPENAPI_PATH + '/noauth.yaml'),
petstoreSeparated = path.join(__dirname, PET_STORE_SEPARATED + '/swagger.yaml'),
petstoreSeparatedPet = path.join(__dirname, PET_STORE_SEPARATED + '/pet.yaml'),
petstoreSeparatedJson = path.join(__dirname, PET_STORE_SEPARATED_JSON + '/swagger.json'),
petstoreSeparatedPetJson = path.join(__dirname, PET_STORE_SEPARATED_JSON + '/Pet.json'),
validHopService31x = path.join(__dirname, VALID_OPENAPI_31_PATH + '/yaml/hopService.yaml');
describe('requestNameSource option', function() {
describe('detectRoot method', function() {
it('should return one root 3.0 correctly no specific version', async function() {
let contentFile = fs.readFileSync(validPetstore, 'utf8'),
input = {
type: 'folder',
data: [
{
path: '/petstore.yaml',
content: contentFile
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data[0].path).to.equal('/petstore.yaml');
});
it('should return one root 3.0 correctly', async function() {
let contentFile = fs.readFileSync(validPetstore, 'utf8'),
input = {
@@ -26,10 +52,118 @@ describe('requestNameSource option', function() {
expect(res.output.data[0].path).to.equal('/petstore.yaml');
});
it('should return no root when specific version is not present', async function() {
let contentFile = fs.readFileSync(validPetstore, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.1',
data: [
{
path: '/petstore.yaml',
content: contentFile
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data.length).to.equal(0);
});
it('should return one root 3.0 correctly with other files in folder', async function() {
let petRoot = fs.readFileSync(petstoreSeparated, 'utf8'),
petSchema = fs.readFileSync(petstoreSeparatedPet, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.0',
data: [
{
path: '/swagger.yaml',
content: petRoot
},
{
path: '/Pet.yaml',
content: petSchema
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data.length).to.equal(1);
expect(res.output.data[0].path).to.equal('/swagger.yaml');
});
it('should return one root 3.1 correctly', async function() {
let contentFile = fs.readFileSync(validHopService31x, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.1',
data: [
{
path: '/hopService.yaml',
content: contentFile
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data[0].path).to.equal('/hopService.yaml');
});
it('should return one root when multiple versions are present correctly', async function() {
let petstoreContent = fs.readFileSync(validPetstore, 'utf8'),
hopService31x = fs.readFileSync(validHopService31x, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.0.0',
data: [
{
path: '/petstore.yaml',
content: petstoreContent
},
{
path: '/hopService.yaml',
content: hopService31x
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data.length).to.equal(1);
expect(res.output.data[0].path).to.equal('/petstore.yaml');
});
it('should return one root when multiple versions are present correctly 3.1', async function() {
let petstoreContent = fs.readFileSync(validPetstore, 'utf8'),
hopService31x = fs.readFileSync(validHopService31x, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.1.0',
data: [
{
path: '/petstore.yaml',
content: petstoreContent
},
{
path: '/hopService.yaml',
content: hopService31x
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data.length).to.equal(1);
expect(res.output.data[0].path).to.equal('/hopService.yaml');
});
it('should return no root file when there is not a root file present', async function() {
let input = {
type: 'folder',
specificationVersion: '3.0',
specificationVersion: '3.0.0',
data: [
{
path: '/petstore.yaml',
@@ -48,7 +182,7 @@ describe('requestNameSource option', function() {
noAuthContent = fs.readFileSync(noauth, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.0',
specificationVersion: '3.0.0',
data: [
{
path: '/petstore.yaml',
@@ -63,6 +197,7 @@ describe('requestNameSource option', function() {
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data.length).to.equal(2);
expect(res.output.data[0].path).to.equal('/petstore.yaml');
expect(res.output.data[1].path).to.equal('/noauth.yaml');
});
@@ -70,7 +205,7 @@ describe('requestNameSource option', function() {
it('should propagate one error correctly', async function () {
let input = {
type: 'folder',
specificationVersion: '3.0',
specificationVersion: '3.0.0',
data: [
{
path: '',
@@ -86,4 +221,28 @@ describe('requestNameSource option', function() {
}
});
it('should return one root 3.0 correctly with other files in folder json', async function() {
let petRoot = fs.readFileSync(petstoreSeparatedJson, 'utf8'),
petSchema = fs.readFileSync(petstoreSeparatedPetJson, 'utf8'),
input = {
type: 'folder',
specificationVersion: '3.0',
data: [
{
path: '/swagger.json',
content: petRoot
},
{
path: '/Pet.json',
content: petSchema
}
]
};
const res = await Converter.detectRootFiles(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(res.output.data.length).to.equal(1);
expect(res.output.data[0].path).to.equal('/swagger.json');
});
});