UNPKG

fastman

Version:

快速api测试及文档生成

149 lines 7.38 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 required property validation rule. Various model properties are either * required or conditionally required. For example, the "swagger" property MUST exist * on the root (document) node. This rule checks for all required and conditionally * required properties on all model types. */ var Oas30RequiredPropertyValidationRule = /** @class */ (function (_super) { __extends(Oas30RequiredPropertyValidationRule, _super); function Oas30RequiredPropertyValidationRule() { return _super !== null && _super.apply(this, arguments) || this; } /** * Called when a required property is missing. * @param code * @param node * @param propertyName */ Oas30RequiredPropertyValidationRule.prototype.requireProperty = function (code, node, propertyName) { // No properties are required if we're dealing with a $ref if (this.hasValue(node["$ref"])) { return; } var propertyValue = node[propertyName]; if (!this.isDefined(propertyValue)) { this.report(code, node, "Property \"" + propertyName + "\" is required."); } }; /** * Called when a conditionally required property is missing. * @param node * @param propertyName * @param dependentProperty * @param dependentValue */ Oas30RequiredPropertyValidationRule.prototype.requirePropertyWhen = function (code, node, propertyName, dependentProperty, dependentValue) { var actualDependentValue = node[dependentProperty]; var dependentValueMatches = actualDependentValue == dependentValue; if (dependentValueMatches) { var propertyValue = node[propertyName]; if (!this.hasValue(propertyValue)) { this.report(code, node, "Property \"" + propertyName + "\" is required when \"" + dependentProperty + "\" property is \"" + dependentValue + "\"."); } } }; Oas30RequiredPropertyValidationRule.prototype.visitDiscriminator = function (node) { this.requireProperty("DISC-3-001", node, "propertyName"); }; Oas30RequiredPropertyValidationRule.prototype.visitExternalDocumentation = function (node) { this.requireProperty("ED-3-002", node, "url"); }; Oas30RequiredPropertyValidationRule.prototype.visitOAuthFlow = function (node) { this.requireProperty("FLOW-3-006", node, "scopes"); }; Oas30RequiredPropertyValidationRule.prototype.visitImplicitOAuthFlow = function (node) { this.visitOAuthFlow(node); this.requireProperty("FLOW-3-001", node, "authorizationUrl"); }; Oas30RequiredPropertyValidationRule.prototype.visitPasswordOAuthFlow = function (node) { this.visitOAuthFlow(node); this.requireProperty("FLOW-3-002", node, "tokenUrl"); }; Oas30RequiredPropertyValidationRule.prototype.visitClientCredentialsOAuthFlow = function (node) { this.visitOAuthFlow(node); this.requireProperty("FLOW-3-002", node, "tokenUrl"); }; Oas30RequiredPropertyValidationRule.prototype.visitAuthorizationCodeOAuthFlow = function (node) { this.visitOAuthFlow(node); this.requireProperty("FLOW-3-001", node, "authorizationUrl"); this.requireProperty("FLOW-3-002", node, "tokenUrl"); }; Oas30RequiredPropertyValidationRule.prototype.visitInfo = function (node) { this.requireProperty("INF-3-001", node, "title"); this.requireProperty("INF-3-002", node, "version"); }; Oas30RequiredPropertyValidationRule.prototype.visitLicense = function (node) { this.requireProperty("LIC-3-001", node, "name"); }; Oas30RequiredPropertyValidationRule.prototype.visitOperation = function (node) { this.requireProperty("OP-3-004", node, "responses"); }; Oas30RequiredPropertyValidationRule.prototype.visitParameter = function (node) { this.requireProperty("PAR-3-003", node, "name"); this.requireProperty("PAR-3-004", node, "in"); // TODO the 'required' property is required for 'path' params }; Oas30RequiredPropertyValidationRule.prototype.visitParameterDefinition = function (node) { this.visitParameter(node); }; Oas30RequiredPropertyValidationRule.prototype.visitDocument = function (node) { this.requireProperty("R-3-001", node, "openapi"); this.requireProperty("R-3-002", node, "info"); this.requireProperty("R-3-003", node, "paths"); }; Oas30RequiredPropertyValidationRule.prototype.visitRequestBody = function (node) { this.requireProperty("RB-3-002", node, "content"); }; Oas30RequiredPropertyValidationRule.prototype.visitRequestBodyDefinition = function (node) { this.visitRequestBody(node); }; Oas30RequiredPropertyValidationRule.prototype.visitServer = function (node) { this.requireProperty("SRV-3-001", node, "url"); }; Oas30RequiredPropertyValidationRule.prototype.visitSecurityScheme = function (node) { this.requireProperty("SS-3-001", node, "type"); this.requirePropertyWhen("SS-3-002", node, "name", "type", "apiKey"); this.requirePropertyWhen("SS-3-003", node, "in", "type", "apiKey"); this.requirePropertyWhen("SS-3-004", node, "scheme", "type", "http"); this.requirePropertyWhen("SS-3-005", node, "flows", "type", "oauth2"); this.requirePropertyWhen("SS-3-006", node, "openIdConnectUrl", "type", "openIdConnect"); }; Oas30RequiredPropertyValidationRule.prototype.visitServerVariable = function (node) { this.requireProperty("SVAR-3-001", node, "default"); }; Oas30RequiredPropertyValidationRule.prototype.visitTag = function (node) { this.requireProperty("TAG-3-001", node, "name"); }; return Oas30RequiredPropertyValidationRule; }(common_rule_1.Oas30ValidationRule)); exports.Oas30RequiredPropertyValidationRule = Oas30RequiredPropertyValidationRule; //# sourceMappingURL=required-property.rule.js.map