Skip to content

Commit f885a16

Browse files
added tests for OA3.1 and fixed nomenclature
1 parent e0941e0 commit f885a16

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

test/unit/base.test.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ var expect = require('chai').expect,
77
VALID_OPENAPI_PATH = '../data/valid_openapi',
88
INVALID_OPENAPI_PATH = '../data/invalid_openapi',
99
SWAGGER_20_FOLDER_YAML = '../data/valid_swagger/yaml/',
10-
SWAGGER_20_FOLDER_JSON = '../data/valid_swagger/json/';
10+
SWAGGER_20_FOLDER_JSON = '../data/valid_swagger/json/',
11+
VALID_OPENAPI_3_1_FOLDER_JSON = '../data/valid_openapi31X/json',
12+
VALID_OPENAPI_3_1_FOLDER_YAML = '../data/valid_openapi31X/yaml';
1113

1214
describe('CONVERT FUNCTION TESTS ', function() {
1315
// these two covers remaining part of util.js
@@ -2015,10 +2017,10 @@ describe('INTERFACE FUNCTION TESTS ', function () {
20152017
describe('The converter must identify valid OA3 specification', function () {
20162018
var pathPrefix = VALID_OPENAPI_PATH,
20172019
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix)),
2018-
oa3_1_files = ['issue#479_2.yaml', 'issue#10229.json', 'query_param_with_enum_resolve_as_example.json'];
2020+
oa31Files = ['issue#479_2.yaml', 'issue#10229.json', 'query_param_with_enum_resolve_as_example.json'];
20192021

20202022
sampleSpecs.map((sample) => {
2021-
if (!oa3_1_files.includes(sample)) {
2023+
if (!oa31Files.includes(sample)) {
20222024
var specPath = path.join(__dirname, pathPrefix, sample);
20232025

20242026
it(specPath + ' is valid ', function(done) {
@@ -2051,6 +2053,51 @@ describe('INTERFACE FUNCTION TESTS ', function () {
20512053
});
20522054
});
20532055

2056+
describe('The converter must identify valid OA3.1 specifications - JSON', function () {
2057+
var pathPrefix = VALID_OPENAPI_3_1_FOLDER_JSON,
2058+
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix)),
2059+
oa30Files = ['deprecated_property.json'],
2060+
incorrectOA31Files = ['webhooks.json'],
2061+
filesToIgnore = oa30Files + incorrectOA31Files;
2062+
2063+
2064+
sampleSpecs.map((sample) => {
2065+
if (!filesToIgnore.includes(sample)) {
2066+
var specPath = path.join(__dirname, pathPrefix, sample);
2067+
2068+
it(specPath + ' is valid ', function(done) {
2069+
var openapi = fs.readFileSync(specPath, 'utf8'),
2070+
validationResult = Converter.validate({ type: 'string', data: openapi });
2071+
2072+
expect(validationResult.result).to.equal(true);
2073+
expect(validationResult.specificationVersion).to.equal('3.1.x');
2074+
done();
2075+
});
2076+
}
2077+
});
2078+
});
2079+
2080+
describe('The converter must identify valid OA3.1 specifications - YAML', function () {
2081+
var pathPrefix = VALID_OPENAPI_3_1_FOLDER_YAML,
2082+
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix)),
2083+
invalidOA31Files = ['marketPayNotificationService4.yaml'];
2084+
2085+
sampleSpecs.map((sample) => {
2086+
if (!invalidOA31Files.includes(sample)) {
2087+
var specPath = path.join(__dirname, pathPrefix, sample);
2088+
2089+
it(specPath + ' is valid ', function(done) {
2090+
var openapi = fs.readFileSync(specPath, 'utf8'),
2091+
validationResult = Converter.validate({ type: 'string', data: openapi });
2092+
2093+
expect(validationResult.result).to.equal(true);
2094+
expect(validationResult.specificationVersion).to.equal('3.1.x');
2095+
done();
2096+
});
2097+
}
2098+
});
2099+
});
2100+
20542101
describe('The converter must identify valid OA2 specifications - YAML', function () {
20552102
var pathPrefix = SWAGGER_20_FOLDER_YAML,
20562103
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix));

0 commit comments

Comments
 (0)