[elm] Enable setting base path for each request (#1538)

This commit is contained in:
Erik Timmers
2018-12-04 11:36:55 +01:00
committed by William Cheng
parent dfa7e616c0
commit d75392e056
3 changed files with 15 additions and 2 deletions
+3
View File
@@ -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)
@@ -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";
@@ -168,6 +169,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
@@ -187,6 +190,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");
@@ -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}}