All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.codegen.config.CodegenConfiguratorUtils Maven / Gradle / Ivy

The newest version!
package io.swagger.codegen.config;

import io.swagger.codegen.utils.OptionUtils;
import org.apache.commons.lang3.tuple.Pair;

import java.util.*;

/**
 * Contains shared logic for applying key-value pairs and CSV strings
 * to specific settings in CodegenConfigurator.
 *
 * 

* This class exists to facilitate testing. These methods could be applied * to CodegenConfigurator, but this complicates things when mocking CodegenConfigurator. *

*/ public final class CodegenConfiguratorUtils { public static void applySystemPropertiesKvp(String systemProperties, CodegenConfigurator configurator) { final Map map = createMapFromKeyValuePairs(systemProperties); for (Map.Entry entry : map.entrySet()) { configurator.addSystemProperty(entry.getKey(), entry.getValue()); } } public static void applyInstantiationTypesKvp(String instantiationTypes, CodegenConfigurator configurator) { final Map map = createMapFromKeyValuePairs(instantiationTypes); for (Map.Entry entry : map.entrySet()) { configurator.addInstantiationType(entry.getKey(), entry.getValue()); } } public static void applyImportMappingsKvp(String importMappings, CodegenConfigurator configurator) { final Map map = createMapFromKeyValuePairs(importMappings); for (Map.Entry entry : map.entrySet()) { configurator.addImportMapping(entry.getKey(), entry.getValue()); } } public static void applyTypeMappingsKvp(String typeMappings, CodegenConfigurator configurator) { final Map map = createMapFromKeyValuePairs(typeMappings); for (Map.Entry entry : map.entrySet()) { configurator.addTypeMapping(entry.getKey(), entry.getValue()); } } public static void applyAdditionalPropertiesKvp(String additionalProperties, CodegenConfigurator configurator) { final Map map = createMapFromKeyValuePairs(additionalProperties); for (Map.Entry entry : map.entrySet()) { configurator.addAdditionalProperty(entry.getKey(), entry.getValue()); } } public static void applyLanguageSpecificPrimitivesCsv(String languageSpecificPrimitives, CodegenConfigurator configurator) { final Set set = createSetFromCsvList(languageSpecificPrimitives); for (String item : set) { configurator.addLanguageSpecificPrimitive(item); } } private static Set createSetFromCsvList(String csvProperty) { final List values = OptionUtils.splitCommaSeparatedList(csvProperty); return new HashSet(values); } private static Map createMapFromKeyValuePairs(String commaSeparatedKVPairs) { final List> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs); Map result = new HashMap(); for (Pair pair : pairs) { result.put(pair.getLeft(), pair.getRight()); } return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy