UNPKG

ern-api-gen

Version:

Electrode Native API generator

841 lines 36.2 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 */ const CliOption_1 = __importDefault(require("../CliOption")); const CodegenConstants_1 = __importDefault(require("../CodegenConstants")); const CodegenModel_1 = __importDefault(require("../CodegenModel")); const CodegenOperation_1 = __importDefault(require("../CodegenOperation")); const CodegenParameter_1 = __importDefault(require("../CodegenParameter")); const CodegenProperty_1 = __importDefault(require("../CodegenProperty")); const CodegenType_1 = __importDefault(require("../CodegenType")); const DefaultCodegen_1 = __importDefault(require("../DefaultCodegen")); const SupportingFile_1 = __importDefault(require("../SupportingFile")); const ArrayModel_1 = __importDefault(require("../models/ArrayModel")); const ModelImpl_1 = __importDefault(require("../models/ModelImpl")); const properties_1 = require("../models/properties"); const LoggerFactory_1 = __importDefault(require("../java/LoggerFactory")); const File_1 = __importDefault(require("../java/File")); const javaUtil_1 = require("../java/javaUtil"); const StringBuilder_1 = __importDefault(require("../java/StringBuilder")); const StringUtils_1 = require("../java/StringUtils"); const path_1 = __importDefault(require("path")); const BooleanHelper_1 = require("../java/BooleanHelper"); class JavascriptClientCodegen extends DefaultCodegen_1.default { constructor() { super(); this.sourceFolder = 'src'; this.localVariablePrefix = ''; this.emitJSDoc = true; this.apiDocPath = 'docs/'; this.modelDocPath = 'docs/'; this.apiTestPath = 'api/'; this.modelTestPath = 'model/'; this.usePromises = false; this.emitModelMethods = false; this.__outputFolder = 'generated-code/js'; this.__templateDir = 'Javascript'; this.__apiPackage = 'api'; this.__modelPackage = 'model'; this.__typeMapping = javaUtil_1.newHashMap(['array', 'Array'], ['map', 'Object'], ['List', 'Array'], ['boolean', 'Boolean'], ['string', 'String'], ['int', 'Integer'], ['float', 'Number'], ['number', 'Number'], ['DateTime', 'Date'], ['date', 'Date'], ['long', 'Integer'], ['short', 'Integer'], ['char', 'String'], ['double', 'Number'], ['object', 'Object'], ['integer', 'Integer'], ['ByteArray', 'String'], ['binary', 'String'], ['UUID', 'String']); this._swaggerToFlowMapping = javaUtil_1.newHashMap(['Integer', 'number'], ['Number', 'number'], ['String', 'string'], ['Boolean', 'boolean']); this.__languageSpecificPrimitives = javaUtil_1.newHashSet('String', 'Boolean', 'Integer', 'Number', 'Array', 'Object', 'Date', 'File'); this.__modelTemplateFiles.put('model.mustache', '.js'); this.__modelTestTemplateFiles.put('model_test.mustache', '.js'); this.__apiTemplateFiles.put('api.mustache', '.js'); this.__apiTestTemplateFiles.put('api_test.mustache', '.js'); this.__modelDocTemplateFiles.put('model_doc.mustache', '.md'); this.__apiDocTemplateFiles.put('api_doc.mustache', '.md'); this.__defaultIncludes = javaUtil_1.newHashSet(...this.__languageSpecificPrimitives); this.__instantiationTypes.put('array', 'Array'); this.__instantiationTypes.put('list', 'Array'); this.__instantiationTypes.put('map', 'Object'); this.__supportingFiles.push(new SupportingFile_1.default('git_push.sh.mustache', '', 'git_push.sh')); this.__supportingFiles.push(new SupportingFile_1.default('README.mustache', '', 'README.md')); this.__supportingFiles.push(new SupportingFile_1.default('mocha.opts', '', 'mocha.opts')); this.__supportingFiles.push(new SupportingFile_1.default('travis.yml', '', '.travis.yml')); // this.__supportingFiles.push(new SupportingFile("package.mustache", "", "package.json")); this.setReservedWordsLowerCase([ 'abstract', 'arguments', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'double', 'else', 'enum', 'eval', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'short', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'var', 'void', 'volatile', 'while', 'with', 'yield', 'Array', 'Date', 'eval', 'function', 'hasOwnProperty', 'Infinity', 'isFinite', 'isNaN', 'isPrototypeOf', 'Math', 'NaN', 'Number', 'Object', 'prototype', 'String', 'toString', 'undefined', 'valueOf', ]); } static reconcileInlineEnums(codegenModel, parentCodegenModel) { if (parentCodegenModel.hasEnums) { const parentModelCodegenProperties = parentCodegenModel.vars; const codegenProperties = codegenModel.vars; let removedChildEnum = false; for (const parentModelCodegenPropery of parentModelCodegenProperties) { if (parentModelCodegenPropery.isEnum) { for (let i = codegenProperties.length; i--;) { const codegenProperty = codegenProperties[i]; if (codegenProperty.isEnum && codegenProperty.equals(parentModelCodegenPropery)) { codegenProperties.splice(i, 1); removedChildEnum = true; } } } } if (removedChildEnum) { let codegenProperty; for (codegenProperty of codegenProperties) { codegenProperty.hasMore = true; } codegenProperty.hasMore = false; codegenModel.vars = codegenProperties; } } return codegenModel; } initalizeCliOptions() { super.initalizeCliOptions(); this.__cliOptions.push(new CliOption_1.default(CodegenConstants_1.default.SOURCE_FOLDER, CodegenConstants_1.default.SOURCE_FOLDER_DESC).defaultValue('src')); this.__cliOptions.push(new CliOption_1.default(CodegenConstants_1.default.LOCAL_VARIABLE_PREFIX, CodegenConstants_1.default.LOCAL_VARIABLE_PREFIX_DESC)); this.__cliOptions.push(new CliOption_1.default(CodegenConstants_1.default.INVOKER_PACKAGE, CodegenConstants_1.default.INVOKER_PACKAGE_DESC)); this.__cliOptions.push(new CliOption_1.default(CodegenConstants_1.default.API_PACKAGE, CodegenConstants_1.default.API_PACKAGE_DESC)); this.__cliOptions.push(new CliOption_1.default(CodegenConstants_1.default.MODEL_PACKAGE, CodegenConstants_1.default.MODEL_PACKAGE_DESC)); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.PROJECT_NAME, 'name of the project (Default: generated from info.title or "swagger-js-client")')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.MODULE_NAME, 'module name for AMD, Node or globals (Default: generated from <projectName>)')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.PROJECT_DESCRIPTION, 'description of the project (Default: using info.description or "Client library of <projectName>")')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.PROJECT_VERSION, 'version of the project (Default: using info.version or "1.0.0")')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.PROJECT_LICENSE_NAME, 'name of the license the project uses (Default: using info.license.name)')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.USE_PROMISES, 'use Promises as return values from the client API, instead of superagent callbacks').defaultValue('false')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.EMIT_MODEL_METHODS, 'generate getters and setters for model properties').defaultValue('false')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.EMIT_JS_DOC, 'generate JSDoc comments').defaultValue('true')); this.__cliOptions.push(new CliOption_1.default(JavascriptClientCodegen.USE_INHERITANCE, 'use JavaScript prototype chains & delegation for inheritance').defaultValue('true')); } getTag() { return CodegenType_1.default.CLIENT; } getName() { return 'javascript'; } getHelp() { return 'Generates a Javascript client library.'; } processOpts() { super.processOpts(); if (this.__additionalProperties.containsKey(JavascriptClientCodegen.PROJECT_NAME)) { ; this.setProjectName(this.__additionalProperties.get(JavascriptClientCodegen.PROJECT_NAME)); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.MODULE_NAME)) { ; this.setModuleName(this.__additionalProperties.get(JavascriptClientCodegen.MODULE_NAME)); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.PROJECT_DESCRIPTION)) { ; this.setProjectDescription(this.__additionalProperties.get(JavascriptClientCodegen.PROJECT_DESCRIPTION)); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.PROJECT_VERSION)) { ; this.setProjectVersion(this.__additionalProperties.get(JavascriptClientCodegen.PROJECT_VERSION)); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.PROJECT_LICENSE_NAME)) { ; this.setProjectLicenseName(this.__additionalProperties.get(JavascriptClientCodegen.PROJECT_LICENSE_NAME)); } if (this.__additionalProperties.containsKey(CodegenConstants_1.default.LOCAL_VARIABLE_PREFIX)) { ; this.setLocalVariablePrefix(this.__additionalProperties.get(CodegenConstants_1.default.LOCAL_VARIABLE_PREFIX)); } if (this.__additionalProperties.containsKey(CodegenConstants_1.default.SOURCE_FOLDER)) { ; this.setSourceFolder(this.__additionalProperties.get(CodegenConstants_1.default.SOURCE_FOLDER)); } if (this.__additionalProperties.containsKey(CodegenConstants_1.default.INVOKER_PACKAGE)) { ; this.setInvokerPackage(this.__additionalProperties.get(CodegenConstants_1.default.INVOKER_PACKAGE)); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.USE_PROMISES)) { this.usePromises = BooleanHelper_1.parseBoolean(this.__additionalProperties.get(JavascriptClientCodegen.USE_PROMISES)); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.USE_INHERITANCE)) { this.supportsInheritance = BooleanHelper_1.parseBoolean(this.__additionalProperties.get(JavascriptClientCodegen.USE_INHERITANCE)); } else { this.supportsInheritance = true; } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.EMIT_MODEL_METHODS)) { ; this.setEmitModelMethods(BooleanHelper_1.parseBoolean(this.__additionalProperties.get(JavascriptClientCodegen.EMIT_MODEL_METHODS))); } if (this.__additionalProperties.containsKey(JavascriptClientCodegen.EMIT_JS_DOC)) { ; this.setEmitJSDoc(BooleanHelper_1.parseBoolean(this.__additionalProperties.get(JavascriptClientCodegen.EMIT_JS_DOC))); } } preprocessSwagger(swagger) { super.preprocessSwagger(swagger); if (swagger.getInfo() != null) { const info = swagger.getInfo(); if (StringUtils_1.isEmpty(this.projectName) && info.getTitle() != null) { this.projectName = this.sanitizeName(this.dashize(info.getTitle())); } if (StringUtils_1.isEmpty(this.projectVersion)) { this.projectVersion = this.escapeUnsafeCharacters(this.escapeQuotationMark(info.getVersion())); } if (this.projectDescription == null && info.getDescription()) { this.projectDescription = this.sanitizeName(info.getDescription()); } if (this.__additionalProperties.get(JavascriptClientCodegen.PROJECT_LICENSE_NAME) == null) { if (info.getLicense() != null) { const license = info.getLicense(); this.__additionalProperties.put(JavascriptClientCodegen.PROJECT_LICENSE_NAME, this.sanitizeName(license.getName())); } } } if (StringUtils_1.isEmpty(this.projectName)) { this.projectName = 'swagger-js-client'; } if (StringUtils_1.isEmpty(this.moduleName)) { this.moduleName = DefaultCodegen_1.default.camelize(DefaultCodegen_1.default.underscore(this.projectName)); } if (StringUtils_1.isEmpty(this.projectVersion)) { this.projectVersion = '1.0.0'; } if (this.projectDescription == null) { this.projectDescription = 'Client library of ' + this.projectName; } this.__additionalProperties.put(JavascriptClientCodegen.PROJECT_NAME, this.projectName); this.__additionalProperties.put(JavascriptClientCodegen.MODULE_NAME, this.moduleName); this.__additionalProperties.put(JavascriptClientCodegen.PROJECT_DESCRIPTION, this.escapeText(this.projectDescription)); this.__additionalProperties.put(JavascriptClientCodegen.PROJECT_VERSION, this.projectVersion); this.__additionalProperties.put(CodegenConstants_1.default.API_PACKAGE, this.__apiPackage); this.__additionalProperties.put(CodegenConstants_1.default.INVOKER_PACKAGE, this.invokerPackage); this.__additionalProperties.put(CodegenConstants_1.default.LOCAL_VARIABLE_PREFIX, this.localVariablePrefix); this.__additionalProperties.put(CodegenConstants_1.default.MODEL_PACKAGE, this.__modelPackage); this.__additionalProperties.put(CodegenConstants_1.default.SOURCE_FOLDER, this.sourceFolder); this.__additionalProperties.put(JavascriptClientCodegen.USE_PROMISES, this.usePromises); this.__additionalProperties.put(JavascriptClientCodegen.USE_INHERITANCE, this.supportsInheritance); this.__additionalProperties.put(JavascriptClientCodegen.EMIT_MODEL_METHODS, this.emitModelMethods); this.__additionalProperties.put(JavascriptClientCodegen.EMIT_JS_DOC, this.emitJSDoc); this.__additionalProperties.put('apiDocPath', this.apiDocPath); this.__additionalProperties.put('modelDocPath', this.modelDocPath); this.__supportingFiles.push(new SupportingFile_1.default('index.mustache', this.createPath(this.sourceFolder, this.invokerPackage), 'index.js')); this.__supportingFiles.push(new SupportingFile_1.default('ApiClient.mustache', this.createPath(this.sourceFolder, this.invokerPackage), 'ApiClient.js')); } escapeReservedWord(name) { return '_' + name; } /** * Concatenates an array of path segments into a path string. * @param segments The path segments to concatenate. A segment may contain either of the file separator characters '\' or '/'. * A segment is ignored if it is <code>null</code>, empty or &quot;.&quot;. * @return A path string using the correct platform-specific file separator character. */ createPath(...segments) { const buf = StringBuilder_1.default(); for (const segment of segments) { if (!StringUtils_1.isEmpty(segment) && !(segment === '.')) { if (buf.length() !== 0) { buf.append(File_1.default.separatorChar); } buf.append(segment); } } return path_1.default.normalize(buf.toString()); } apiTestFileFolder() { return (this.__outputFolder + path_1.default.sep + 'test' + path_1.default.sep + this.apiTestPath) .split(path_1.default.sep) .join(File_1.default.separatorChar); } modelTestFileFolder() { return (this.__outputFolder + path_1.default.sep + 'test' + path_1.default.sep + this.modelTestPath) .split(path_1.default.sep) .join(File_1.default.separatorChar); } apiFileFolder() { return this.createPath(this.__outputFolder, this.sourceFolder, this.invokerPackage, this.apiPackage()); } modelFileFolder() { return this.createPath(this.__outputFolder, this.sourceFolder, this.invokerPackage, this.modelPackage()); } apiDocFileFolder() { return this.createPath(this.__outputFolder, this.apiDocPath); } modelDocFileFolder() { return this.createPath(this.__outputFolder, this.modelDocPath); } toApiDocFilename(name) { return this.toApiName(name); } toModelDocFilename(name) { return this.toModelName(name); } toApiTestFilename(name) { return this.toApiName(name) + '.spec'; } toModelTestFilename(name) { return this.toModelName(name) + '.spec'; } toVarName(name) { name = this.sanitizeName(name); if ('_' === name) { name = '_u'; } if (name.match('^[A-Z_]*$')) { return name; } name = DefaultCodegen_1.default.camelize(name, true); if (this.isReservedWord(name) || name.match('^\\d.*')) { name = this.escapeReservedWord(name); } return name; } toParamName(name) { return this.toVarName(name); } toModelName(name) { name = this.sanitizeName(name); if (!StringUtils_1.isEmpty(this.modelNamePrefix)) { name = this.modelNamePrefix + '_' + name; } if (!StringUtils_1.isEmpty(this.modelNameSuffix)) { name = name + '_' + this.modelNameSuffix; } name = DefaultCodegen_1.default.camelize(name); if (this.isReservedWord(name)) { const modelName = 'Model' + name; Log.warn(name + ' (reserved word) cannot be used as model name. Renamed to ' + modelName); return modelName; } if (name.match('^\\d.*')) { const modelName = 'Model' + name; Log.warn(name + ' (model name starts with number) cannot be used as model name. Renamed to ' + modelName); return modelName; } return name; } toModelFilename(name) { return this.toModelName(name); } toModelImport(name) { return name; } toApiImport(name) { return this.toApiName(name); } getTypeDeclaration(p) { if (p != null && p instanceof properties_1.ArrayProperty) { const inner = p.getItems(); return '[' + this.getTypeDeclaration(inner) + ']'; } else if (p != null && p instanceof properties_1.MapProperty) { const inner = p.getAdditionalProperties(); return '{String: ' + this.getTypeDeclaration(inner) + '}'; } return super.getTypeDeclaration(p); } toDefaultValue(p) { const dp = p.getDefault(); if (dp != null) { if (p instanceof properties_1.StringProperty) { return JSON.stringify(dp) + ''; } if (p instanceof properties_1.BooleanProperty || p instanceof properties_1.DoubleProperty || p instanceof properties_1.FloatProperty || p instanceof properties_1.IntegerProperty || p instanceof properties_1.LongProperty) { return dp.toString(); } } return dp; } toDefaultValueWithParam(name, p) { const type = this.normalizeType(this.getTypeDeclaration(p)); if (p instanceof properties_1.RefProperty) { return ' = ' + type + ".constructFromObject(data['" + name + "']);"; } else { return " = ApiClient.convertToType(data['" + name + "'], " + type + ');'; } } setParameterExampleValue(p) { let example; if (p.defaultValue == null) { example = p.example; } else { example = p.defaultValue; } let type = p.baseType; if (type == null) { type = p.dataType; } if ('String' === type) { if (example == null) { example = p.paramName + '_example'; } example = '"' + this.escapeText(example) + '"'; } else if ('Integer' === type) { if (example == null) { example = '56'; } } else if ('Number' === type) { if (example == null) { example = '3.4'; } } else if ('Boolean' === type) { if (example == null) { example = 'true'; } } else if ('File' === type) { if (example == null) { example = '/path/to/file'; } example = '"' + this.escapeText(example) + '"'; } else if ('Date' === type) { if (example == null) { example = '2013-10-20T19:20:30+01:00'; } example = 'new Date("' + this.escapeText(example) + '")'; } else if (!this.__languageSpecificPrimitives.contains(type)) { example = 'new ' + this.moduleName + '.' + type + '()'; } if (example == null) { example = 'null'; } else if (p.isListContainer) { example = '[' + example + ']'; } else if (p.isMapContainer) { example = '{key: ' + example + '}'; } p.example = example; } /** * Normalize type by wrapping primitive types with single quotes. * * @param type Primitive type * @return Normalized type */ normalizeType(type) { return type.replace(new RegExp('\\b(Boolean|Integer|Number|String|Date)\\b', 'g'), "'$1'"); } getSwaggerType(p) { const swaggerType = super.getSwaggerType(p); let type = null; if (this.__typeMapping.containsKey(swaggerType)) { type = this.__typeMapping.get(swaggerType); if (!this.needToImport(type)) { return type; } } else { type = swaggerType; } if (null == type) { Log.error('No Type defined for Property ' + p); } return this.toModelName(type); } toOperationId(operationId) { if (StringUtils_1.isEmpty(operationId)) { throw new Error('Empty method/operation name (operationId) not allowed'); } operationId = DefaultCodegen_1.default.camelize(this.sanitizeName(operationId), true); if (this.isReservedWord(operationId)) { const newOperationId = DefaultCodegen_1.default.camelize('call_' + operationId, true); Log.warn(operationId + ' (reserved word) cannot be used as method name. Renamed to ' + newOperationId); return newOperationId; } return operationId; } fromOperation(pp, httpMethod, operation, definitions, swagger) { if (arguments.length > 4) { const op = super.fromOperation(pp, httpMethod, operation, definitions, swagger); if (op.returnType != null) { op.returnType = this.normalizeType(op.returnType); } op.path = this.sanitizePath(op.path); let lastRequired = null; let lastOptional = null; for (const p of op.allParams) { if (p.required) { lastRequired = p; } else { lastOptional = p; } } for (const p of op.allParams) { if (p === lastRequired) { p._hasMoreRequired = false; } else if (p === lastOptional) { p._hasMoreOptional = false; } else { p._hasMoreRequired = true; p._hasMoreOptional = true; } } op._hasRequiredParams = lastRequired != null; return op; } return super.fromOperation(pp, httpMethod, operation, definitions); } fromModel(name, model, allDefinitions) { if (arguments.length > 2) { let codegenModel = super.fromModel(name, model, allDefinitions); if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) { const parentModel = allDefinitions.get(codegenModel.parentSchema); const parentCodegenModel = super.fromModel(codegenModel.parent, parentModel, allDefinitions); codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel); } if (model != null && model instanceof ArrayModel_1.default) { const am = model; if (am.getItems() != null) { codegenModel._isArray = true; codegenModel._itemType = this.getSwaggerType(am.getItems()); } } else if (model != null && model instanceof ModelImpl_1.default) { const mm = model; if (mm.getAdditionalProperties() != null) { codegenModel._isMap = true; codegenModel._itemType = this.getSwaggerType(mm.getAdditionalProperties()); } } return codegenModel; } else { return super.fromModel(name, model); } } sanitizePath(p) { return p.replace(new RegExp("'", 'g'), '%27'); } trimBrackets(s) { if (s != null) { const beginIdx = s[0] === '[' ? 1 : 0; let endIdx = s.length; if (s[endIdx - 1] === ']') { endIdx--; } return s.substring(beginIdx, endIdx); } return null; } getModelledType(dataType) { return ('module:' + (StringUtils_1.isEmpty(this.invokerPackage) ? '' : this.invokerPackage + '/') + (StringUtils_1.isEmpty(this.__modelPackage) ? '' : this.__modelPackage + '/') + dataType); } getJSDocType(cm, cp) { if (((cm != null && cm instanceof CodegenModel_1.default) || cm === null) && ((cp != null && cp instanceof CodegenProperty_1.default) || cp === null)) { if (cp.isContainer) { if (cp.containerType === 'array') { return 'Array.<' + this.getJSDocType(cm, cp.items) + '>'; } else if (cp.containerType === 'map') { return 'Object.<String, ' + this.getJSDocType(cm, cp.items) + '>'; } } let dataType = this.trimBrackets(cp.datatypeWithEnum); if (cp.isEnum) { dataType = cm.classname + '.' + dataType; } if (this.isModelledType(cp)) { dataType = this.getModelledType(dataType); } return dataType; } else if (((cm != null && cm instanceof CodegenParameter_1.default) || cm === null) && cp === undefined) { let dataType = this.trimBrackets(cm.dataType); if (this.isModelledType(cm)) { dataType = this.getModelledType(dataType); } if (cm.isListContainer) { return 'Array.<' + dataType + '>'; } else if (cm.isMapContainer) { return 'Object.<String, ' + dataType + '>'; } return dataType; } else if (((cm != null && cm instanceof CodegenOperation_1.default) || cm === null) && cp === undefined) { let returnType = this.trimBrackets(cm.returnType); if (returnType != null) { if (this.isModelledType(cm)) { returnType = this.getModelledType(returnType); } if (cm.isListContainer) { return 'Array.<' + returnType + '>'; } else if (cm.isMapContainer) { return 'Object.<String, ' + returnType + '>'; } } return returnType; } else { throw new Error('invalid overload'); } } isModelledType(cp) { if ((cp != null && cp instanceof CodegenProperty_1.default) || cp === null) { return (cp.isEnum || !this.__languageSpecificPrimitives.contains(cp.baseType == null ? cp.datatype : cp.baseType)); } else if ((cp != null && cp instanceof CodegenParameter_1.default) || cp === null) { return (cp.isEnum || !this.__languageSpecificPrimitives.contains(cp.baseType == null ? cp.dataType : cp.baseType)); } else if ((cp != null && cp instanceof CodegenOperation_1.default) || cp === null) { return !cp.returnTypeIsPrimitive; } throw new Error('invalid overload'); } postProcessOperations(objs) { const operations = objs.get('operations'); if (operations != null) { const ops = operations.get('operation'); for (const operation of ops) { const argList = []; let hasOptionalParams = false; for (const p of operation.allParams) { if (p.required) { let flowsify = p.paramName; const swaggerType = p.dataType; if (this._swaggerToFlowMapping.containsKey(swaggerType)) { flowsify += `: ${this._swaggerToFlowMapping.get(swaggerType)}`; } else { flowsify += ': any'; } argList.push(flowsify); } else { hasOptionalParams = true; } } if (hasOptionalParams) { argList.push('opts: any'); } if (!this.usePromises) { argList.push('callback: Function'); } operation._argList = argList.join(', '); for (const cp of operation.allParams) { cp._jsDocType = this.getJSDocType(cp); } operation.hasOptionalParams = hasOptionalParams; operation.hasParams = operation.allParams.length > 0; operation._jsDocType = this.getJSDocType(operation); } } javaUtil_1.Collections.sort(objs.get('imports'), (a, b) => { const a1 = a.get('import'); const b1 = b.get('import'); return a1.localeCompare(b1); }); return objs; } postProcessModels(objs) { objs = super.postProcessModelsEnum(objs); const models = objs.get('models'); for (const mo of models) { const cm = mo.get('model'); const required = []; const allRequired = this.supportsInheritance ? [] : required; cm._required = required; cm._allRequired = allRequired; for (const __var of cm.vars) { const jsDocType = this.getJSDocType(cm, __var); __var._jsDocType = jsDocType; if (__var.required) { required.push(__var); } } if (this.supportsInheritance) { for (const vars of cm.allVars) { if (vars.required) { allRequired.push(vars); } } } let lastRequired = null; for (const vars of cm.vars) { if (vars.required != null && vars.required) { lastRequired = vars; } } for (const vars of cm.vars) { if (vars === lastRequired) { vars._hasMoreRequired = false; } else if (vars.required != null && vars.required) { vars._hasMoreRequired = true; } } } return objs; } needToImport(type) { return (!this.__defaultIncludes.contains(type) && !this.__languageSpecificPrimitives.contains(type)); } staticsanitizePackageName(packageName) { packageName = packageName.trim(); packageName = packageName.replace(new RegExp('[^a-zA-Z0-9_\\.]', 'g'), '_'); if (StringUtils_1.isEmpty(packageName)) { return 'invalidPackageName'; } return packageName; } toEnumName(property) { return this.sanitizeName(DefaultCodegen_1.default.camelize(property.name)) + 'Enum'; } toEnumVarName(value, datatype) { return value; } toEnumValue(value, datatype) { if ('Integer' === datatype || 'Number' === datatype) { return value; } else { return '"' + this.escapeText(value) + '"'; } } escapeQuotationMark(input) { return (input && input .split('"') .join('') .split("'") .join('')); } escapeUnsafeCharacters(input) { return (input && input .split('*/') .join('*_/') .split('/*') .join('/_*')); } } JavascriptClientCodegen.PROJECT_NAME = 'projectName'; JavascriptClientCodegen.MODULE_NAME = 'moduleName'; JavascriptClientCodegen.PROJECT_DESCRIPTION = 'projectDescription'; JavascriptClientCodegen.PROJECT_VERSION = 'projectVersion'; JavascriptClientCodegen.PROJECT_LICENSE_NAME = 'projectLicenseName'; JavascriptClientCodegen.USE_PROMISES = 'usePromises'; JavascriptClientCodegen.USE_INHERITANCE = 'useInheritance'; JavascriptClientCodegen.EMIT_MODEL_METHODS = 'emitModelMethods'; JavascriptClientCodegen.EMIT_JS_DOC = 'emitJSDoc'; exports.default = JavascriptClientCodegen; const Log = LoggerFactory_1.default.getLogger(JavascriptClientCodegen); //# sourceMappingURL=JavascriptClientCodegen.js.map