diff --git a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java index 201f605fa535..552a44f25630 100644 --- a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java +++ b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java @@ -17,19 +17,8 @@ package org.openapitools.codegen.plugin; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvp; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvp; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvp; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsv; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvp; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvp; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvpList; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvpList; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsvList; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvpList; -import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvpList; import static org.apache.commons.lang3.StringUtils.isNotEmpty; +import static org.openapitools.codegen.config.CodegenConfiguratorUtils.*; import java.io.File; import java.util.HashMap; @@ -289,6 +278,12 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name = "additionalProperties", property = "openapi.generator.maven.plugin.additionalProperties") private List additionalProperties; + /** + * A map of server variable overrides for specs that support server URL templating + */ + @Parameter(name = "serverVariableOverrides", property = "openapi.generator.maven.plugin.serverVariableOverrides") + private List serverVariableOverrides; + /** * A map of reserved names and how they should be escaped */ @@ -615,6 +610,10 @@ public void execute() throws MojoExecutionException { configurator); } + if (serverVariableOverrides == null && configOptions.containsKey("server-variables")) { + applyServerVariablesKvp(configOptions.get("server-variables").toString(), configurator); + } + // Retained for backwards-compataibility with configOptions -> reserved-words-mappings if (reservedWordsMappings == null && configOptions.containsKey("reserved-words-mappings")) { applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings") @@ -648,6 +647,10 @@ public void execute() throws MojoExecutionException { applyAdditionalPropertiesKvpList(additionalProperties, configurator); } + if (serverVariableOverrides != null && (configOptions == null || !configOptions.containsKey("server-variables"))) { + applyServerVariablesKvpList(serverVariableOverrides, configurator); + } + // Apply Reserved Words Mappings if (reservedWordsMappings != null && (configOptions == null || !configOptions.containsKey("reserved-words-mappings"))) { applyReservedWordsMappingsKvpList(reservedWordsMappings, configurator); @@ -698,10 +701,10 @@ public void execute() throws MojoExecutionException { // Store a checksum of the input spec File storedInputSpecHashFile = getHashFile(inputSpecFile); ByteSource inputSpecByteSource = - inputSpecFile.exists() - ? Files.asByteSource(inputSpecFile) - : CharSource.wrap(ClasspathHelper.loadFileFromClasspath(inputSpecFile.toString().replaceAll("\\\\","/"))) - .asByteSource(Charsets.UTF_8); + inputSpecFile.exists() + ? Files.asByteSource(inputSpecFile) + : CharSource.wrap(ClasspathHelper.loadFileFromClasspath(inputSpecFile.toString().replaceAll("\\\\","/"))) + .asByteSource(Charsets.UTF_8); String inputSpecHash =inputSpecByteSource.hash(Hashing.sha256()).toString(); if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {