Skip to content

Commit

Permalink
[elm] Enable setting Http request trackers (OpenAPITools#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktim authored and wing328 committed Dec 6, 2018
1 parent 9e3a2c2 commit 55b9e4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/generators/elm.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ CONFIG OPTIONS for elm
elmEnableCustomBasePaths
Enable setting the base path for each request (Default: false)

elmEnableHttpRequestTrackers
Enable adding a tracker to each http request (Default: false)

Back to the [generators list](README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 ELM_ENABLE_HTTP_REQUEST_TRACKERS = "elmEnableHttpRequestTrackers";
private static final String ENCODER = "elmEncoder";
private static final String DECODER = "elmDecoder";
private static final String DISCRIMINATOR_NAME = "discriminatorName";
Expand Down Expand Up @@ -172,6 +173,8 @@ public ElmClientCodegen() {
cliOptions.add(elmPrefixCustomTypeVariants);
final CliOption elmEnableCustomBasePaths = CliOption.newBoolean(ELM_ENABLE_CUSTOM_BASE_PATHS, "Enable setting the base path for each request");
cliOptions.add(elmEnableCustomBasePaths);
final CliOption elmEnableHttpRequestTrackers = CliOption.newBoolean(ELM_ENABLE_HTTP_REQUEST_TRACKERS, "Enable adding a tracker to each http request");
cliOptions.add(elmEnableHttpRequestTrackers);
}

@Override
Expand All @@ -196,6 +199,11 @@ public void processOpts() {
additionalProperties.put("enableCustomBasePaths", enable);
}

if (additionalProperties.containsKey(ELM_ENABLE_HTTP_REQUEST_TRACKERS)) {
final boolean enable = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_ENABLE_HTTP_REQUEST_TRACKERS).toString()));
additionalProperties.put("enableHttpRequestTrackers", 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ basePath =
{{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}}
{{#enableHttpRequestTrackers}} , tracker : Maybe String{{/enableHttpRequestTrackers}}
{{#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}}
Expand All @@ -38,7 +39,7 @@ basePath =
, 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}}
, expect = {{^responses}}Http.expectWhatever params.onSend{{/responses}}{{#responses}}{{#-first}}{{^dataType}}Http.expectWhatever params.onSend{{/dataType}}{{#dataType}}Http.expectJson params.onSend {{#isMapContainer}}(Decode.dict {{/isMapContainer}}{{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{elmDecoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/dataType}}{{/-first}}{{/responses}}
, timeout = Just 30000
, tracker = Nothing
, tracker = {{#enableHttpRequestTrackers}}params.tracker{{/enableHttpRequestTrackers}}{{^enableHttpRequestTrackers}}Nothing{{/enableHttpRequestTrackers}}
}
{{/operation}}
{{/operations}}

0 comments on commit 55b9e4d

Please sign in to comment.