mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Decouple validation
Decouple validation
This commit is contained in:
committed by
Erik Mendoza
parent
5bd0e47af5
commit
c8cdf86563
54
lib/inputValidation.js
Normal file
54
lib/inputValidation.js
Normal file
@@ -0,0 +1,54 @@
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* Validate Spec to check if some of the required fields are present.
|
||||
*
|
||||
* @param {Object} spec OpenAPI spec
|
||||
* @return {Object} Validation result
|
||||
*/
|
||||
validateSpec: function (spec) {
|
||||
|
||||
// Checking for the all the required properties in the specification
|
||||
if (!spec.hasOwnProperty('openapi')) {
|
||||
return {
|
||||
result: false,
|
||||
reason: 'Specification must contain a semantic version number of the OAS specification'
|
||||
};
|
||||
}
|
||||
|
||||
if (!spec.hasOwnProperty('paths')) {
|
||||
return {
|
||||
result: false,
|
||||
reason: 'Specification must contain Paths Object for the available operational paths'
|
||||
};
|
||||
}
|
||||
|
||||
if (!spec.hasOwnProperty('info')) {
|
||||
return {
|
||||
result: false,
|
||||
reason: 'Specification must contain an Info Object for the meta-data of the API'
|
||||
};
|
||||
}
|
||||
if (!spec.info.hasOwnProperty('$ref')) {
|
||||
if (!spec.info.hasOwnProperty('title')) {
|
||||
return {
|
||||
result: false,
|
||||
reason: 'Specification must contain a title in order to generate a collection'
|
||||
};
|
||||
}
|
||||
|
||||
if (!spec.info.hasOwnProperty('version')) {
|
||||
return {
|
||||
result: false,
|
||||
reason: 'Specification must contain a semantic version number of the API in the Info Object'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Valid specification
|
||||
return {
|
||||
result: true,
|
||||
openapi: spec
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user