Skip to content

Commit 73f59ed

Browse files
authored
Merge pull request #674 from postmanlabs/feature/add-specification-version-to-validation-result
Added specificationVersion to validate method output
2 parents 0e5b2f2 + f885a16 commit 73f59ed

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
lines changed

lib/schemapack.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class SchemaPack {
142142
this.openapi = specParseResult.openapi;
143143
this.validated = true;
144144
this.validationResult = {
145-
result: true
145+
result: true,
146+
specificationVersion: concreteUtils.version
146147
};
147148
return this.validationResult;
148149
}

test/unit/base.test.js

Lines changed: 106 additions & 1 deletion
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
@@ -2011,6 +2013,109 @@ describe('INTERFACE FUNCTION TESTS ', function () {
20112013
});
20122014
});
20132015
});
2016+
2017+
describe('The converter must identify valid OA3 specification', function () {
2018+
var pathPrefix = VALID_OPENAPI_PATH,
2019+
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix)),
2020+
oa31Files = ['issue#479_2.yaml', 'issue#10229.json', 'query_param_with_enum_resolve_as_example.json'];
2021+
2022+
sampleSpecs.map((sample) => {
2023+
if (!oa31Files.includes(sample)) {
2024+
var specPath = path.join(__dirname, pathPrefix, sample);
2025+
2026+
it(specPath + ' is valid ', function(done) {
2027+
var openapi = fs.readFileSync(specPath, 'utf8'),
2028+
validationResult = Converter.validate({ type: 'string', data: openapi });
2029+
2030+
expect(validationResult.result).to.equal(true);
2031+
expect(validationResult.specificationVersion).to.equal('3.0.x');
2032+
done();
2033+
});
2034+
}
2035+
});
2036+
});
2037+
2038+
describe('The converter must identify valid OA2 specifications - JSON', function () {
2039+
var pathPrefix = SWAGGER_20_FOLDER_JSON,
2040+
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix));
2041+
2042+
sampleSpecs.map((sample) => {
2043+
var specPath = path.join(__dirname, pathPrefix, sample);
2044+
2045+
it(specPath + ' is valid ', function(done) {
2046+
var openapi = fs.readFileSync(specPath, 'utf8'),
2047+
validationResult = Converter.validate({ type: 'string', data: openapi });
2048+
2049+
expect(validationResult.result).to.equal(true);
2050+
expect(validationResult.specificationVersion).to.equal('2.0');
2051+
done();
2052+
});
2053+
});
2054+
});
2055+
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+
2101+
describe('The converter must identify valid OA2 specifications - YAML', function () {
2102+
var pathPrefix = SWAGGER_20_FOLDER_YAML,
2103+
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix));
2104+
2105+
sampleSpecs.map((sample) => {
2106+
var specPath = path.join(__dirname, pathPrefix, sample);
2107+
2108+
it(specPath + ' is valid ', function(done) {
2109+
var openapi = fs.readFileSync(specPath, 'utf8'),
2110+
validationResult = Converter.validate({ type: 'string', data: openapi });
2111+
2112+
expect(validationResult.result).to.equal(true);
2113+
expect(validationResult.specificationVersion).to.equal('2.0');
2114+
done();
2115+
});
2116+
});
2117+
});
2118+
20142119
describe('The converter must identify invalid specifications', function () {
20152120
var pathPrefix = INVALID_OPENAPI_PATH,
20162121
sampleSpecs = fs.readdirSync(path.join(__dirname, pathPrefix));

0 commit comments

Comments
 (0)