From c10301dc4d20114e3c1e2cf42f270609c994e413 Mon Sep 17 00:00:00 2001
From: Erik Timmers <e.timmers@gmail.com>
Date: Fri, 23 Nov 2018 21:50:05 +0100
Subject: [PATCH] [elm] Enable setting base path for each request

---
 docs/generators/elm.md                                    | 3 +++
 .../openapitools/codegen/languages/ElmClientCodegen.java  | 8 ++++++++
 .../openapi-generator/src/main/resources/elm/api.mustache | 6 ++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/generators/elm.md b/docs/generators/elm.md
index bab23d8acf6..4fcb79ad250 100644
--- a/docs/generators/elm.md
+++ b/docs/generators/elm.md
@@ -9,4 +9,7 @@ CONFIG OPTIONS for elm
 	elmPrefixCustomTypeVariants
 	    Prefix custom type variants (Default: false)
 
+	elmEnableCustomBasePaths
+	    Enable setting the base path for each request (Default: false)
+
 Back to the [generators list](README.md)
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java
index ed9c8040d55..fe1527c1f0d 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java
@@ -63,6 +63,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
 
     private static final String ELM_VERSION = "elmVersion";
     private static final String ELM_PREFIX_CUSTOM_TYPE_VARIANTS = "elmPrefixCustomTypeVariants";
+    private static final String ELM_ENABLE_CUSTOM_BASE_PATHS = "elmEnableCustomBasePaths";
     private static final String ENCODER = "elmEncoder";
     private static final String DECODER = "elmDecoder";
     private static final String DISCRIMINATOR_NAME = "discriminatorName";
@@ -166,6 +167,8 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
         cliOptions.add(elmVersion);
         final CliOption elmPrefixCustomTypeVariants = CliOption.newBoolean(ELM_PREFIX_CUSTOM_TYPE_VARIANTS, "Prefix custom type variants");
         cliOptions.add(elmPrefixCustomTypeVariants);
+        final CliOption elmEnableCustomBasePaths = CliOption.newBoolean(ELM_ENABLE_CUSTOM_BASE_PATHS, "Enable setting the base path for each request");
+        cliOptions.add(elmEnableCustomBasePaths);
     }
 
     @Override
@@ -185,6 +188,11 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
             elmPrefixCustomTypeVariants = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_PREFIX_CUSTOM_TYPE_VARIANTS).toString()));
         }
 
+        if (additionalProperties.containsKey(ELM_ENABLE_CUSTOM_BASE_PATHS)) {
+            final boolean enable = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_ENABLE_CUSTOM_BASE_PATHS).toString()));
+            additionalProperties.put("enableCustomBasePaths", enable);
+        }
+
         if (StringUtils.isEmpty(System.getenv("ELM_POST_PROCESS_FILE"))) {
             if (elmVersion.equals(ElmVersion.ELM_018)) { // 0.18
                 LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.18");
diff --git a/modules/openapi-generator/src/main/resources/elm/api.mustache b/modules/openapi-generator/src/main/resources/elm/api.mustache
index 63d1f780695..959eee34153 100644
--- a/modules/openapi-generator/src/main/resources/elm/api.mustache
+++ b/modules/openapi-generator/src/main/resources/elm/api.mustache
@@ -8,9 +8,10 @@ import Json.Decode as Decode
 import Url.Builder as Url
 
 
-basePath : String
+{{^enableCustomBasePaths}}basePath : String
 basePath =
     "{{basePath}}"
+{{/enableCustomBasePaths}}
 {{#operations}}
   {{#operation}}
 
@@ -21,6 +22,7 @@ basePath =
 {{/notes}}
 {{operationId}} :
     { onSend : Result Http.Error {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}} -> msg
+{{#enableCustomBasePaths}}    , basePath : String{{/enableCustomBasePaths}}
 {{#bodyParam}}    , body : {{^required}}Maybe {{/required}}{{dataType}}{{/bodyParam}}
 {{#pathParams}}    , {{paramName}} : {{#isListContainer}}List {{/isListContainer}}{{dataType}}{{/pathParams}}
 {{#queryParams}}    , {{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{dataType}}{{^required}}){{/required}}{{/queryParams}}
@@ -30,7 +32,7 @@ basePath =
     Http.request
         { method = "{{httpMethod}}"
         , headers = []
-        , url = Url.crossOrigin basePath
+        , url = Url.crossOrigin {{#enableCustomBasePaths}}params.{{/enableCustomBasePaths}}basePath
             [{{{path}}}]
             (List.filterMap identity [{{{vendorExtensions.query}}}])
         , body = {{#bodyParam}}{{^required}}Maybe.withDefault Http.emptyBody <| Maybe.map ({{/required}}Http.jsonBody {{#required}}<|{{/required}}{{^required}}<<{{/required}} {{vendorExtensions.elmEncoder}}{{^required}}){{/required}} params.body{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}}
-- 
GitLab