fastman
Version:
快速api测试及文档生成
118 lines • 7.93 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 validation_1 = require("../validation");
var common_rule_1 = require("./common.rule");
/**
* Implements the Invalid Reference validation rule. This rule is responsible
* for reporting whenever a property references another node in the document
* but that reference is missing or invalid.
*/
var Oas30InvalidReferenceValidationRule = /** @class */ (function (_super) {
__extends(Oas30InvalidReferenceValidationRule, _super);
function Oas30InvalidReferenceValidationRule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Returns true if the security requirement name is valid. It does this by looking up a declared
* security scheme definition in the document. If no security scheme definition exists with the
* given name, then it is invalid.
* @param securityReqName
* @param doc
*/
// private isValidSecurityRequirementName(securityReqName: string, doc: Oas30Document): boolean {
// return this.hasValue(doc.components) && this.hasValue(doc.components.getSecurityScheme(securityReqName));
// }
Oas30InvalidReferenceValidationRule.prototype.visitCallback = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("CALL-3-001", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Callback.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitCallbackDefinition = function (node) { this.visitCallback(node); };
Oas30InvalidReferenceValidationRule.prototype.visitExample = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("EX-3-003", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Example.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitExampleDefinition = function (node) { this.visitExample(node); };
Oas30InvalidReferenceValidationRule.prototype.visitHeader = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("HEAD-3-005", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Header.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitHeaderDefinition = function (node) { this.visitHeader(node); };
Oas30InvalidReferenceValidationRule.prototype.visitLink = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("LINK-3-005", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Link.");
}
if (this.hasValue(node.operationRef)) {
this.reportIfInvalid("LINK-3-003", validation_1.OasValidationRuleUtil.canResolveRef(node.operationRef, node), node, "The \"operationRef\" property value \"" + node.$ref + "\" must reference a valid Link.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitLinkDefinition = function (node) { this.visitLink(node); };
Oas30InvalidReferenceValidationRule.prototype.visitParameter = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("PAR-3-017", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Parameter.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitParameterDefinition = function (node) { this.visitParameter(node); };
Oas30InvalidReferenceValidationRule.prototype.visitRequestBody = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("RB-3-003", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Request Body.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitRequestBodyDefinition = function (node) { this.visitRequestBody(node); };
Oas30InvalidReferenceValidationRule.prototype.visitResponseBase = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("RES-3-004", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Response.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitResponse = function (node) { this.visitResponseBase(node); };
Oas30InvalidReferenceValidationRule.prototype.visitResponseDefinition = function (node) { this.visitResponseBase(node); };
Oas30InvalidReferenceValidationRule.prototype.visitSecurityScheme = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("SS-3-012", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Security Scheme.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitSchema = function (node) {
if (this.hasValue(node.$ref)) {
this.reportIfInvalid("SCH-3-002", validation_1.OasValidationRuleUtil.canResolveRef(node.$ref, node), node, "The \"$ref\" property value \"" + node.$ref + "\" must reference a valid Schema.");
}
};
Oas30InvalidReferenceValidationRule.prototype.visitAllOfSchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitAnyOfSchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitOneOfSchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitNotSchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitPropertySchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitItemsSchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitAdditionalPropertiesSchema = function (node) { this.visitSchema(node); };
Oas30InvalidReferenceValidationRule.prototype.visitSchemaDefinition = function (node) { this.visitSchema(node); };
return Oas30InvalidReferenceValidationRule;
}(common_rule_1.Oas30ValidationRule));
exports.Oas30InvalidReferenceValidationRule = Oas30InvalidReferenceValidationRule;
//# sourceMappingURL=invalid-reference.rule.js.map