UNPKG

ern-api-gen

Version:

Electrode Native API generator

831 lines 40.5 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 Mustache_1 = __importDefault(require("./java/Mustache")); const System_1 = __importDefault(require("./java/System")); const OAuth2Definition_1 = __importDefault(require("./models/auth/OAuth2Definition")); const Json_1 = __importDefault(require("./java/Json")); const ObjectUtils_1 = __importDefault(require("./java/ObjectUtils")); const StringUtils_1 = __importDefault(require("./java/StringUtils")); const StringBuilder_1 = __importDefault(require("./java/StringBuilder")); const LoggerFactory_1 = __importDefault(require("./java/LoggerFactory")); const File_1 = __importDefault(require("./java/File")); const javaUtil_1 = require("./java/javaUtil"); const IOUtils_1 = __importDefault(require("./java/IOUtils")); const AbstractGenerator_1 = __importDefault(require("./AbstractGenerator")); const CodegenConstants_1 = __importDefault(require("./CodegenConstants")); const InlineModelResolver_1 = __importDefault(require("./InlineModelResolver")); const GlobalSupportingFile_1 = __importDefault(require("./GlobalSupportingFile")); const CodegenIgnoreProcessor_1 = __importDefault(require("./ignore/CodegenIgnoreProcessor")); const TreeMap_1 = __importDefault(require("./java/TreeMap")); const path_1 = __importDefault(require("path")); const TemplateLocator_1 = require("./TemplateLocator"); const InheritanceTreeSorter_1 = require("./InheritanceTreeSorter"); const sortOperationId = (a, b) => a.operationId.localeCompare(b.operationId); const sortClassName = (a, b) => { const a1 = (a && a.get('classname')) || ''; const b1 = b && b.get('classname'); return a1.localeCompare(b1); }; const sortImports = (a, b) => a.get('import').localeCompare(b.get('import')); const sortModelName = (a, b) => { const a1 = (a && a.get('model')) || ''; const b1 = b && b.get('model'); const aclassname = a1 && a1.classname; const bclassname = b1 && b1.classname; if (aclassname) { return aclassname.localeCompare(bclassname); } if (!bclassname) { return 0; } return -1; }; const rethrow = (e, ...args) => { Log.trace(e); throw new Error(...args); }; class DefaultGenerator extends AbstractGenerator_1.default { static processMimeTypes(mimeTypeList, operation, source) { if (mimeTypeList != null && mimeTypeList.length) { const last = mimeTypeList.length - 1; const c = mimeTypeList.map((key, i) => javaUtil_1.newHashMap(['mediaType', key], ['hasMore', i !== last])); operation.put(source, c); operation.put(`has${StringUtils_1.default.upperFirst(source)}`, true); } } static generateParameterId(parameter) { return parameter.getName() + ':' + parameter.getIn(); } opts(opts) { this.__opts = opts; this.swagger = opts.getSwagger(); this.config = opts.getConfig(); this.ignoreProcessor = new CodegenIgnoreProcessor_1.default(this.config.getOutputDir()); this.config.additionalProperties().putAll(opts.getOpts().getProperties()); return this; } generate() { let generateApis = null; let generateModels = null; let generateSupportingFiles = null; let generateApiTests = null; let generateApiDocumentation = null; let generateModelTests = null; let generateModelDocumentation = null; let modelsToGenerate = null; let apisToGenerate = null; let supportingFilesToGenerate = null; if (System_1.default.getProperty('models') != null) { const modelNames = System_1.default.getProperty('models'); generateModels = true; if (!(modelNames.length === 0)) { modelsToGenerate = javaUtil_1.newHashSet(...modelNames.split(',')); } } if (System_1.default.getProperty('apis') != null) { const apiNames = System_1.default.getProperty('apis'); generateApis = true; if (!(apiNames.length === 0)) { apisToGenerate = javaUtil_1.newHashSet(...apiNames.split(',')); } } if (System_1.default.getProperty('supportingFiles') != null) { const supportingFiles = System_1.default.getProperty('supportingFiles'); generateSupportingFiles = true; if (!(supportingFiles.length === 0)) { supportingFilesToGenerate = javaUtil_1.newHashSet(...supportingFiles.split(',')); } } if (System_1.default.getProperty('modelTests') != null) { generateModelTests = Boolean(System_1.default.getProperty('modelTests')); } if (System_1.default.getProperty('modelDocs') != null) { generateModelDocumentation = Boolean(System_1.default.getProperty('modelDocs')); } if (System_1.default.getProperty('apiTests') != null) { generateApiTests = Boolean(System_1.default.getProperty('apiTests')); } if (System_1.default.getProperty('apiDocs') != null) { generateApiDocumentation = Boolean(System_1.default.getProperty('apiDocs')); } if (generateApis == null && generateModels == null && generateSupportingFiles == null) { generateApis = true; generateModels = true; generateSupportingFiles = true; } else { if (generateApis == null) { generateApis = false; } if (generateModels == null) { generateModels = false; } if (generateSupportingFiles == null) { generateSupportingFiles = false; } } if (generateModelTests == null) { generateModelTests = true; } if (generateModelDocumentation == null) { generateModelDocumentation = true; } if (generateApiTests == null) { generateApiTests = true; } if (generateApiDocumentation == null) { generateApiDocumentation = true; } this.config .additionalProperties() .put(CodegenConstants_1.default.GENERATE_API_TESTS, generateApiTests); this.config .additionalProperties() .put(CodegenConstants_1.default.GENERATE_MODEL_TESTS, generateModelTests); if (!generateApiTests && !generateModelTests) { this.config .additionalProperties() .put(CodegenConstants_1.default.EXCLUDE_TESTS, true); } if (this.swagger == null || this.config == null) { throw new Error('missing swagger input or config!'); } if (System_1.default.getProperty('debugSwagger') != null) { Json_1.default.prettyPrint(this.swagger); } const files = []; this.config.processOpts(); this.config.preprocessSwagger(this.swagger); this.config .additionalProperties() .put('generatedDate', new Date().toString()); this.config .additionalProperties() .put('generatorClass', this.config.constructor.name); if (this.swagger.getInfo() != null) { const info = this.swagger.getInfo(); if (info.getTitle() != null) { this.config .additionalProperties() .put('appName', this.config.escapeText(info.getTitle())); } if (info.getVersion() != null) { this.config .additionalProperties() .put('appVersion', this.config.escapeText(info.getVersion())); } if (StringUtils_1.default.isEmpty(info.getDescription())) { this.config .additionalProperties() .put('appDescription', 'No descripton provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)'); } else { this.config .additionalProperties() .put('appDescription', this.config.escapeText(info.getDescription())); } if (info.getContact() != null) { const contact = info.getContact(); this.config .additionalProperties() .put('infoUrl', this.config.escapeText(contact.getUrl())); if (contact.getEmail() != null) { this.config .additionalProperties() .put('infoEmail', this.config.escapeText(contact.getEmail())); } } if (info.getLicense() != null) { const license = info.getLicense(); if (license.getName() != null) { this.config .additionalProperties() .put('licenseInfo', this.config.escapeText(license.getName())); } if (license.getUrl() != null) { this.config .additionalProperties() .put('licenseUrl', this.config.escapeText(license.getUrl())); } } if (info.getVersion() != null) { this.config .additionalProperties() .put('version', this.config.escapeText(info.getVersion())); } if (info.getTermsOfService() != null) { this.config .additionalProperties() .put('termsOfService', this.config.escapeText(info.getTermsOfService())); } } if (this.swagger.getVendorExtensions() != null) { this.config.vendorExtensions().putAll(this.swagger.getVendorExtensions()); } const hostBuilder = StringBuilder_1.default(); let scheme; if (this.swagger.getSchemes() != null && this.swagger.getSchemes().length > 0) { scheme = this.config.escapeText(this.swagger.getSchemes()[0]); } else { scheme = 'https'; } scheme = this.config.escapeText(scheme); hostBuilder.append(scheme); hostBuilder.append('://'); if (this.swagger.getHost() != null) { hostBuilder.append(this.swagger.getHost()); } else { hostBuilder.append('localhost'); } if (this.swagger.getBasePath() != null) { hostBuilder.append(this.swagger.getBasePath()); } const contextPath = this.config.escapeText(this.swagger.getBasePath() == null ? '' : this.swagger.getBasePath()); const basePath = this.config.escapeText(hostBuilder.toString()); const basePathWithoutHost = this.config.escapeText(this.swagger.getBasePath()); const inlineModelResolver = new InlineModelResolver_1.default(); inlineModelResolver.flatten(this.swagger); const allOperations = []; const allModels = []; const definitions = this.swagger.getDefinitions(); if (definitions != null) { let modelKeys = definitions.keySet(); if (generateModels) { if (javaUtil_1.isNotEmptySet(modelsToGenerate)) { const updatedKeys = javaUtil_1.newHashSet(); for (const m of modelKeys) { if (modelsToGenerate.contains(m)) { updatedKeys.add(m); } } modelKeys = updatedKeys; } let allProcessedModels = new TreeMap_1.default(new InheritanceTreeSorter_1.InheritanceTreeSorter(this, definitions)); for (const name of modelKeys) { try { if (this.config.importMapping().containsKey(name)) { Log.info('Model ' + name + ' not imported due to import mapping'); continue; } const model = definitions.get(name); const models = this.processModels(this.config, javaUtil_1.newHashMap([name, model]), definitions); models.put('classname', this.config.toModelName(name)); models.putAll(this.config.additionalProperties()); allProcessedModels.set(name, models); } catch (e) { rethrow(e, "Could not process model '" + name + "'.Please make sure that your schema is correct!", e); } } allProcessedModels = this.config.postProcessAllModels(allProcessedModels); for (const [name, models] of allProcessedModels) { try { if (this.config.importMapping().containsKey(name)) { continue; } allModels.push(models.value.models[0]); for (const [templateName, suffix,] of this.config.modelTemplateFiles()) { const filename = this.config.modelFileFolder() + File_1.default.separator + this.config.toModelFilename(name) + suffix; if (!this.config.shouldOverwrite(filename)) { Log.info('Skipped overwriting ' + filename); continue; } const written = this.processTemplateToFile(models, templateName, filename); if (written != null) { files.push(written); } } if (generateModelTests) { for (const [templateName, suffix,] of this.config.modelTestTemplateFiles()) { const filename = this.config.modelTestFileFolder() + File_1.default.separator + this.config.toModelTestFilename(name) + suffix; if (new File_1.default(filename).exists()) { Log.info('File exists. Skipped overwriting ' + filename); continue; } const written = this.processTemplateToFile(models, templateName, filename); if (written != null) { files.push(written); } } } if (generateModelDocumentation) { for (const [templateName, suffix,] of this.config.modelDocTemplateFiles()) { const filename = this.config.modelDocFileFolder() + File_1.default.separator + this.config.toModelDocFilename(name) + suffix; if (!this.config.shouldOverwrite(filename)) { Log.info('Skipped overwriting ' + filename); continue; } const written = this.processTemplateToFile(models, templateName, filename); if (written != null) { files.push(written); } } } } catch (e) { rethrow(e, "Could not generate model '" + name + "'", e); } } } } if (System_1.default.getProperty('debugModels') != null) { Log.info('############ Model info ############'); Json_1.default.prettyPrint(allModels); } let paths = this.processPaths(this.swagger.getPaths()); if (generateApis) { if (javaUtil_1.isNotEmptySet(apisToGenerate)) { const updatedPaths = new TreeMap_1.default(); for (const [m, p] of paths) { if (apisToGenerate.contains(m)) { updatedPaths.set(m, p); } } paths = updatedPaths; } for (const [tag, ops] of paths) { try { ops.sort((one, another) => ObjectUtils_1.default.compare(one.operationId, another.operationId)); const operation = this.processOperations(this.config, tag, ops); operation.put('basePath', basePath); operation.put('basePathWithoutHost', basePathWithoutHost); operation.put('contextPath', contextPath); operation.put('baseName', tag); operation.put('modelPackage', this.config.modelPackage()); operation.putAll(this.config.additionalProperties()); operation.put('classname', this.config.toApiName(tag)); operation.put('classVarName', this.config.toApiVarName(tag)); operation.put('importPath', this.config.toApiImport(tag)); if (javaUtil_1.isNotEmptySet(this.config.vendorExtensions())) { operation.put('vendorExtensions', this.config.vendorExtensions()); } let sortParamsByRequiredFlag = true; if (this.config .additionalProperties() .containsKey(CodegenConstants_1.default.SORT_PARAMS_BY_REQUIRED_FLAG)) { sortParamsByRequiredFlag = Boolean(this.config .additionalProperties() .get(CodegenConstants_1.default.SORT_PARAMS_BY_REQUIRED_FLAG)); } operation.put('sortParamsByRequiredFlag', sortParamsByRequiredFlag); DefaultGenerator.processMimeTypes(this.swagger.getConsumes(), operation, 'consumes'); DefaultGenerator.processMimeTypes(this.swagger.getProduces(), operation, 'produces'); allOperations.push(operation); for (let i = 0; i < allOperations.length; i++) { const oo = allOperations[i]; if (i < allOperations.length - 1) { oo.put('hasMore', 'true'); } } for (const [templateName] of this.config.apiTemplateFiles()) { const filename = this.config.apiFilename(templateName, tag); if (!this.config.shouldOverwrite(filename) && new File_1.default(filename).exists()) { Log.info('Skipped overwriting ' + filename); continue; } if (this.config.shouldGenerateApiFor(templateName, operation)) { const written = this.processTemplateToFile(operation, templateName, filename); if (written != null) { files.push(written); } } } const requestDataObjects = operation.get('requestDataObjects'); if (requestDataObjects) { for (const requestDataObject of requestDataObjects) { for (const [templateName] of this.config.apiDataTemplateFile()) { const filename = this.config.apiDataFilename(templateName, requestDataObject.requestDataType); if (!this.config.shouldOverwrite(filename) && new File_1.default(filename).exists()) { Log.info('Skipped overwriting ' + filename); continue; } const written = this.processTemplateToFile(requestDataObject, templateName, filename); if (written != null) { files.push(written); } } } } if (generateApiTests) { for (const [templateName] of this.config.apiTestTemplateFiles()) { const filename = this.config.apiTestFilename(templateName, tag); if (new File_1.default(filename).exists()) { Log.info('File exists. Skipped overwriting ' + filename); continue; } const written = this.processTemplateToFile(operation, templateName, filename); if (written != null) { files.push(written); } } } if (generateApiDocumentation) { for (const [templateName] of this.config.apiDocTemplateFiles()) { const filename = path_1.default.normalize(this.config.apiDocFilename(templateName, tag)); if (!this.config.shouldOverwrite(filename) && new File_1.default(filename).exists()) { Log.info('Skipped overwriting ' + filename); continue; } const written = this.processTemplateToFile(operation, templateName, filename); if (written != null) { files.push(written); } } } } catch (e) { rethrow(e, "Could not generate api file for '" + tag + "'", e); } } } if (System_1.default.getProperty('debugOperations') != null) { Log.info('############ Operation info ############'); Json_1.default.prettyPrint(allOperations); } const bundle = javaUtil_1.newHashMap(); bundle.putAll(this.config.additionalProperties()); bundle.put('apiPackage', this.config.apiPackage()); if (this.swagger.getHost() != null) { bundle.put('host', this.swagger.getHost()); } bundle.put('swagger', this.swagger); bundle.put('basePath', basePath); bundle.put('basePathWithoutHost', basePathWithoutHost); bundle.put('scheme', scheme); bundle.put('contextPath', contextPath); // Sort to make stable. bundle.put('apiInfo', { apis: javaUtil_1.Collections.sort(allOperations, sortClassName), }); bundle.put('models', javaUtil_1.Collections.sort(allModels, sortModelName)); bundle.put('apiFolder', /* replace */ this.config .apiPackage() .split('.') .join(File_1.default.separatorChar)); bundle.put('modelPackage', this.config.modelPackage()); const authMethods = this.config.fromSecurity(this.swagger.getSecurityDefinitions()); if (javaUtil_1.isNotEmptySet(authMethods)) { bundle.put('authMethods', authMethods); bundle.put('hasAuthMethods', true); let authMethod; for (authMethod of authMethods) { authMethod.hasMore = true; } authMethod.hasMore = false; } if (this.swagger.getExternalDocs() != null) { bundle.put('externalDocs', this.swagger.getExternalDocs()); } for (let i = 0; i < allModels.length - 1; i++) { const cm = allModels[i]; const m = cm.get('model'); m.hasMoreModels = true; } this.config.postProcessSupportingFileData(bundle); if (System_1.default.getProperty('debugSupportingFiles') != null) { Log.info('############ Supporting file info ############'); Json_1.default.prettyPrint(bundle); } if (generateSupportingFiles) { for (const support of this.config.supportingFiles()) { try { let outputFolder = this.config.outputFolder(); if (StringUtils_1.default.isNotEmpty(support.folder)) { outputFolder += File_1.default.separator + support.folder; } const of = new File_1.default(outputFolder); if (!of.isDirectory()) { of.mkdirs(); } const outputFilename = outputFolder + File_1.default.separator + (support.destinationFilename || ''); if (!this.config.shouldOverwrite(outputFilename)) { Log.info('Skipped overwriting ' + outputFilename); continue; } let templateFile; if (support != null && support instanceof GlobalSupportingFile_1.default) { templateFile = this._resolveFile(this.config.getCommonTemplateDir(), support.templateFile || ''); } else { templateFile = this.getFullTemplateFile(this.config, support.templateFile); } if (templateFile == null) { Log.warn(`Could not resolve ${support.templateFile}`); continue; } let shouldGenerate = true; if (javaUtil_1.isNotEmptySet(supportingFilesToGenerate)) { if (supportingFilesToGenerate.contains(support.destinationFilename)) { shouldGenerate = true; } else { shouldGenerate = false; } } if (shouldGenerate) { if (this.ignoreProcessor.allowsFile(new File_1.default(outputFilename))) { if (templateFile == null) { Log.warn(`Could not resolve template file ${support.templateFile}`); } else if (templateFile.endsWith('.mustache')) { const template = this.readTemplate(templateFile); const tmpl = Mustache_1.default.compiler() .withLoader(new TemplateLocator_1.TemplateLocator(this)) .defaultValue('') .compile(template, templateFile); this.writeToFile(outputFilename, tmpl.execute(bundle)); files.push(new File_1.default(outputFilename)); } else { const input = new File_1.default(templateFile); const outputFile = new File_1.default(outputFilename); const out = new File_1.default(outputFile); Log.info('writing file ' + outputFile); IOUtils_1.default.copy(input, out); files.push(outputFile); } } else { Log.info('Skipped generation of ' + outputFilename + ' due to rule in .swagger-codegen-ignore'); } } } catch (e) { rethrow(e, "Could not generate supporting file '" + support + "'", e); } } if (this.config.addSwaggerIgnoreFile()) { const swaggerCodegenIgnore = '.swagger-codegen-ignore'; const ignoreFileNameTarget = this.config.outputFolder() + File_1.default.separator + swaggerCodegenIgnore; const ignoreFile = new File_1.default(ignoreFileNameTarget); if (!ignoreFile.exists()) { const ignoreFileNameSource = this._resolveFilePath(this.config.getCommonTemplateDir(), swaggerCodegenIgnore); const ignoreFileContents = this.readResourceContents(ignoreFileNameSource); try { this.writeToFile(ignoreFileNameTarget, ignoreFileContents); } catch (e) { rethrow(e, "Could not generate supporting file '" + swaggerCodegenIgnore + "'", e); } files.push(ignoreFile); } } if (this.config.addLicenseFile()) { const apache2License = 'LICENSE'; const licenseFileNameTarget = this.config.outputFolder() + File_1.default.separator + apache2License; const licenseFile = new File_1.default(licenseFileNameTarget); const licenseFileNameSource = File_1.default.separator + this.config.getCommonTemplateDir() + File_1.default.separator + apache2License; const licenseFileContents = this.readResourceContents(licenseFileNameSource); try { this.writeToFile(licenseFileNameTarget, licenseFileContents); } catch (e) { rethrow(e, "Could not generate LICENSE file '" + apache2License + "'", e); } files.push(licenseFile); } } this.config.processSwagger(this.swagger); return files; } processTemplateToFile(templateData, templateName, outputFilename) { if (this.ignoreProcessor.allowsFile(new File_1.default(outputFilename))) { const templateFile = this.getFullTemplateFile(this.config, templateName); const template = this.readTemplate(templateFile); const tmpl = Mustache_1.default.compiler() .withLoader(new TemplateLocator_1.TemplateLocator(this)) .defaultValue('') .compile(template, templateFile); this.writeToFile(outputFilename, tmpl.execute(templateData)); return new File_1.default(outputFilename); } Log.info('Skipped generation of ' + outputFilename + ' due to rule in .swagger-codegen-ignore'); return null; } processPaths(paths) { const ops = javaUtil_1.newHashMap(); for (const p of paths) { const resourcePath = p.path; this.processOperation(resourcePath, 'get', p.getGet(), ops); this.processOperation(resourcePath, 'head', p.getHead(), ops); this.processOperation(resourcePath, 'put', p.getPut(), ops); this.processOperation(resourcePath, 'post', p.getPost(), ops); this.processOperation(resourcePath, 'delete', p.getDelete(), ops); this.processOperation(resourcePath, 'patch', p.getPatch(), ops); this.processOperation(resourcePath, 'options', p.getOptions(), ops); this.processOperation(resourcePath, 'event', p.getEvent(), ops); } return ops; } fromSecurity(name) { const map = this.swagger.getSecurityDefinitions(); if (map == null) { return null; } return map.get(name); } processOperation(resourcePath, httpMethod, operation, operations) { if (operation == null) { return; } if (System_1.default.getProperty('debugOperations') != null) { Log.info('processOperation: resourcePath= ' + resourcePath + '\t;' + httpMethod + ' ' + operation + '\n'); } let tags = operation.getTags(); if (tags == null) { tags = []; tags.push('default'); } const operationParameters = javaUtil_1.newHashSet(); if (operation.getParameters() != null) { for (const parameter of operation.getParameters()) { operationParameters.add(DefaultGenerator.generateParameterId(parameter)); } for (const parameter of operation.getParameters()) { if (!operationParameters.contains(DefaultGenerator.generateParameterId(parameter))) { operation.addParameter(parameter); } } } for (const tag of tags) { let co = null; try { co = this.config.fromOperation(resourcePath, httpMethod, operation, this.swagger.getDefinitions(), this.swagger); co.tags = [this.config.sanitizeTag(tag)]; this.config.addOperationToGroup(this.config.sanitizeTag(tag), resourcePath, operation, co, operations); let securities = operation.getSecurity(); if (securities == null && this.swagger.getSecurity() != null) { securities = []; for (const sr of this.swagger.getSecurity()) { securities.push(sr.getRequirements()); } } if (!javaUtil_1.isNotEmptySet(securities)) { continue; } const authMethods = javaUtil_1.newHashMap(); for (const security of securities) { for (const securityName of Object.keys(security)) { const securityDefinition = this.fromSecurity(securityName); if (securityDefinition != null) { if (securityDefinition != null && securityDefinition instanceof OAuth2Definition_1.default) { const oauth2Definition = securityDefinition; const oauth2Operation = new OAuth2Definition_1.default(); oauth2Operation.setType(oauth2Definition.getType()); oauth2Operation.setAuthorizationUrl(oauth2Definition.getAuthorizationUrl()); oauth2Operation.setFlow(oauth2Definition.getFlow()); oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl()); oauth2Operation.setScopes(javaUtil_1.newHashMap()); for (const scope of security[securityName]) { if (scope in oauth2Definition.getScopes()) { oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope)); } } authMethods.put(securityName, securityDefinition); } else { authMethods.put(securityName, securityDefinition); } } } } if (javaUtil_1.isNotEmptySet(authMethods)) { co.authMethods = this.config.fromSecurity(authMethods); co.hasAuthMethods = true; } } catch (ex) { const msg = 'Could not process operation:\n Tag: ' + tag + '\n Operation: ' + operation.getOperationId() + '\n Resource: ' + httpMethod + ' ' + resourcePath + '\n Definitions: ' + this.swagger.getDefinitions() + '\n Exception: ' + ex.message; rethrow(ex, msg, ex); } } } processOperations(config, tag, ops) { let counter = 0; javaUtil_1.Collections.sort(ops, sortOperationId); const opIds = javaUtil_1.newHashSet(); for (const op of ops) { const opId = op.nickname; if (opIds.contains(opId)) { counter++; op.nickname += '_' + counter; } opIds.add(opId); } const allImports = javaUtil_1.newHashSet(); for (const op of ops) { allImports.addAll(op.imports); } const imports = []; for (const nextImport of allImports) { let mapping = config.importMapping().get(nextImport); if (mapping == null) { mapping = config.toModelImport(nextImport); } if (mapping != null) { imports.push(javaUtil_1.newHashMap(['import', mapping])); } } javaUtil_1.Collections.sort(imports, sortImports); const operations = javaUtil_1.newHashMap(['imports', imports], ['hasImport', imports.length > 0], [ 'operations', javaUtil_1.newHashMap(['classname', config.toApiName(tag)], ['pathPrefix', config.toApiVarName(tag)], ['operation', ops]), ], ['package', config.apiPackage()]); config.postProcessOperations(operations); // perhaps more where added? let lastOp; for ( /* const [TSCONV] */lastOp of operations .get('operations') .get('operation')) { lastOp.hasMore = true; } if (lastOp) { lastOp.hasMore = false; } return operations; } processModels(config, definitions, allDefinitions) { const models = []; const imports = []; const objs = javaUtil_1.newHashMap(['package', config.modelPackage()], ['models', models], ['imports', imports]); const allImports = javaUtil_1.newHashSet(); const importSet = javaUtil_1.newHashSet(); for (const [key, mm] of definitions) { const cm = config.fromModel(key, mm, allDefinitions); models.push(javaUtil_1.newHashMap(['model', cm], ['importPath', config.toModelImport(cm.classname)])); allImports.addAll(cm.imports); } for (const nextImport of allImports) { let mapping = config.importMapping().get(nextImport); if (mapping == null) { mapping = config.toModelImport(nextImport); } if (mapping != null && !config.defaultIncludes().contains(mapping)) { importSet.add(mapping); } mapping = config.instantiationTypes().get(nextImport); if (mapping != null && !config.defaultIncludes().contains(mapping)) { importSet.add(mapping); } } for (const s of importSet) { imports.push(javaUtil_1.newHashMap(['import', s])); } config.postProcessModels(objs); return objs; } } exports.default = DefaultGenerator; const Log = LoggerFactory_1.default.getLogger(DefaultGenerator); //# sourceMappingURL=DefaultGenerator.js.map