UNPKG

ern-api-gen

Version:

Electrode Native API generator

212 lines 6.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /* tslint:disable:variable-name */ /* tslint:disable:max-classes-per-file */ const javaUtil_1 = require("./javaUtil"); const factory_1 = __importDefault(require("../models/factory")); const response_1 = __importDefault(require("sway/lib/types/response")); const api_1 = __importDefault(require("sway/lib/types/api")); const path_1 = __importDefault(require("sway/lib/types/path")); const operation_1 = __importDefault(require("sway/lib/types/operation")); const parameters_1 = __importDefault(require("../models/parameters")); const beanUtils_1 = require("./beanUtils"); const properties_1 = require("../models/properties"); const PropertyBuilder_1 = require("../models/PropertyBuilder"); const auth_1 = __importDefault(require("../models/auth")); const sway_1 = __importDefault(require("sway")); const StringUtils_1 = require("./StringUtils"); const swagger_methods_1 = __importDefault(require("swagger-methods")); swagger_methods_1.default.push('event'); /** * This class fixes up Sway so that it can work as the model for swagger-codegen. * */ swagger_methods_1.default.map(function method(name) { this[`get${StringUtils_1.upperFirst(name)}`] = function () { return this.getOperation(name); }; }, path_1.default.prototype); path_1.default.prototype.toJSON = function () { return this.definition; }; const _asResponse = r => [(r.statusCode || 'default') + '', r]; function asParameter(p) { if (p.definition && '$ref' in p.definition) { return parameters_1.default(p.definitionFullyResolved); } return parameters_1.default(p.definition); } beanUtils_1.beanify(Object.assign(operation_1.default.prototype, { getVendorExtensions() { if (!this._vendorExtensions) { this._vendorExtensions = javaUtil_1.newHashMap(); } return this._vendorExtensions; }, getParameters() { if (!this._parameters) { if (this.parameterObjects) { this._parameters = this.parameterObjects.map(asParameter); } else if (this.parameters) { this._parameters = this.parameters.map(parameters_1.default); } } return this._parameters; }, getResponses() { if (!this._responses) { this._responses = javaUtil_1.newHashMap(...this.responseObjects.map(_asResponse)); } return this._responses; }, getSchema() { if (this._schema === void 0) { this._schema = this.schema ? factory_1.default(this.schema) : null; } return this._schema; }, setParameters(parameters) { this._parameters = parameters ? parameters.map(parameters_1.default) : []; }, }), [ 'produces', 'summary', 'tags', 'operationId', 'description', 'externalDocs', 'consumes', 'schemes', 'method', 'securityDefinitions', ]); beanUtils_1.beanify(Object.assign(response_1.default.prototype, { getSchema() { if (this._schema === void 0) { if (!this.definition.schema) { this._schema = null; } else { this._schema = factory_1.default(Object.assign({ description: this.definition.description }, this.definition.schema)); } } return this._schema; }, setSchema(schema) { if (schema instanceof properties_1.Property) { this._schema = schema; } else { this.schema = schema; } }, getCode() { return this.statusCode; }, getHeaders() { return (this.headers && javaUtil_1.newHashMap(...Object.keys(this.headers).map(key => [key, this.headers[key]]))); }, toJSON() { return this.definition; }, }), ['description', 'statusCode', 'examples']); class VendorExtensions { setVendorExtensions(extensions) { this.vendorExtensions = extensions; } getVendorExtensions() { if (!this.vendorExtensions) { this.setVendorExtensions(javaUtil_1.newHashMap()); } return this.vendorExtensions; } } class Contact extends VendorExtensions { } beanUtils_1.beanify(Contact.prototype, ['name', 'url', 'email']); class License extends VendorExtensions { } beanUtils_1.beanify(License.prototype, ['name', 'url']); class Info { getContact() { return beanUtils_1.apply(new Contact(), this.contact); } getLicense() { return beanUtils_1.apply(new License(), this.license); } } beanUtils_1.beanify(Info.prototype, [ 'title', 'description', 'version', 'title', 'termsOfService', ]); Object.assign(api_1.default.prototype, { addDefinition(name, definition) { let definitions = this.getDefinitions(); if (definitions == null) { definitions = this._definitions = javaUtil_1.newHashMap(); } definitions.put(name, definition); return this; }, getDefinitions() { if (this._definitions === void 0) { if (this.definitions == null) { this._definitions = null; } else { const defs = Object.keys(this.definitions).map(key => [ key, PropertyBuilder_1.toModel(factory_1.default(Object.assign({ name: key, }, this.definitions[key]))), ]); this._definitions = javaUtil_1.newHashMap(...defs); } } return this._definitions; }, getInfo() { if (!this._info) { this._info = beanUtils_1.apply(new Info(), this.info); } return this._info; }, getSecurityDefinitions() { if (!this._securityDefinitions) { const securityDefinitions = this.definitionFullyResolved.securityDefinitions || {}; const defs = Object.keys(securityDefinitions).map(key => [ key, auth_1.default(securityDefinitions[key]), ]); this._securityDefinitions = javaUtil_1.newHashMap(...defs); } return this._securityDefinitions; }, }); beanUtils_1.beanify(api_1.default.prototype, [ 'info', 'host', 'basePath', 'tags', 'schemes', 'produces', 'consumes', 'security', 'paths', 'securityDefinitions', 'definitions', 'parameters', 'responses', 'externalDocs', ['vendorExtensions', javaUtil_1.newHashMap], ]); exports.default = sway_1.default; //# sourceMappingURL=Swagger.js.map