From 0cef8e5d0eb1f8ce6851e7736951cc24c8ef6f67 Mon Sep 17 00:00:00 2001 From: Jon Schoning <jonschoning@gmail.com> Date: Thu, 14 Mar 2019 12:42:42 -0500 Subject: [PATCH] [haskell-http-client] add cli option `customTestInstanceModule` 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 ``` --- docs/generators/haskell-http-client.md | 1 + .../codegen/languages/HaskellHttpClientCodegen.java | 12 +++++++++--- .../resources/haskell-http-client/README.mustache | 1 + .../haskell-http-client.cabal.mustache | 3 ++- .../haskell-http-client/tests/Instances.mustache | 3 ++- .../haskell-http-client/tests/Test.mustache | 3 ++- .../client/petstore/haskell-http-client/README.md | 1 + 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/generators/haskell-http-client.md b/docs/generators/haskell-http-client.md index fc8b5647ad1..6dffd55f255 100644 --- a/docs/generators/haskell-http-client.md +++ b/docs/generators/haskell-http-client.md @@ -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| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java index f5f137261d6..2b225223af0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java @@ -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"; @@ -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_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())); } @@ -320,9 +323,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC 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); @@ -353,6 +354,8 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC 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); @@ -467,6 +470,9 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC 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 diff --git a/modules/openapi-generator/src/main/resources/haskell-http-client/README.mustache b/modules/openapi-generator/src/main/resources/haskell-http-client/README.mustache index 620eeff6da5..1e403bc86bd 100644 --- a/modules/openapi-generator/src/main/resources/haskell-http-client/README.mustache +++ b/modules/openapi-generator/src/main/resources/haskell-http-client/README.mustache @@ -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}}} | diff --git a/modules/openapi-generator/src/main/resources/haskell-http-client/haskell-http-client.cabal.mustache b/modules/openapi-generator/src/main/resources/haskell-http-client/haskell-http-client.cabal.mustache index 379b377c42d..981cdc6ac28 100644 --- a/modules/openapi-generator/src/main/resources/haskell-http-client/haskell-http-client.cabal.mustache +++ b/modules/openapi-generator/src/main/resources/haskell-http-client/haskell-http-client.cabal.mustache @@ -113,5 +113,6 @@ test-suite tests other-modules: ApproxEq Instances - PropMime + PropMime{{#customTestInstanceModule}} + {{.}}{{/customTestInstanceModule}} default-language: Haskell2010 diff --git a/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Instances.mustache b/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Instances.mustache index 7ee2d27d983..492212070ad 100644 --- a/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Instances.mustache +++ b/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Instances.mustache @@ -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 diff --git a/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Test.mustache b/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Test.mustache index 7cf4adb9a65..733cfb841b5 100644 --- a/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Test.mustache +++ b/modules/openapi-generator/src/main/resources/haskell-http-client/tests/Test.mustache @@ -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 diff --git a/samples/client/petstore/haskell-http-client/README.md b/samples/client/petstore/haskell-http-client/README.md index 74308f09346..49b68e11b7e 100644 --- a/samples/client/petstore/haskell-http-client/README.md +++ b/samples/client/petstore/haskell-http-client/README.md @@ -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) | | | -- GitLab