[haskell-http-client] add cli option customTestInstanceModule (#2406)

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
```
This commit is contained in:
Jon Schoning
2019-03-15 07:34:46 -05:00
committed by GitHub
parent 5ba35ecd31
commit c9737cf97d
7 changed files with 18 additions and 6 deletions

View File

@@ -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| |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| |dateTimeFormat|format string used to parse/render a datetime| |null|
|dateFormat|format string used to parse/render a date| |%Y-%m-%d| |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| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|

View File

@@ -63,6 +63,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
public static final String PROP_CABAL_VERSION = "cabalVersion"; public static final String PROP_CABAL_VERSION = "cabalVersion";
public static final String PROP_CONFIG_TYPE = "configType"; public static final String PROP_CONFIG_TYPE = "configType";
public static final String PROP_DATETIME_FORMAT = "dateTimeFormat"; 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_DATE_FORMAT = "dateFormat";
public static final String PROP_GENERATE_ENUMS = "generateEnums"; public static final String PROP_GENERATE_ENUMS = "generateEnums";
public static final String PROP_GENERATE_FORM_URLENCODED_INSTANCES = "generateFormUrlEncodedInstances"; public static final String PROP_GENERATE_FORM_URLENCODED_INSTANCES = "generateFormUrlEncodedInstances";
@@ -270,6 +271,8 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
cliOptions.add(CliOption.newString(PROP_DATETIME_FORMAT, "format string used to parse/render a datetime")); 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_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())); cliOptions.add(CliOption.newBoolean(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC).defaultValue(Boolean.TRUE.toString()));
} }
@@ -320,9 +323,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
setStringProp(PROP_DATETIME_FORMAT, value); setStringProp(PROP_DATETIME_FORMAT, value);
} }
public void setDateFormat(String value) { public void setDateFormat(String value) { setStringProp(PROP_DATE_FORMAT, value); }
setStringProp(PROP_DATE_FORMAT, value);
}
public void setCabalPackage(String value) { public void setCabalPackage(String value) {
setStringProp(PROP_CABAL_PACKAGE, value); setStringProp(PROP_CABAL_PACKAGE, value);
@@ -353,6 +354,8 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
this.useKatip = value; this.useKatip = value;
} }
public void setCustomTestInstanceModule(String value) { setStringProp(PROP_CUSTOM_TEST_INSTANCE_MODULE, value); }
private void setStringProp(String key, String value) { private void setStringProp(String key, String value) {
if (StringUtils.isBlank(value)) { if (StringUtils.isBlank(value)) {
additionalProperties.remove(key); additionalProperties.remove(key);
@@ -467,6 +470,9 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
if (additionalProperties.containsKey(PROP_CONFIG_TYPE)) { if (additionalProperties.containsKey(PROP_CONFIG_TYPE)) {
setConfigType(additionalProperties.get(PROP_CONFIG_TYPE).toString()); 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 @Override

View File

@@ -62,6 +62,7 @@ These options allow some customization of the code generation process.
| baseModule | Set the base module namespace | | {{{baseModule}}} | | 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}}} | | 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}}} | | 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}}} | | configType | Set the name of the type used for configuration | | {{{configType}}} |
| dateFormat | format string used to parse/render a date | %Y-%m-%d | {{{dateFormat}}} | | 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}}} | | dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | {{{dateTimeFormat}}} |

View File

@@ -113,5 +113,6 @@ test-suite tests
other-modules: other-modules:
ApproxEq ApproxEq
Instances Instances
PropMime PropMime{{#customTestInstanceModule}}
{{.}}{{/customTestInstanceModule}}
default-language: Haskell2010 default-language: Haskell2010

View File

@@ -3,7 +3,8 @@
module Instances where module Instances where
import {{baseModule}}.Model import {{baseModule}}.Model
import {{baseModule}}.Core import {{baseModule}}.Core{{#customTestInstanceModule}}
import {{.}} (){{/customTestInstanceModule}}
import qualified Data.Aeson as A import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy as BL

View File

@@ -10,7 +10,8 @@ import Test.Hspec
import Test.Hspec.QuickCheck import Test.Hspec.QuickCheck
import PropMime import PropMime
import Instances () import Instances (){{#customTestInstanceModule}}
import {{.}} (){{/customTestInstanceModule}}
import {{baseModule}}.Model import {{baseModule}}.Model
import {{baseModule}}.MimeTypes import {{baseModule}}.MimeTypes

View File

@@ -62,6 +62,7 @@ These options allow some customization of the code generation process.
| baseModule | Set the base module namespace | | OpenAPIPetstore | | 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 | | 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 | | 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 | | 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 | | 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) | | | | dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | |