UNPKG

fastman

Version:

快速api测试及文档生成

71 lines 3.57 kB
"use strict"; /** * @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"); /** * Implements the Uniqueness validation rule. This rule is responsible * for reporting whenever properties whose values are required to be unique, * fail that test. Examples are scopes, tags, and operationId. */ var Oas30UniquenessValidationRule = /** @class */ (function (_super) { __extends(Oas30UniquenessValidationRule, _super); function Oas30UniquenessValidationRule() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.indexedOperations = {}; return _this; } Oas30UniquenessValidationRule.prototype.visitTag = function (node) { var tags = node.ownerDocument().tags; var tcount = tags.filter(function (tag) { return tag.name === node.name; }).length; this.reportIfInvalid("TAG-3-003", tcount === 1, node, "Duplicate tag \"" + node.name + "\" found (every tag must have a unique name)."); }; Oas30UniquenessValidationRule.prototype.visitOperation = function (node) { if (this.hasValue(node.operationId)) { var dupes = this.indexedOperations[node.operationId]; if (this.hasValue(dupes)) { this.reportIfInvalid("OP-3-002", dupes.length > 1, dupes[0], "The \"operationId\" property value '" + node.operationId + "' must be unique across ALL operations."); this.report("OP-3-002", node, "The \"operationId\" property value '" + node.operationId + "' must be unique across ALL operations."); dupes.push(node); } else { this.indexedOperations[node.operationId] = [node]; } } }; Oas30UniquenessValidationRule.prototype.visitParameter = function (node) { var params = node.parent().parameters; this.reportIfInvalid("PAR-3-001", params.filter(function (param) { return param.in === node.in && param.name === node.name; }).length === 1, node, "Duplicate '" + node.in + "' parameter named '" + node.name + "' found (parameters must be unique by name and location)."); }; return Oas30UniquenessValidationRule; }(common_rule_1.Oas30ValidationRule)); exports.Oas30UniquenessValidationRule = Oas30UniquenessValidationRule; //# sourceMappingURL=uniqueness.rule.js.map