Skip to content

Commit

Permalink
[haskell-http-client] add cli option customTestInstanceModule (#2406)
Browse files Browse the repository at this point in the history
setting `customTestInstanceModule` will import typeclasses from the
specified module into tests/Instances.hs, to provide typeclass
instances for types not known by the generator

this property set using `--additional-properties`

example:
```
--additional-properties=customTestInstanceModule=CustomInstances
```
  • Loading branch information
jonschoning committed Mar 15, 2019
1 parent 5ba35ec commit c9737cf
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/generators/haskell-http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ sidebar_label: haskell-http-client
|useKatip|Sets the default value for the UseKatip cabal flag. If true, the katip package provides logging instead of monad-logger| |true|
|dateTimeFormat|format string used to parse/render a datetime| |null|
|dateFormat|format string used to parse/render a date| |%Y-%m-%d|
|customTestInstanceModule|test module used to provide typeclass instances for types not known by the generator| |null|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
public static final String PROP_CABAL_VERSION = "cabalVersion";
public static final String PROP_CONFIG_TYPE = "configType";
public static final String PROP_DATETIME_FORMAT = "dateTimeFormat";
public static final String PROP_CUSTOM_TEST_INSTANCE_MODULE = "customTestInstanceModule";
public static final String PROP_DATE_FORMAT = "dateFormat";
public static final String PROP_GENERATE_ENUMS = "generateEnums";
public static final String PROP_GENERATE_FORM_URLENCODED_INSTANCES = "generateFormUrlEncodedInstances";
Expand Down Expand Up @@ -270,6 +271,8 @@ public HaskellHttpClientCodegen() {
cliOptions.add(CliOption.newString(PROP_DATETIME_FORMAT, "format string used to parse/render a datetime"));
cliOptions.add(CliOption.newString(PROP_DATE_FORMAT, "format string used to parse/render a date").defaultValue(defaultDateFormat));

cliOptions.add(CliOption.newString(PROP_CUSTOM_TEST_INSTANCE_MODULE, "test module used to provide typeclass instances for types not known by the generator"));

cliOptions.add(CliOption.newBoolean(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC).defaultValue(Boolean.TRUE.toString()));

}
Expand Down Expand Up @@ -320,9 +323,7 @@ public void setDateTimeFormat(String value) {
setStringProp(PROP_DATETIME_FORMAT, value);
}

public void setDateFormat(String value) {
setStringProp(PROP_DATE_FORMAT, value);
}
public void setDateFormat(String value) { setStringProp(PROP_DATE_FORMAT, value); }

public void setCabalPackage(String value) {
setStringProp(PROP_CABAL_PACKAGE, value);
Expand Down Expand Up @@ -353,6 +354,8 @@ public void setUseKatip(Boolean value) {
this.useKatip = value;
}

public void setCustomTestInstanceModule(String value) { setStringProp(PROP_CUSTOM_TEST_INSTANCE_MODULE, value); }

private void setStringProp(String key, String value) {
if (StringUtils.isBlank(value)) {
additionalProperties.remove(key);
Expand Down Expand Up @@ -467,6 +470,9 @@ public void processOpts() {
if (additionalProperties.containsKey(PROP_CONFIG_TYPE)) {
setConfigType(additionalProperties.get(PROP_CONFIG_TYPE).toString());
}
if (additionalProperties.containsKey(PROP_CUSTOM_TEST_INSTANCE_MODULE)) {
setCustomTestInstanceModule(additionalProperties.get(PROP_CUSTOM_TEST_INSTANCE_MODULE).toString());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ These options allow some customization of the code generation process.
| baseModule | Set the base module namespace | | {{{baseModule}}} |
| cabalPackage | Set the cabal package name, which consists of one or more alphanumeric words separated by hyphens | | {{{cabalPackage}}} |
| cabalVersion | Set the cabal version number, consisting of a sequence of one or more integers separated by dots | 0.1.0.0 | {{{cabalVersion}}} |
| customTestInstanceModule | test module used to provide typeclass instances for types not known by the generator | | {{{customTestInstanceModule}}} |
| configType | Set the name of the type used for configuration | | {{{configType}}} |
| dateFormat | format string used to parse/render a date | %Y-%m-%d | {{{dateFormat}}} |
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | {{{dateTimeFormat}}} |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ test-suite tests
other-modules:
ApproxEq
Instances
PropMime
PropMime{{#customTestInstanceModule}}
{{.}}{{/customTestInstanceModule}}
default-language: Haskell2010
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Instances where

import {{baseModule}}.Model
import {{baseModule}}.Core
import {{baseModule}}.Core{{#customTestInstanceModule}}
import {{.}} (){{/customTestInstanceModule}}

import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as BL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Test.Hspec
import Test.Hspec.QuickCheck

import PropMime
import Instances ()
import Instances (){{#customTestInstanceModule}}
import {{.}} (){{/customTestInstanceModule}}

import {{baseModule}}.Model
import {{baseModule}}.MimeTypes
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/haskell-http-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ These options allow some customization of the code generation process.
| baseModule | Set the base module namespace | | OpenAPIPetstore |
| cabalPackage | Set the cabal package name, which consists of one or more alphanumeric words separated by hyphens | | openapi-petstore |
| cabalVersion | Set the cabal version number, consisting of a sequence of one or more integers separated by dots | 0.1.0.0 | 0.1.0.0 |
| customTestInstanceModule | test module used to provide typeclass instances for types not known by the generator | | |
| configType | Set the name of the type used for configuration | | OpenAPIPetstoreConfig |
| dateFormat | format string used to parse/render a date | %Y-%m-%d | %Y-%m-%d |
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | |
Expand Down

0 comments on commit c9737cf

Please sign in to comment.