Files
fastapi-openapi-to-postman/lib/swaggerUtils/inputValidationSwagger.js
Luis Tejeda afbdbcbd46 Merge pull request #506 from postmanlabs/feature/SwaggerConvert
adding multifile swagger examples, adding tests to validate merging, …
2022-04-20 12:02:49 -05:00

43 lines
1011 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
};
}
};