fastman
Version:
快速api测试及文档生成
156 lines • 7.94 kB
JavaScript
;
/**
* @license
* Copyright 2017 Red Hat
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var visitor_base_1 = require("../visitors/visitor.base");
var required_property_rule_1 = require("./2.0/required-property.rule");
var path_visitor_1 = require("../visitors/path.visitor");
var visitor_utils_1 = require("../visitors/visitor.utils");
var invalid_property_format_rule_1 = require("./2.0/invalid-property-format.rule");
var invalid_property_name_rule_1 = require("./2.0/invalid-property-name.rule");
var invalid_property_value_rule_1 = require("./2.0/invalid-property-value.rule");
var uniqueness_rule_1 = require("./2.0/uniqueness.rule");
var mutually_exclusive_rule_1 = require("./2.0/mutually-exclusive.rule");
var invalid_reference_rule_1 = require("./2.0/invalid-reference.rule");
var invalid_property_format_rule_2 = require("./3.0/invalid-property-format.rule");
var ignored_property_name_rule_1 = require("./3.0/ignored-property-name.rule");
var invalid_property_name_rule_2 = require("./3.0/invalid-property-name.rule");
var invalid_property_value_rule_2 = require("./3.0/invalid-property-value.rule");
var invalid_reference_rule_2 = require("./3.0/invalid-reference.rule");
var mutually_exclusive_rule_2 = require("./3.0/mutually-exclusive.rule");
var required_property_rule_2 = require("./3.0/required-property.rule");
var uniqueness_rule_2 = require("./3.0/uniqueness.rule");
/**
* Visitor used to clear validation problems. This is typically done just before
* validation is run so that the data model is clean. Validation would then add new
* problem nodes to the model.
*/
var OasResetValidationProblemsVisitor = /** @class */ (function (_super) {
__extends(OasResetValidationProblemsVisitor, _super);
function OasResetValidationProblemsVisitor() {
return _super !== null && _super.apply(this, arguments) || this;
}
OasResetValidationProblemsVisitor.prototype.doVisitNode = function (node) {
node.clearValidationProblems();
};
return OasResetValidationProblemsVisitor;
}(visitor_base_1.OasAllNodeVisitor));
exports.OasResetValidationProblemsVisitor = OasResetValidationProblemsVisitor;
/**
* Visitor used to validate a OpenAPI document (or a subsection of the document). The result
* of the validation will be a list of validation errors. In addition, the validator will
* add the validation errors directly to the offending model nodes as attributes.
*/
var Oas20ValidationVisitor = /** @class */ (function (_super) {
__extends(Oas20ValidationVisitor, _super);
function Oas20ValidationVisitor() {
var _this = _super.call(this) || this;
_this.errors = [];
// Add a bunch of validation rules to the array of visitors.
_this.addVisitors([
new required_property_rule_1.Oas20RequiredPropertyValidationRule(_this),
new invalid_property_format_rule_1.Oas20InvalidPropertyFormatValidationRule(_this),
new invalid_property_name_rule_1.Oas20InvalidPropertyNameValidationRule(_this),
new invalid_property_value_rule_1.Oas20InvalidPropertyValueValidationRule(_this),
new uniqueness_rule_1.Oas20UniquenessValidationRule(_this),
new mutually_exclusive_rule_1.Oas20MutuallyExclusiveValidationRule(_this),
new invalid_reference_rule_1.Oas20InvalidReferenceValidationRule(_this)
]);
return _this;
}
/**
* Returns the array of validation errors found by the visitor.
* @return {OasValidationProblem[]}
*/
Oas20ValidationVisitor.prototype.getValidationErrors = function () {
return this.errors;
};
/**
* Called by validation rules when an error is detected.
* @param code
* @param node
* @param message
*/
Oas20ValidationVisitor.prototype.report = function (code, node, message) {
var viz = new path_visitor_1.Oas20NodePathVisitor();
visitor_utils_1.OasVisitorUtil.visitTree(node, viz, visitor_utils_1.OasTraverserDirection.up);
var path = viz.path();
var error = node.addValidationProblem(code, path, message);
// Include the error in the list of errors found by this visitor.
this.errors.push(error);
};
return Oas20ValidationVisitor;
}(visitor_base_1.Oas20CompositeVisitor));
exports.Oas20ValidationVisitor = Oas20ValidationVisitor;
/**
* Visitor used to validate a OpenAPI document (or a subsection of the document). The result
* of the validation will be a list of validation errors. In addition, the validator will
* add the validation errors directly to the offending model nodes as attributes.
*/
var Oas30ValidationVisitor = /** @class */ (function (_super) {
__extends(Oas30ValidationVisitor, _super);
function Oas30ValidationVisitor() {
var _this = _super.call(this) || this;
_this.errors = [];
// Add a bunch of validation rules to the array of visitors.
_this.addVisitors([
new invalid_property_format_rule_2.Oas30InvalidPropertyFormatValidationRule(_this),
new ignored_property_name_rule_1.Oas30IgnoredPropertyNameValidationRule(_this),
new invalid_property_name_rule_2.Oas30InvalidPropertyNameValidationRule(_this),
new invalid_property_value_rule_2.Oas30InvalidPropertyValueValidationRule(_this),
new invalid_reference_rule_2.Oas30InvalidReferenceValidationRule(_this),
new mutually_exclusive_rule_2.Oas30MutuallyExclusiveValidationRule(_this),
new required_property_rule_2.Oas30RequiredPropertyValidationRule(_this),
new uniqueness_rule_2.Oas30UniquenessValidationRule(_this)
]);
return _this;
}
/**
* Returns the array of validation errors found by the visitor.
* @return {OasValidationProblem[]}
*/
Oas30ValidationVisitor.prototype.getValidationErrors = function () {
return this.errors;
};
/**
* Called by validation rules when an error is detected.
* @param code
* @param node
* @param message
*/
Oas30ValidationVisitor.prototype.report = function (code, node, message) {
var viz = new path_visitor_1.Oas30NodePathVisitor();
visitor_utils_1.OasVisitorUtil.visitTree(node, viz, visitor_utils_1.OasTraverserDirection.up);
var path = viz.path();
var error = node.addValidationProblem(code, path, message);
// Include the error in the list of errors found by this visitor.
this.errors.push(error);
};
return Oas30ValidationVisitor;
}(visitor_base_1.Oas30CompositeVisitor));
exports.Oas30ValidationVisitor = Oas30ValidationVisitor;
//# sourceMappingURL=validation.visitor.js.map