fastman
Version:
快速api测试及文档生成
115 lines • 7.28 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 common_rule_1 = require("./common.rule");
var validation_1 = require("../validation");
/**
* Implements the Invalid Property Name validation rule. This rule is responsible
* for reporting whenever the **name** of a property fails to conform to the required
* format defined by the specification.
*/
var Oas30InvalidPropertyNameValidationRule = /** @class */ (function (_super) {
__extends(Oas30InvalidPropertyNameValidationRule, _super);
function Oas30InvalidPropertyNameValidationRule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Returns true if the definition name is valid.
* @param name
* @return {boolean}
*/
Oas30InvalidPropertyNameValidationRule.isValidDefinitionName = function (name) {
var definitionNamePattern = /^[a-zA-Z0-9\.\-_]+$/;
return definitionNamePattern.test(name);
};
/**
* Returns true if the given schema has a property defined with the given name.
* @param {Oas30Schema} schema
* @param {string} propertyName
* @return {boolean}
*/
Oas30InvalidPropertyNameValidationRule.prototype.isValidSchemaProperty = function (schema, propertyName) {
if (this.isNullOrUndefined(schema)) {
return false;
}
return !this.isNullOrUndefined(schema.property(propertyName));
};
Oas30InvalidPropertyNameValidationRule.prototype.visitPathItem = function (node) {
this.reportIfInvalid("PATH-3-004", node.path().indexOf("/") === 0, node, "The path must start with a '/' character.");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitResponse = function (node) {
// The "default" response will have a statusCode of "null"
if (this.hasValue(node.statusCode())) {
this.reportIfInvalid("RES-3-001", validation_1.OasValidationRuleUtil.isValidHttpCode(node.statusCode()), node, "Response status code \"" + node.statusCode() + "\" is not a valid HTTP response status code.");
}
};
Oas30InvalidPropertyNameValidationRule.prototype.visitSecurityRequirement = function (node) {
var _this = this;
var srn = node.securityRequirementNames();
srn.forEach(function (name) {
var doc = node.ownerDocument();
var scheme = doc.components.getSecurityScheme(name);
_this.reportIfInvalid("SREQ-3-001", !(scheme === undefined || scheme === null), node, "Security Requirement \"" + name + "\" does not correspond to a declared Security Scheme.");
});
};
Oas30InvalidPropertyNameValidationRule.prototype.visitSchemaDefinition = function (node) {
this.reportIfInvalid("COMP-3-001", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Schema Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitParameterDefinition = function (node) {
this.reportIfInvalid("COMP-3-002", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.parameterName()), node, "The Parameter Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitResponseDefinition = function (node) {
this.reportIfInvalid("COMP-3-003", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Response Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitSecurityScheme = function (node) {
this.reportIfInvalid("COMP-3-004", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.schemeName()), node, "The Security Scheme name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitExampleDefinition = function (node) {
this.reportIfInvalid("COMP-3-005", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Example Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitRequestBodyDefinition = function (node) {
this.reportIfInvalid("COMP-3-006", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Request Body Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitHeaderDefinition = function (node) {
this.reportIfInvalid("COMP-3-007", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Header Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitLinkDefinition = function (node) {
this.reportIfInvalid("COMP-3-008", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Link Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitCallbackDefinition = function (node) {
this.reportIfInvalid("COMP-3-009", Oas30InvalidPropertyNameValidationRule.isValidDefinitionName(node.name()), node, "The Callback Definition name must match the regular expression: ^[a-zA-Z0-9\\.\\-_]+$");
};
Oas30InvalidPropertyNameValidationRule.prototype.visitEncoding = function (node) {
var name = node.name();
var schema = node.parent().schema;
this.reportIfInvalid("ENC-3-006", this.isValidSchemaProperty(schema, name), node, "The encoding property \"" + name + "\" cannot be found in the associated schema.");
};
return Oas30InvalidPropertyNameValidationRule;
}(common_rule_1.Oas30ValidationRule));
exports.Oas30InvalidPropertyNameValidationRule = Oas30InvalidPropertyNameValidationRule;
//# sourceMappingURL=invalid-property-name.rule.js.map