Skip to content

Commit b509057

Browse files
committed
use of lodash isnill
use of isnill to simplify flow
1 parent 2e376ed commit b509057

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

lib/30XUtils/inputValidation.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,36 @@ module.exports = {
1010
validateSpec: function (spec) {
1111

1212
// Checking for the all the required properties in the specification
13-
if (!spec.hasOwnProperty('openapi')) {
13+
if (_.isNil(spec.openapi)) {
1414
return {
1515
result: false,
1616
reason: 'Specification must contain a semantic version number of the OAS specification'
1717
};
1818
}
1919

20-
if (!spec.hasOwnProperty('paths')) {
20+
if (_.isNil(spec.paths)) {
2121
return {
2222
result: false,
2323
reason: 'Specification must contain Paths Object for the available operational paths'
2424
};
2525
}
2626

27-
if (!spec.hasOwnProperty('info')) {
27+
if (_.isNil(spec.info)) {
2828
return {
2929
result: false,
3030
reason: 'Specification must contain an Info Object for the meta-data of the API'
3131
};
3232
}
3333

34-
if (_.isEmpty(spec.info)) {
35-
return {
36-
result: false,
37-
reason: 'Specification must contain a valid not null info'
38-
};
39-
}
40-
4134
if (!spec.info.hasOwnProperty('$ref')) {
42-
if (!spec.info.hasOwnProperty('title') || !spec.info.title) {
35+
if (_.isNil(spec.info.title)) {
4336
return {
4437
result: false,
4538
reason: 'Specification must contain a title in order to generate a collection'
4639
};
4740
}
4841

49-
if (!spec.info.hasOwnProperty('version') || !spec.info.version) {
42+
if (_.isNil(spec.info.version)) {
5043
return {
5144
result: false,
5245
reason: 'Specification must contain a semantic version number of the API in the Info Object'

lib/31XUtils/inputValidation31X.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,45 @@ module.exports = {
1111
*/
1212
validateSpec: function (spec, options) {
1313
const includeWebhooksOption = options.includeWebhooks;
14-
if (!spec.hasOwnProperty('openapi')) {
14+
if (_.isNil(spec.openapi)) {
1515
return {
1616
result: false,
1717
reason: 'Specification must contain a semantic version number of the OAS specification'
1818
};
1919
}
2020

21-
if (!spec.hasOwnProperty('info')) {
21+
if (_.isNil(spec.info)) {
2222
return {
2323
result: false,
2424
reason: 'Specification must contain an Info Object for the meta-data of the API'
2525
};
2626
}
2727

28-
if (_.isEmpty(spec.info)) {
29-
return {
30-
result: false,
31-
reason: 'Specification must contain a valid not null info'
32-
};
33-
}
34-
3528
if (!spec.info.hasOwnProperty('$ref')) {
36-
if (!spec.info.hasOwnProperty('title') || !spec.info.title) {
29+
if (_.isNil(spec.info.title)) {
3730
return {
3831
result: false,
3932
reason: 'Specification must contain a title in order to generate a collection'
4033
};
4134
}
4235

43-
if (!spec.info.hasOwnProperty('version') || !spec.info.version) {
36+
if (_.isNil(spec.info.version)) {
4437
return {
4538
result: false,
4639
reason: 'Specification must contain a semantic version number of the API in the Info Object'
4740
};
4841
}
4942
}
5043

51-
if (!spec.hasOwnProperty('paths') && !includeWebhooksOption) {
44+
if (_.isNil(spec.paths) && !includeWebhooksOption) {
5245
return {
5346
result: false,
5447
reason: 'Specification must contain Paths Object for the available operational paths'
5548
};
5649
}
5750

58-
if (includeWebhooksOption && !spec.hasOwnProperty('paths') &&
59-
!spec.hasOwnProperty('webhooks') && !spec.hasOwnProperty('components')) {
51+
if (includeWebhooksOption && _.isNil(spec.paths) &&
52+
_.isNil(spec.webhooks) && _.isNil(spec.components)) {
6053
return {
6154
result: false,
6255
reason: 'Specification must contain either Paths, Webhooks or Components sections'

test/unit/31Xsupport/schemaUtils31X.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('parseSpec method', function () {
3131
let fileContent = fs.readFileSync(invalid31xFolder + '/invalid-null-info.json', 'utf8');
3232
const parsedSpec = concreteUtils.parseSpec(fileContent, { includeWebhooks: false });
3333
expect(parsedSpec.result).to.be.false;
34-
expect(parsedSpec.reason).to.equal('Specification must contain a valid not null info');
34+
expect(parsedSpec.reason).to.equal('Specification must contain an Info Object for the meta-data of the API');
3535
});
3636

3737
it('should return false and Spec must contain information version', function () {

test/unit/base.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
11511151
{}, (err, conversionResult) => {
11521152
expect(err).to.be.null;
11531153
expect(conversionResult.result).to.equal(false);
1154-
expect(conversionResult.reason).to.equal('Specification must contain a valid not null info');
1154+
expect(conversionResult.reason)
1155+
.to.equal('Specification must contain an Info Object for the meta-data of the API');
11551156
done();
11561157
});
11571158
});

0 commit comments

Comments
 (0)