UNPKG

fastman

Version:

快速api测试及文档生成

460 lines 18.3 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 node_path_1 = require("../models/node-path"); /** * Base class for Node Path visitors for all versions of OpenAPI. */ var OasNodePathVisitor = /** @class */ (function () { function OasNodePathVisitor() { this._path = new node_path_1.OasNodePath(); } OasNodePathVisitor.prototype.path = function () { return this._path; }; OasNodePathVisitor.prototype.visitDocument = function (node) { // Nothing to do for the root }; OasNodePathVisitor.prototype.visitInfo = function (node) { this._path.prependSegment("info"); }; OasNodePathVisitor.prototype.visitContact = function (node) { this._path.prependSegment("contact"); }; OasNodePathVisitor.prototype.visitLicense = function (node) { this._path.prependSegment("license"); }; OasNodePathVisitor.prototype.visitPaths = function (node) { this._path.prependSegment("paths"); }; OasNodePathVisitor.prototype.visitPathItem = function (node) { this._path.prependSegment(node.path(), true); }; OasNodePathVisitor.prototype.visitOperation = function (node) { this._path.prependSegment(node.method()); }; OasNodePathVisitor.prototype.visitExternalDocumentation = function (node) { this._path.prependSegment("externalDocs"); }; OasNodePathVisitor.prototype.visitSecurityRequirement = function (node) { var securityRequirements = node.parent().security; var idx = 0; for (var _i = 0, securityRequirements_1 = securityRequirements; _i < securityRequirements_1.length; _i++) { var securityRequirement = securityRequirements_1[_i]; if (securityRequirement === node) { this._path.prependSegment(idx, true); this._path.prependSegment("security"); break; } else { idx++; } } }; OasNodePathVisitor.prototype.visitResponses = function (node) { this._path.prependSegment("responses"); }; OasNodePathVisitor.prototype.visitSchema = function (node) { this._path.prependSegment("schema"); }; OasNodePathVisitor.prototype.visitHeader = function (node) { this._path.prependSegment(node.headerName(), true); }; OasNodePathVisitor.prototype.visitTag = function (node) { var tags = node.parent().tags; var idx = 0; for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) { var tag = tags_1[_i]; if (tag === node) { this._path.prependSegment(idx, true); this._path.prependSegment("tags"); break; } else { idx++; } } }; OasNodePathVisitor.prototype.visitSecurityScheme = function (node) { this._path.prependSegment(node.schemeName(), true); }; OasNodePathVisitor.prototype.visitXML = function (node) { this._path.prependSegment("xml"); }; OasNodePathVisitor.prototype.visitExtension = function (node) { this._path.prependSegment(node.name); }; OasNodePathVisitor.prototype.visitValidationProblem = function (node) { this._path.prependSegment(node.errorCode, true); this._path.prependSegment("_validationProblems"); }; return OasNodePathVisitor; }()); exports.OasNodePathVisitor = OasNodePathVisitor; /** * A visitor used to create a node path for any given node. Here are some examples * of node paths: * * - The root document: * / * * - An 'Info' object * /info * * - A GET operation from pet-store: * /paths[/pet/findByStatus]/get * * - External Documentation for a tag: * /tags[2]/externalDocs * */ var Oas20NodePathVisitor = /** @class */ (function (_super) { __extends(Oas20NodePathVisitor, _super); function Oas20NodePathVisitor() { return _super !== null && _super.apply(this, arguments) || this; } Oas20NodePathVisitor.prototype.visitDocument = function (node) { // Nothing to do for the root }; Oas20NodePathVisitor.prototype.visitParameter = function (node) { var params = node.parent().parameters; var idx = 0; for (var _i = 0, params_1 = params; _i < params_1.length; _i++) { var param = params_1[_i]; if (param === node) { this._path.prependSegment(idx, true); this._path.prependSegment("parameters"); break; } else { idx++; } } }; Oas20NodePathVisitor.prototype.visitParameterDefinition = function (node) { this._path.prependSegment(node.parameterName(), true); }; Oas20NodePathVisitor.prototype.visitResponseDefinition = function (node) { this._path.prependSegment(node.name(), true); }; Oas20NodePathVisitor.prototype.visitExample = function (node) { this._path.prependSegment("examples"); }; Oas20NodePathVisitor.prototype.visitItems = function (node) { this._path.prependSegment("items"); }; Oas20NodePathVisitor.prototype.visitSecurityDefinitions = function (node) { this._path.prependSegment("securityDefinitions"); }; Oas20NodePathVisitor.prototype.visitScopes = function (node) { this._path.prependSegment("scopes"); }; Oas20NodePathVisitor.prototype.visitSchemaDefinition = function (node) { this._path.prependSegment(node.definitionName(), true); }; Oas20NodePathVisitor.prototype.visitPropertySchema = function (node) { this._path.prependSegment(node.propertyName(), true); this._path.prependSegment("properties"); }; Oas20NodePathVisitor.prototype.visitAdditionalPropertiesSchema = function (node) { this._path.prependSegment("additionalProperties"); }; Oas20NodePathVisitor.prototype.visitAllOfSchema = function (node) { var schemas = node.parent().allOf; var idx = 0; for (var _i = 0, schemas_1 = schemas; _i < schemas_1.length; _i++) { var schema = schemas_1[_i]; if (schema === node) { this._path.prependSegment(idx, true); this._path.prependSegment("allOf"); break; } else { idx++; } } }; Oas20NodePathVisitor.prototype.visitItemsSchema = function (node) { var schemas = node.parent().items; if (Array.isArray(schemas)) { var idx = 0; for (var _i = 0, schemas_2 = schemas; _i < schemas_2.length; _i++) { var schema = schemas_2[_i]; if (schema === node) { this._path.prependSegment(idx, true); this._path.prependSegment("items"); break; } else { idx++; } } } else { this._path.prependSegment("items"); } }; Oas20NodePathVisitor.prototype.visitDefinitions = function (node) { this._path.prependSegment("definitions"); }; Oas20NodePathVisitor.prototype.visitParametersDefinitions = function (node) { this._path.prependSegment("parameters"); }; Oas20NodePathVisitor.prototype.visitResponsesDefinitions = function (node) { this._path.prependSegment("responses"); }; Oas20NodePathVisitor.prototype.visitResponse = function (node) { this._path.prependSegment(node.statusCode(), true); }; Oas20NodePathVisitor.prototype.visitHeaders = function (node) { this._path.prependSegment("headers"); }; return Oas20NodePathVisitor; }(OasNodePathVisitor)); exports.Oas20NodePathVisitor = Oas20NodePathVisitor; /** * The 3.0 version of a node path visitor (creates a node path from a node). */ var Oas30NodePathVisitor = /** @class */ (function (_super) { __extends(Oas30NodePathVisitor, _super); function Oas30NodePathVisitor() { return _super !== null && _super.apply(this, arguments) || this; } Oas30NodePathVisitor.prototype.visitParameter = function (node) { var params = node.parent().parameters; var idx = 0; for (var _i = 0, params_2 = params; _i < params_2.length; _i++) { var param = params_2[_i]; if (param === node) { this._path.prependSegment(idx, true); this._path.prependSegment("parameters"); break; } else { idx++; } } }; Oas30NodePathVisitor.prototype.visitParameterDefinition = function (node) { this._path.prependSegment(node.parameterName(), true); this._path.prependSegment("parameters"); }; Oas30NodePathVisitor.prototype.visitResponse = function (node) { this._path.prependSegment(node.statusCode(), true); }; Oas30NodePathVisitor.prototype.visitMediaType = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("content"); }; Oas30NodePathVisitor.prototype.visitEncoding = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("encoding"); }; Oas30NodePathVisitor.prototype.visitExample = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("examples"); }; Oas30NodePathVisitor.prototype.visitLink = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("links"); }; Oas30NodePathVisitor.prototype.visitLinkParameterExpression = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("parameters"); }; Oas30NodePathVisitor.prototype.visitLinkRequestBodyExpression = function (node) { this._path.prependSegment("requestBody"); }; Oas30NodePathVisitor.prototype.visitLinkServer = function (node) { this._path.prependSegment("server"); }; Oas30NodePathVisitor.prototype.visitResponseDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("responses"); }; Oas30NodePathVisitor.prototype.visitRequestBody = function (node) { this._path.prependSegment("requestBody"); }; Oas30NodePathVisitor.prototype.visitHeader = function (node) { this._path.prependSegment(node.headerName(), true); this._path.prependSegment("headers"); }; Oas30NodePathVisitor.prototype.visitCallback = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("callbacks"); }; Oas30NodePathVisitor.prototype.visitCallbackPathItem = function (node) { this._path.prependSegment(node.path(), true); }; Oas30NodePathVisitor.prototype.visitServer = function (node) { var servers = node.parent().servers; var idx = 0; for (var _i = 0, servers_1 = servers; _i < servers_1.length; _i++) { var server = servers_1[_i]; if (server === node) { this._path.prependSegment(idx, true); this._path.prependSegment("servers"); break; } else { idx++; } } }; Oas30NodePathVisitor.prototype.visitServerVariable = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("variables"); }; Oas30NodePathVisitor.prototype.visitAllOfSchema = function (node) { var schemas = node.parent().allOf; var idx = 0; for (var _i = 0, schemas_3 = schemas; _i < schemas_3.length; _i++) { var schema = schemas_3[_i]; if (schema === node) { this._path.prependSegment(idx, true); this._path.prependSegment("allOf"); break; } else { idx++; } } }; Oas30NodePathVisitor.prototype.visitAnyOfSchema = function (node) { var schemas = node.parent().anyOf; var idx = 0; for (var _i = 0, schemas_4 = schemas; _i < schemas_4.length; _i++) { var schema = schemas_4[_i]; if (schema === node) { this._path.prependSegment(idx, true); this._path.prependSegment("anyOf"); break; } else { idx++; } } }; Oas30NodePathVisitor.prototype.visitOneOfSchema = function (node) { var schemas = node.parent().oneOf; var idx = 0; for (var _i = 0, schemas_5 = schemas; _i < schemas_5.length; _i++) { var schema = schemas_5[_i]; if (schema === node) { this._path.prependSegment(idx, true); this._path.prependSegment("oneOf"); break; } else { idx++; } } }; Oas30NodePathVisitor.prototype.visitNotSchema = function (node) { this._path.prependSegment("not"); }; Oas30NodePathVisitor.prototype.visitPropertySchema = function (node) { this._path.prependSegment(node.propertyName(), true); this._path.prependSegment("properties"); }; Oas30NodePathVisitor.prototype.visitItemsSchema = function (node) { var schemas = node.parent().items; if (Array.isArray(schemas)) { var idx = 0; for (var _i = 0, schemas_6 = schemas; _i < schemas_6.length; _i++) { var schema = schemas_6[_i]; if (schema === node) { this._path.prependSegment(idx, true); this._path.prependSegment("items"); break; } else { idx++; } } } else { this._path.prependSegment("items"); } }; Oas30NodePathVisitor.prototype.visitAdditionalPropertiesSchema = function (node) { this._path.prependSegment("additionalProperties"); }; Oas30NodePathVisitor.prototype.visitDiscriminator = function (node) { this._path.prependSegment("discriminator"); }; Oas30NodePathVisitor.prototype.visitComponents = function (node) { this._path.prependSegment("components"); }; Oas30NodePathVisitor.prototype.visitSchemaDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("schemas"); }; Oas30NodePathVisitor.prototype.visitExampleDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("examples"); }; Oas30NodePathVisitor.prototype.visitRequestBodyDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("requestBodies"); }; Oas30NodePathVisitor.prototype.visitHeaderDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("headers"); }; Oas30NodePathVisitor.prototype.visitOAuthFlows = function (node) { this._path.prependSegment("flows"); }; Oas30NodePathVisitor.prototype.visitImplicitOAuthFlow = function (node) { this._path.prependSegment("implicit"); }; Oas30NodePathVisitor.prototype.visitPasswordOAuthFlow = function (node) { this._path.prependSegment("password"); }; Oas30NodePathVisitor.prototype.visitClientCredentialsOAuthFlow = function (node) { this._path.prependSegment("clientCredentials"); }; Oas30NodePathVisitor.prototype.visitAuthorizationCodeOAuthFlow = function (node) { this._path.prependSegment("authorizationCode"); }; Oas30NodePathVisitor.prototype.visitLinkDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("links"); }; Oas30NodePathVisitor.prototype.visitCallbackDefinition = function (node) { this._path.prependSegment(node.name(), true); this._path.prependSegment("callbacks"); }; Oas30NodePathVisitor.prototype.visitSecurityScheme = function (node) { this._path.prependSegment(node.schemeName(), true); this._path.prependSegment("securitySchemes"); }; return Oas30NodePathVisitor; }(OasNodePathVisitor)); exports.Oas30NodePathVisitor = Oas30NodePathVisitor; //# sourceMappingURL=path.visitor.js.map