Files
fastapi-openapi-to-postman/lib/swaggerUtils/inputValidationSwagger.js
Luis Tejeda 3e62efcf4a PR requested changes
PR requested changes
2022-05-27 12:21:38 -05:00

43 lines
1013 B
JavaScript

module.exports = {
/**
* Validate Spec to check if some of the required fields are present.
* @param {Object} spec OpenAPI spec
* @param {object} options Validation options
* @return {Object} Validation result
*/
validateSpec: function (spec, options) {
if (spec.swagger !== '2.0') {
return {
result: false,
reason: 'The value of "swagger" field must be 2.0'
};
}
if (!spec.info) {
return {
result: false,
reason: 'The Swagger specification must have an "info" field'
};
}
if (!(spec.info.title && spec.info.version) && !options.isFolder) {
return {
result: false,
reason: 'Title, and version fields are required for the Info Object'
};
}
if (!spec.paths) {
return {
result: false,
reason: 'The Swagger specification must have a "paths" field'
};
}
// Valid. No reason needed
return {
result: true,
openapi: spec
};
}
};