UNPKG

fastman

Version:

快速api测试及文档生成

1,230 lines 87.7 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 document_model_1 = require("../models/2.0/document.model"); var document_model_2 = require("../models/3.0/document.model"); /** * This class reads a javascript object and turns it into a OAS model. */ var OasJS2ModelReader = /** @class */ (function () { function OasJS2ModelReader() { } /** * Returns true if the given thing is defined. * @param thing * @return {boolean} */ OasJS2ModelReader.prototype.isDefined = function (thing) { if (typeof thing === "undefined" || thing === null) { return false; } else { return true; } }; /** * Reads an OAS Document object from the given javascript data. * @param document * @param documentModel */ OasJS2ModelReader.prototype.readDocument = function (document, documentModel) { var info = document["info"]; var paths = document["paths"]; var security = document["security"]; var tags = document["tags"]; var externalDocs = document["externalDocs"]; if (this.isDefined(info)) { var infoModel = documentModel.createInfo(); this.readInfo(info, infoModel); documentModel.info = infoModel; } if (this.isDefined(paths)) { var pathsModel = documentModel.createPaths(); this.readPaths(paths, pathsModel); documentModel.paths = pathsModel; } if (this.isDefined(security)) { var securityModels = []; for (var _i = 0, security_1 = security; _i < security_1.length; _i++) { var sec = security_1[_i]; var secModel = documentModel.createSecurityRequirement(); this.readSecurityRequirement(sec, secModel); securityModels.push(secModel); } documentModel.security = securityModels; } if (this.isDefined(tags)) { var tagModels = []; for (var _a = 0, tags_1 = tags; _a < tags_1.length; _a++) { var tag = tags_1[_a]; var tagModel = documentModel.createTag(); this.readTag(tag, tagModel); tagModels.push(tagModel); } documentModel.tags = tagModels; } if (this.isDefined(externalDocs)) { var externalDocsModel = documentModel.createExternalDocumentation(); this.readExternalDocumentation(externalDocs, externalDocsModel); documentModel.externalDocs = externalDocsModel; } this.readExtensions(document, documentModel); }; /** * Reads a OAS Info object from the given javascript data. * @param info * @param infoModel */ OasJS2ModelReader.prototype.readInfo = function (info, infoModel) { var title = info["title"]; var description = info["description"]; var termsOfService = info["termsOfService"]; var contact = info["contact"]; var license = info["license"]; var version = info["version"]; if (this.isDefined(title)) { infoModel.title = title; } if (this.isDefined(description)) { infoModel.description = description; } if (this.isDefined(termsOfService)) { infoModel.termsOfService = termsOfService; } if (this.isDefined(contact)) { var contactModel = infoModel.createContact(); this.readContact(contact, contactModel); infoModel.contact = contactModel; } if (this.isDefined(license)) { var licenseModel = infoModel.createLicense(); this.readLicense(license, licenseModel); infoModel.license = licenseModel; } if (this.isDefined(version)) { infoModel.version = version; } this.readExtensions(info, infoModel); }; /** * Reads a OAS Contact object from the given javascript data. * @param contact * @param contactModel */ OasJS2ModelReader.prototype.readContact = function (contact, contactModel) { var name = contact["name"]; var url = contact["url"]; var email = contact["email"]; if (this.isDefined(name)) { contactModel.name = name; } if (this.isDefined(url)) { contactModel.url = url; } if (this.isDefined(email)) { contactModel.email = email; } this.readExtensions(contact, contactModel); }; /** * Reads a OAS License object from the given javascript data. * @param license * @param licenseModel */ OasJS2ModelReader.prototype.readLicense = function (license, licenseModel) { var name = license["name"]; var url = license["url"]; if (this.isDefined(name)) { licenseModel.name = name; } if (this.isDefined(url)) { licenseModel.url = url; } this.readExtensions(license, licenseModel); }; /** * Reads an OAS Paths object from the given JS data. * @param paths * @param pathsModel */ OasJS2ModelReader.prototype.readPaths = function (paths, pathsModel) { for (var path in paths) { if (path.indexOf("x-") === 0) { continue; } var pathItem = paths[path]; var pathItemModel = pathsModel.createPathItem(path); this.readPathItem(pathItem, pathItemModel); pathsModel.addPathItem(path, pathItemModel); } this.readExtensions(paths, pathsModel); }; /** * Reads an OAS PathItem object from the given JS data. * @param pathItem * @param pathItemModel */ OasJS2ModelReader.prototype.readPathItem = function (pathItem, pathItemModel) { var $ref = pathItem["$ref"]; var get = pathItem["get"]; var put = pathItem["put"]; var post = pathItem["post"]; var delete_ = pathItem["delete"]; var options = pathItem["options"]; var head = pathItem["head"]; var patch = pathItem["patch"]; var parameters = pathItem["parameters"]; if (this.isDefined($ref)) { pathItemModel.$ref = $ref; } if (this.isDefined(get)) { var opModel = pathItemModel.createOperation("get"); this.readOperation(get, opModel); pathItemModel.get = opModel; } if (this.isDefined(put)) { var opModel = pathItemModel.createOperation("put"); this.readOperation(put, opModel); pathItemModel.put = opModel; } if (this.isDefined(post)) { var opModel = pathItemModel.createOperation("post"); this.readOperation(post, opModel); pathItemModel.post = opModel; } if (this.isDefined(delete_)) { var opModel = pathItemModel.createOperation("delete"); this.readOperation(delete_, opModel); pathItemModel.delete = opModel; } if (this.isDefined(options)) { var opModel = pathItemModel.createOperation("options"); this.readOperation(options, opModel); pathItemModel.options = opModel; } if (this.isDefined(head)) { var opModel = pathItemModel.createOperation("head"); this.readOperation(head, opModel); pathItemModel.head = opModel; } if (this.isDefined(patch)) { var opModel = pathItemModel.createOperation("patch"); this.readOperation(patch, opModel); pathItemModel.patch = opModel; } if (this.isDefined(parameters)) { for (var _i = 0, parameters_1 = parameters; _i < parameters_1.length; _i++) { var parameter = parameters_1[_i]; var paramModel = pathItemModel.createParameter(); this.readParameter(parameter, paramModel); pathItemModel.addParameter(paramModel); } } this.readExtensions(pathItem, pathItemModel); }; /** * Reads an OAS Operation object from the given JS data. * @param operation * @param operationModel */ OasJS2ModelReader.prototype.readOperation = function (operation, operationModel) { var tags = operation["tags"]; var summary = operation["summary"]; var description = operation["description"]; var externalDocs = operation["externalDocs"]; var operationId = operation["operationId"]; var parameters = operation["parameters"]; var responses = operation["responses"]; var deprecated = operation["deprecated"]; var security = operation["security"]; if (this.isDefined(tags)) { operationModel.tags = tags; } if (this.isDefined(summary)) { operationModel.summary = summary; } if (this.isDefined(description)) { operationModel.description = description; } if (this.isDefined(externalDocs)) { var externalDocsModel = operationModel.createExternalDocumentation(); this.readExternalDocumentation(externalDocs, externalDocsModel); operationModel.externalDocs = externalDocsModel; } if (this.isDefined(operationId)) { operationModel.operationId = operationId; } if (this.isDefined(parameters)) { for (var _i = 0, parameters_2 = parameters; _i < parameters_2.length; _i++) { var parameter = parameters_2[_i]; var paramModel = operationModel.createParameter(); this.readParameter(parameter, paramModel); operationModel.addParameter(paramModel); } } if (this.isDefined(responses)) { var responsesModel = operationModel.createResponses(); this.readResponses(responses, responsesModel); operationModel.responses = responsesModel; } if (this.isDefined(deprecated)) { operationModel.deprecated = deprecated; } if (this.isDefined(security)) { for (var _a = 0, security_2 = security; _a < security_2.length; _a++) { var securityRequirement = security_2[_a]; var securityRequirementModel = operationModel.createSecurityRequirement(); this.readSecurityRequirement(securityRequirement, securityRequirementModel); operationModel.addSecurityRequirement(securityRequirementModel); } } this.readExtensions(operation, operationModel); }; /** * Reads an OAS Responses object from the given JS data. * @param responses * @param responsesModel */ OasJS2ModelReader.prototype.readResponses = function (responses, responsesModel) { var default_ = responses["default"]; if (this.isDefined(default_)) { var defaultModel = responsesModel.createResponse(); this.readResponse(default_, defaultModel); responsesModel.default = defaultModel; } for (var statusCode in responses) { if (statusCode.indexOf("x-") === 0) { continue; } if (statusCode === "default") { continue; } var response = responses[statusCode]; var responseModel = responsesModel.createResponse(statusCode); this.readResponse(response, responseModel); responsesModel.addResponse(statusCode, responseModel); } this.readExtensions(responses, responsesModel); }; /** * Reads an OAS Schema object from the given JS data. * @param schema * @param schemaModel */ OasJS2ModelReader.prototype.readSchema = function (schema, schemaModel) { var _this = this; var $ref = schema["$ref"]; var format = schema["format"]; var title = schema["title"]; var description = schema["description"]; var default_ = schema["default"]; var multipleOf = schema["multipleOf"]; var maximum = schema["maximum"]; var exclusiveMaximum = schema["exclusiveMaximum"]; var minimum = schema["minimum"]; var exclusiveMinimum = schema["exclusiveMinimum"]; var maxLength = schema["maxLength"]; // Require: integer var minLength = schema["minLength"]; // Require: integer var pattern = schema["pattern"]; var maxItems = schema["maxItems"]; // Require: integer var minItems = schema["minItems"]; // Require: integer var uniqueItems = schema["uniqueItems"]; var maxProperties = schema["maxProperties"]; var minProperties = schema["minProperties"]; var required = schema["required"]; var enum_ = schema["enum"]; var type = schema["type"]; var items = schema["items"]; var allOf = schema["allOf"]; var properties = schema["properties"]; var additionalProperties = schema["additionalProperties"]; var readOnly = schema["readOnly"]; var xml = schema["xml"]; var externalDocs = schema["externalDocs"]; var example = schema["example"]; if (this.isDefined($ref)) { schemaModel.$ref = $ref; } if (this.isDefined(format)) { schemaModel.format = format; } if (this.isDefined(title)) { schemaModel.title = title; } if (this.isDefined(description)) { schemaModel.description = description; } if (this.isDefined(default_)) { schemaModel.default = default_; } if (this.isDefined(multipleOf)) { schemaModel.multipleOf = multipleOf; } if (this.isDefined(maximum)) { schemaModel.maximum = maximum; } if (this.isDefined(exclusiveMaximum)) { schemaModel.exclusiveMaximum = exclusiveMaximum; } if (this.isDefined(minimum)) { schemaModel.minimum = minimum; } if (this.isDefined(exclusiveMinimum)) { schemaModel.exclusiveMinimum = exclusiveMinimum; } if (this.isDefined(maxLength)) { schemaModel.maxLength = maxLength; } if (this.isDefined(minLength)) { schemaModel.minLength = minLength; } if (this.isDefined(pattern)) { schemaModel.pattern = pattern; } if (this.isDefined(maxItems)) { schemaModel.maxItems = maxItems; } if (this.isDefined(minItems)) { schemaModel.minItems = minItems; } if (this.isDefined(uniqueItems)) { schemaModel.uniqueItems = uniqueItems; } if (this.isDefined(maxProperties)) { schemaModel.maxProperties = maxProperties; } if (this.isDefined(minProperties)) { schemaModel.minProperties = minProperties; } if (this.isDefined(required)) { schemaModel.required = required; } if (this.isDefined(enum_)) { schemaModel.enum = enum_; } if (this.isDefined(type)) { schemaModel.type = type; } if (this.isDefined(items)) { if (Array.isArray(items)) { schemaModel.items = items.map(function (item) { var itemsSchemaModel = schemaModel.createItemsSchema(); _this.readSchema(item, itemsSchemaModel); return itemsSchemaModel; }); } else { var itemsSchemaModel = schemaModel.createItemsSchema(); this.readSchema(items, itemsSchemaModel); schemaModel.items = itemsSchemaModel; } } if (this.isDefined(allOf)) { var schemaModels = []; for (var _i = 0, allOf_1 = allOf; _i < allOf_1.length; _i++) { var allOfSchema = allOf_1[_i]; var allOfSchemaModel = schemaModel.createAllOfSchema(); this.readSchema(allOfSchema, allOfSchemaModel); schemaModels.push(allOfSchemaModel); } schemaModel.allOf = schemaModels; } if (this.isDefined(properties)) { for (var propertyName in properties) { var propertySchema = properties[propertyName]; var propertySchemaModel = schemaModel.createPropertySchema(propertyName); this.readSchema(propertySchema, propertySchemaModel); schemaModel.addProperty(propertyName, propertySchemaModel); } } if (this.isDefined(additionalProperties)) { if (typeof additionalProperties === "boolean") { schemaModel.additionalProperties = additionalProperties; } else { var additionalPropertiesModel = schemaModel.createAdditionalPropertiesSchema(); this.readSchema(additionalProperties, additionalPropertiesModel); schemaModel.additionalProperties = additionalPropertiesModel; } } if (this.isDefined(readOnly)) { schemaModel.readOnly = readOnly; } if (this.isDefined(xml)) { var xmlModel = schemaModel.createXML(); this.readXML(xml, xmlModel); schemaModel.xml = xmlModel; } if (this.isDefined(externalDocs)) { var externalDocsModel = schemaModel.createExternalDocumentation(); this.readExternalDocumentation(externalDocs, externalDocsModel); schemaModel.externalDocs = externalDocsModel; } if (this.isDefined(example)) { schemaModel.example = example; } this.readExtensions(items, schemaModel); }; /** * Reads an OAS XML object from the given JS data. * @param xml * @param xmlModel */ OasJS2ModelReader.prototype.readXML = function (xml, xmlModel) { var name = xml["name"]; var namespace = xml["namespace"]; var prefix = xml["prefix"]; var attribute = xml["attribute"]; var wrapped = xml["wrapped"]; if (this.isDefined(name)) { xmlModel.name = name; } if (this.isDefined(namespace)) { xmlModel.namespace = namespace; } if (this.isDefined(prefix)) { xmlModel.prefix = prefix; } if (this.isDefined(attribute)) { xmlModel.attribute = attribute; } if (this.isDefined(wrapped)) { xmlModel.wrapped = wrapped; } this.readExtensions(xml, xmlModel); }; /** * Reads an OAS 2.0 Security Schema object from the given javascript data. * @param scheme * @param schemeModel */ OasJS2ModelReader.prototype.readSecurityScheme = function (scheme, schemeModel) { var type = scheme["type"]; var description = scheme["description"]; var name = scheme["name"]; var in_ = scheme["in"]; if (this.isDefined(type)) { schemeModel.type = type; } if (this.isDefined(description)) { schemeModel.description = description; } if (this.isDefined(name)) { schemeModel.name = name; } if (this.isDefined(in_)) { schemeModel.in = in_; } this.readExtensions(scheme, schemeModel); }; /** * Reads an OAS Security Requirement object from the given javascript data. * @param sec * @param secModel */ OasJS2ModelReader.prototype.readSecurityRequirement = function (sec, secModel) { for (var name in sec) { secModel.addSecurityRequirementItem(name, sec[name]); } }; /** * Reads a OAS Tag object from the given javascript data. * @param tag * @param tagModel */ OasJS2ModelReader.prototype.readTag = function (tag, tagModel) { var name = tag["name"]; var description = tag["description"]; var externalDocs = tag["externalDocs"]; if (this.isDefined(name)) { tagModel.name = name; } if (this.isDefined(description)) { tagModel.description = description; } if (this.isDefined(externalDocs)) { var externalDocsModel = tagModel.createExternalDocumentation(); this.readExternalDocumentation(externalDocs, externalDocsModel); tagModel.externalDocs = externalDocsModel; } this.readExtensions(tag, tagModel); }; /** * Reads an OAS External Documentation object from the given javascript data. * @param externalDocs * @param externalDocsModel */ OasJS2ModelReader.prototype.readExternalDocumentation = function (externalDocs, externalDocsModel) { var description = externalDocs["description"]; var url = externalDocs["url"]; if (this.isDefined(description)) { externalDocsModel.description = description; } if (this.isDefined(url)) { externalDocsModel.url = url; } this.readExtensions(externalDocs, externalDocsModel); }; /** * Reads all of the extension nodes. An extension node is characterized by a property * that begins with "x-". * @param jsData * @param model */ OasJS2ModelReader.prototype.readExtensions = function (jsData, model) { for (var key in jsData) { if (key.indexOf("x-") === 0) { var val = jsData[key]; model.addExtension(key, val); } } }; return OasJS2ModelReader; }()); exports.OasJS2ModelReader = OasJS2ModelReader; /** * This class reads a javascript object and turns it into a OAS 2.0 model. It is obviously * assumed that the javascript data actually does represent an OAS 2.0 document. */ var Oas20JS2ModelReader = /** @class */ (function (_super) { __extends(Oas20JS2ModelReader, _super); function Oas20JS2ModelReader() { return _super !== null && _super.apply(this, arguments) || this; } /** * Reads the given javascript data and returns an OAS 2.0 document. Throws an error if * the root 'swagger' property is not found or if its value is not "2.0". * @param jsData */ Oas20JS2ModelReader.prototype.read = function (jsData) { var docModel = new document_model_1.Oas20Document(); this.readDocument(jsData, docModel); return docModel; }; /** * Reads an OAS 2.0 Document object from the given javascript data. * @param document * @param documentModel */ Oas20JS2ModelReader.prototype.readDocument = function (document, documentModel) { var swagger = document["swagger"]; if (swagger != "2.0") { throw Error("Unsupported specification version: " + swagger); } _super.prototype.readDocument.call(this, document, documentModel); var host = document["host"]; var basePath = document["basePath"]; var schemes = document["schemes"]; var consumes = document["consumes"]; var produces = document["produces"]; var definitions = document["definitions"]; var parameters = document["parameters"]; var responses = document["responses"]; var securityDefinitions = document["securityDefinitions"]; if (this.isDefined(host)) { documentModel.host = host; } if (this.isDefined(basePath)) { documentModel.basePath = basePath; } if (this.isDefined(schemes)) { documentModel.schemes = schemes; } if (this.isDefined(consumes)) { documentModel.consumes = consumes; } if (this.isDefined(produces)) { documentModel.produces = produces; } if (this.isDefined(definitions)) { var definitionsModel = documentModel.createDefinitions(); this.readDefinitions(definitions, definitionsModel); documentModel.definitions = definitionsModel; } if (this.isDefined(parameters)) { var parametersDefinitionsModel = documentModel.createParametersDefinitions(); this.readParametersDefinitions(parameters, parametersDefinitionsModel); documentModel.parameters = parametersDefinitionsModel; } if (this.isDefined(responses)) { var responsesDefinitionsModel = documentModel.createResponsesDefinitions(); this.readResponsesDefinitions(responses, responsesDefinitionsModel); documentModel.responses = responsesDefinitionsModel; } if (this.isDefined(securityDefinitions)) { var securityDefinitionsModel = documentModel.createSecurityDefinitions(); this.readSecurityDefinitions(securityDefinitions, securityDefinitionsModel); documentModel.securityDefinitions = securityDefinitionsModel; } }; /** * Reads an OAS 2.0 Schema object from the given javascript data. * @param schema * @param schemaModel */ Oas20JS2ModelReader.prototype.readSchema = function (schema, schemaModel) { _super.prototype.readSchema.call(this, schema, schemaModel); var discriminator = schema["discriminator"]; if (this.isDefined(discriminator)) { schemaModel.discriminator = discriminator; } }; /** * Reads an OAS 2.0 Security Definitions object from the given javascript data. * @param securityDefinitions * @param securityDefinitionsModel */ Oas20JS2ModelReader.prototype.readSecurityDefinitions = function (securityDefinitions, securityDefinitionsModel) { for (var name in securityDefinitions) { var scheme = securityDefinitions[name]; var schemeModel = securityDefinitionsModel.createSecurityScheme(name); this.readSecurityScheme(scheme, schemeModel); securityDefinitionsModel.addSecurityScheme(name, schemeModel); } }; /** * Reads an OAS 2.0 Security Schema object from the given javascript data. * @param scheme * @param schemeModel */ Oas20JS2ModelReader.prototype.readSecurityScheme = function (scheme, schemeModel) { _super.prototype.readSecurityScheme.call(this, scheme, schemeModel); var flow = scheme["flow"]; var authorizationUrl = scheme["authorizationUrl"]; var tokenUrl = scheme["tokenUrl"]; var scopes = scheme["scopes"]; if (this.isDefined(flow)) { schemeModel.flow = flow; } if (this.isDefined(authorizationUrl)) { schemeModel.authorizationUrl = authorizationUrl; } if (this.isDefined(tokenUrl)) { schemeModel.tokenUrl = tokenUrl; } if (this.isDefined(scopes)) { var scopesModel = schemeModel.createScopes(); this.readScopes(scopes, scopesModel); schemeModel.scopes = scopesModel; } }; /** * Reads an OAS 2.0 Scopes object from the given javascript data. * @param scopes * @param scopesModel */ Oas20JS2ModelReader.prototype.readScopes = function (scopes, scopesModel) { for (var scope in scopes) { if (scope.indexOf("x-") === 0) { continue; } var description = scopes[scope]; scopesModel.addScope(scope, description); } this.readExtensions(scopes, scopesModel); }; /** * Reads an OAS 2.0 Operation object from the given JS data. * @param operation * @param operationModel */ Oas20JS2ModelReader.prototype.readOperation = function (operation, operationModel) { _super.prototype.readOperation.call(this, operation, operationModel); var consumes = operation["consumes"]; var produces = operation["produces"]; var schemes = operation["schemes"]; if (this.isDefined(consumes)) { operationModel.consumes = consumes; } if (this.isDefined(produces)) { operationModel.produces = produces; } if (this.isDefined(schemes)) { operationModel.schemes = schemes; } }; /** * Reads an OAS 2.0 Parameter object from the given JS data. * @param parameter * @param paramModel */ Oas20JS2ModelReader.prototype.readParameter = function (parameter, paramModel) { var $ref = parameter["$ref"]; if (this.isDefined($ref)) { paramModel.$ref = $ref; } this.readParameterBase(parameter, paramModel); }; /** * Reads an OAS 2.0 Parameter Definition from the given JS data. * @param parameterDef * @param paramDefModel */ Oas20JS2ModelReader.prototype.readParameterDefinition = function (parameterDef, paramDefModel) { this.readParameterBase(parameterDef, paramDefModel); }; /** * Reads an OAS 2.0 Parameter object from the given JS data. * @param parameter * @param paramModel */ Oas20JS2ModelReader.prototype.readParameterBase = function (parameter, paramModel) { this.readItems(parameter, paramModel); var name = parameter["name"]; var in_ = parameter["in"]; var description = parameter["description"]; var required = parameter["required"]; var schema = parameter["schema"]; var allowEmptyValue = parameter["allowEmptyValue"]; if (this.isDefined(name)) { paramModel.name = name; } if (this.isDefined(in_)) { paramModel.in = in_; } if (this.isDefined(description)) { paramModel.description = description; } if (this.isDefined(required)) { paramModel.required = required; } if (this.isDefined(schema)) { var schemaModel = paramModel.createSchema(); this.readSchema(schema, schemaModel); paramModel.schema = schemaModel; } if (this.isDefined(allowEmptyValue)) { paramModel.allowEmptyValue = allowEmptyValue; } this.readExtensions(parameter, paramModel); }; /** * Reads an OAS 2.0 Items object from the given JS data. * @param items * @param itemsModel */ Oas20JS2ModelReader.prototype.readItems = function (items, itemsModel) { var type = items["type"]; var format = items["format"]; var itemsChild = items["items"]; var collectionFormat = items["collectionFormat"]; var default_ = items["default"]; var maximum = items["maximum"]; var exclusiveMaximum = items["exclusiveMaximum"]; var minimum = items["minimum"]; var exclusiveMinimum = items["exclusiveMinimum"]; var maxLength = items["maxLength"]; // Require: integer var minLength = items["minLength"]; // Require: integer var pattern = items["pattern"]; var maxItems = items["maxItems"]; // Require: integer var minItems = items["minItems"]; // Require: integer var uniqueItems = items["uniqueItems"]; var enum_ = items["enum"]; var multipleOf = items["multipleOf"]; if (this.isDefined(type)) { itemsModel.type = type; } if (this.isDefined(format)) { itemsModel.format = format; } if (this.isDefined(itemsChild)) { var itemsChildModel = itemsModel.createItems(); this.readItems(itemsChild, itemsChildModel); itemsModel.items = itemsChildModel; } if (this.isDefined(collectionFormat)) { itemsModel.collectionFormat = collectionFormat; } if (this.isDefined(default_)) { itemsModel.default = default_; } if (this.isDefined(maximum)) { itemsModel.maximum = maximum; } if (this.isDefined(exclusiveMaximum)) { itemsModel.exclusiveMaximum = exclusiveMaximum; } if (this.isDefined(minimum)) { itemsModel.minimum = minimum; } if (this.isDefined(exclusiveMinimum)) { itemsModel.exclusiveMinimum = exclusiveMinimum; } if (this.isDefined(maxLength)) { itemsModel.maxLength = maxLength; } if (this.isDefined(minLength)) { itemsModel.minLength = minLength; } if (this.isDefined(pattern)) { itemsModel.pattern = pattern; } if (this.isDefined(maxItems)) { itemsModel.maxItems = maxItems; } if (this.isDefined(minItems)) { itemsModel.minItems = minItems; } if (this.isDefined(uniqueItems)) { itemsModel.uniqueItems = uniqueItems; } if (this.isDefined(enum_)) { itemsModel.enum = enum_; } if (this.isDefined(multipleOf)) { itemsModel.multipleOf = multipleOf; } this.readExtensions(items, itemsModel); }; /** * Reads an OAS 2.0 Response object from the given JS data. * @param response * @param responseModel */ Oas20JS2ModelReader.prototype.readResponse = function (response, responseModel) { var $ref = response["$ref"]; if (this.isDefined($ref)) { responseModel.$ref = $ref; } this.readResponseBase(response, responseModel); }; /** * Reads an OAS 2.0 Response Definition object from the given JS data. * @param response * @param responseDefModel */ Oas20JS2ModelReader.prototype.readResponseDefinition = function (response, responseDefModel) { this.readResponseBase(response, responseDefModel); }; /** * Reads an OAS 2.0 Response object from the given JS data. * @param response * @param responseModel */ Oas20JS2ModelReader.prototype.readResponseBase = function (response, responseModel) { var description = response["description"]; var schema = response["schema"]; var headers = response["headers"]; var examples = response["examples"]; if (this.isDefined(description)) { responseModel.description = description; } if (this.isDefined(schema)) { var schemaModel = responseModel.createSchema(); this.readSchema(schema, schemaModel); responseModel.schema = schemaModel; } if (this.isDefined(headers)) { var headersModel = responseModel.createHeaders(); this.readHeaders(headers, headersModel); responseModel.headers = headersModel; } if (this.isDefined(examples)) { var exampleModel = responseModel.createExample(); this.readExample(examples, exampleModel); responseModel.examples = exampleModel; } this.readExtensions(response, responseModel); }; /** * Reads an OAS 2.0 Example object from the given JS data. * @param examples * @param exampleModel */ Oas20JS2ModelReader.prototype.readExample = function (examples, exampleModel) { for (var contentType in examples) { var example = examples[contentType]; exampleModel.addExample(contentType, example); } }; /** * Reads an OAS Headers object from the given JS data. * @param headers * @param headersModel */ Oas20JS2ModelReader.prototype.readHeaders = function (headers, headersModel) { for (var headerName in headers) { var header = headers[headerName]; var headerModel = headersModel.createHeader(headerName); this.readHeader(header, headerModel); headersModel.addHeader(headerName, headerModel); } }; /** * Reads an OAS 2.0 Header object from the given JS data. * @param header * @param headerModel */ Oas20JS2ModelReader.prototype.readHeader = function (header, headerModel) { var description = header["description"]; if (this.isDefined(description)) { headerModel.description = description; } this.readItems(header, headerModel); }; /** * Reads an OAS 2.0 Definitions object from the given JS data. * @param definitions * @param definitionsModel */ Oas20JS2ModelReader.prototype.readDefinitions = function (definitions, definitionsModel) { for (var definitionName in definitions) { var definition = definitions[definitionName]; var definitionSchemaModel = definitionsModel.createSchemaDefinition(definitionName); this.readSchema(definition, definitionSchemaModel); definitionsModel.addDefinition(definitionName, definitionSchemaModel); } }; /** * Reads an OAS 2.0 Parameters Definitions object from the given JS data. * @param parameters * @param parametersDefinitionsModel */ Oas20JS2ModelReader.prototype.readParametersDefinitions = function (parameters, parametersDefinitionsModel) { for (var parameterName in parameters) { var parameter = parameters[parameterName]; var parameterDefModel = parametersDefinitionsModel.createParameter(parameterName); this.readParameterDefinition(parameter, parameterDefModel); parametersDefinitionsModel.addParameter(parameterName, parameterDefModel); } }; /** * Reads an OAS 2.0 Responses Definitions object from the given JS data. * @param responses * @param responsesDefinitionsModel */ Oas20JS2ModelReader.prototype.readResponsesDefinitions = function (responses, responsesDefinitionsModel) { for (var responseName in responses) { var response = responses[responseName]; var responseModel = responsesDefinitionsModel.createResponse(responseName); this.readResponseBase(response, responseModel); responsesDefinitionsModel.addResponse(responseName, responseModel); } }; return Oas20JS2ModelReader; }(OasJS2ModelReader)); exports.Oas20JS2ModelReader = Oas20JS2ModelReader; /** * A visitor used to invoke the appropriate readXYZ() method on the Oas20JS2ModelReader * class. This is useful when reading a partial (non root) model from a JS object. The * caller still needs to first construct the appropriate model prior to reading into it. */ var Oas20JS2ModelReaderVisitor = /** @class */ (function () { /** * Constructor. * @param reader * @param jsData */ function Oas20JS2ModelReaderVisitor(reader, jsData) { this.reader = reader; this.jsData = jsData; } Oas20JS2ModelReaderVisitor.prototype.visitDocument = function (node) { // Not supported - call the reader directly if you want to read a full document. }; Oas20JS2ModelReaderVisitor.prototype.visitInfo = function (node) { this.reader.readInfo(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitContact = function (node) { this.reader.readContact(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitLicense = function (node) { this.reader.readLicense(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitPaths = function (node) { this.reader.readPaths(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitPathItem = function (node) { this.reader.readPathItem(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitOperation = function (node) { this.reader.readOperation(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitParameter = function (node) { this.reader.readParameter(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitParameterDefinition = function (node) { this.reader.readParameterDefinition(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitExternalDocumentation = function (node) { this.reader.readExternalDocumentation(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitSecurityRequirement = function (node) { this.reader.readSecurityRequirement(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitResponses = function (node) { this.reader.readResponses(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitResponse = function (node) { this.reader.readResponse(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitResponseDefinition = function (node) { this.reader.readResponseDefinition(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitSchema = function (node) { this.reader.readSchema(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitHeaders = function (node) { this.reader.readHeaders(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitHeader = function (node) { this.reader.readHeader(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitExample = function (node) { this.reader.readExample(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitItems = function (node) { this.reader.readItems(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitTag = function (node) { this.reader.readTag(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitSecurityDefinitions = function (node) { this.reader.readSecurityDefinitions(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitSecurityScheme = function (node) { this.reader.readSecurityScheme(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitScopes = function (node) { this.reader.readScopes(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitXML = function (node) { this.reader.readXML(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitSchemaDefinition = function (node) { this.reader.readSchema(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitPropertySchema = function (node) { this.reader.readSchema(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitAdditionalPropertiesSchema = function (node) { this.reader.readSchema(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitAllOfSchema = function (node) { this.reader.readSchema(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitItemsSchema = function (node) { this.reader.readSchema(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitDefinitions = function (node) { this.reader.readDefinitions(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitParametersDefinitions = function (node) { this.reader.readParametersDefinitions(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitResponsesDefinitions = function (node) { this.reader.readResponsesDefinitions(this.jsData, node); }; Oas20JS2ModelReaderVisitor.prototype.visitExtension = function (node) { // Not supported: cannot read a single extension }; Oas20JS2ModelReaderVisitor.prototype.visitValidationProblem = function (node) { // Not supported: validation problems are transient }; return Oas20JS2ModelReaderVisitor; }()); exports.Oas20JS2ModelReaderVisitor = Oas20JS2ModelReaderVisitor; /** * A visitor used to invoke the appropriate readXYZ() method on the Oas20JS2ModelReader * class. This is useful when reading a partial (non root) model from a JS object. The * caller still needs to first construct the appropriate model prior to reading into it. */ var Oas30JS2ModelReaderVisitor = /** @class */ (function () { /** * Constructor. * @param reader * @param jsData */ function Oas30JS2ModelReaderVisitor(reader, jsData) { this.reader = reader; this.jsData = jsData; } Oas30JS2ModelReaderVisitor.prototype.visitDocument = function (node) { // Not supported - call the reader directly if you want to read a full document. }; Oas30JS2ModelReaderVisitor.prototype.visitInfo = function (node) { this.reader.readInfo(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitContact = function (node) { this.reader.readContact(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitLicense = function (node) { this.reader.readLicense(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitPaths = function (node) { this.reader.readPaths(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitPathItem = function (node) { this.reader.readPathItem(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitOperation = function (node) { this.reader.readOperation(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitParameter = function (node) { this.reader.readParameter(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitParameterDefinition = function (node) { this.reader.readParameterBase(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitResponses = function (node) { this.reader.readResponses(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitResponse = function (node) { this.reader.readResponse(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitMediaType = function (node) { this.reader.readMediaType(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitEncoding = function (node) { this.reader.readEncoding(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitExample = function (node) { this.reader.readExample(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitLink = function (node) { this.reader.readLink(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitLinkParameterExpression = function (node) { // Nothing to read - the expression is simple and not extensible }; Oas30JS2ModelReaderVisitor.prototype.visitLinkRequestBodyExpression = function (node) { // Nothing to read - the expression is simple and not extensible }; Oas30JS2ModelReaderVisitor.prototype.visitLinkServer = function (node) { this.reader.readServer(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitResponseDefinition = function (node) { this.reader.readResponseBase(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitSchema = function (node) { this.reader.readSchema(this.jsData, node); }; Oas30JS2ModelReaderVisitor.prototype.visitDiscriminator = function (node) { this.reader.readDiscriminator(this.jsData, node); }; Oas30JS2ModelReaderVi