From 97ca4a836687af0198695199e8c241c181dc3dab Mon Sep 17 00:00:00 2001 From: Jon Schoning Date: Wed, 2 Oct 2019 22:52:26 -0500 Subject: [PATCH] [haskell-http-client] add dateTimeParseFormat cli option - overrides the format string used to parse a datetime --- docs/generators/haskell-http-client.md | 1 + .../languages/HaskellHttpClientCodegen.java | 14 +++++++++++--- .../resources/haskell-http-client/Core.mustache | 6 +++--- .../resources/haskell-http-client/README.mustache | 1 + .../client/petstore/haskell-http-client/README.md | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/generators/haskell-http-client.md b/docs/generators/haskell-http-client.md index 6dffd55f255d..b26bd8be10eb 100644 --- a/docs/generators/haskell-http-client.md +++ b/docs/generators/haskell-http-client.md @@ -28,6 +28,7 @@ sidebar_label: haskell-http-client |strictFields|Add strictness annotations to all model fields| |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| +|dateTimeParseFormat|overrides the format string used to parse 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 b3bce02f8f9d..35195ca1dc69 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_DATETIME_PARSE_FORMAT = "dateTimeParseFormat"; 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"; @@ -271,6 +272,7 @@ public HaskellHttpClientCodegen() { cliOptions.add(CliOption.newBoolean(PROP_USE_KATIP, "Sets the default value for the UseKatip cabal flag. If true, the katip package provides logging instead of monad-logger").defaultValue((Boolean.TRUE.toString()))); cliOptions.add(CliOption.newString(PROP_DATETIME_FORMAT, "format string used to parse/render a datetime")); + cliOptions.add(CliOption.newString(PROP_DATETIME_PARSE_FORMAT, "overrides the format string used to parse 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")); @@ -321,9 +323,9 @@ public void setModelDeriving(String value) { } } - public void setDateTimeFormat(String value) { - setStringProp(PROP_DATETIME_FORMAT, value); - } + public void setDateTimeFormat(String value) { setStringProp(PROP_DATETIME_FORMAT, value); } + + public void setDateTimeParseFormat(String value) { setStringProp(PROP_DATETIME_PARSE_FORMAT, value); } public void setDateFormat(String value) { setStringProp(PROP_DATE_FORMAT, value); } @@ -438,6 +440,12 @@ public void processOpts() { setDateTimeFormat(null); // default should be null } + if (additionalProperties.containsKey(PROP_DATETIME_PARSE_FORMAT)) { + setDateTimeParseFormat(additionalProperties.get(PROP_DATETIME_PARSE_FORMAT).toString()); + } else { + setDateTimeParseFormat(null); // default should be null + } + if (additionalProperties.containsKey(PROP_DATE_FORMAT)) { setDateFormat(additionalProperties.get(PROP_DATE_FORMAT).toString()); } else { diff --git a/modules/openapi-generator/src/main/resources/haskell-http-client/Core.mustache b/modules/openapi-generator/src/main/resources/haskell-http-client/Core.mustache index b313d73d480b..65ea95b6b5fa 100644 --- a/modules/openapi-generator/src/main/resources/haskell-http-client/Core.mustache +++ b/modules/openapi-generator/src/main/resources/haskell-http-client/Core.mustache @@ -425,16 +425,16 @@ instance P.Show DateTime where instance MimeRender MimeMultipartFormData DateTime where mimeRender _ = mimeRenderDefaultMultipartFormData --- | @{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}@ +-- | @{{#dateTimeParseFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeParseFormat}}}"{{/dateTimeParseFormat}}{{^dateTimeParseFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{/dateTimeParseFormat}}@ _readDateTime :: (TI.ParseTime t, Monad m{{^dateTimeFormat}}, Alternative m{{/dateTimeFormat}}) => String -> m t _readDateTime = - {{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}} + {{#dateTimeParseFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeParseFormat}}}"{{/dateTimeParseFormat}}{{^dateTimeParseFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{/dateTimeParseFormat}} {-# INLINE _readDateTime #-} -- | @{{^dateTimeFormat}}TI.formatISO8601Millis{{/dateTimeFormat}}{{#dateTimeFormat}}TI.formatTime TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}@ _showDateTime :: ({{^dateTimeFormat}}t ~ TI.UTCTime, {{/dateTimeFormat}}TI.FormatTime t) => t -> String _showDateTime = - {{^dateTimeFormat}}TI.formatISO8601Millis{{/dateTimeFormat}}{{#dateTimeFormat}}TI.formatTime TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}} + {{#dateTimeFormat}}TI.formatTime TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}{{^dateTimeFormat}}TI.formatISO8601Millis{{/dateTimeFormat}} {-# INLINE _showDateTime #-} -- | parse an ISO8601 date-time string 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 1e403bc86bd2..1ccf6cc45896 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 @@ -66,6 +66,7 @@ These options allow some customization of the code generation process. | 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}}} | +| dateTimeParseFormat | overrides the format string used to parse a datetime | | {{{dateTimeParseFormat}}} | | generateEnums | Generate specific datatypes for OpenAPI enums | true | {{{generateEnums}}} | | generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | {{{generateFormUrlEncodedInstances}}} | | generateLenses | Generate Lens optics for Models | true | {{{generateLenses}}} | diff --git a/samples/client/petstore/haskell-http-client/README.md b/samples/client/petstore/haskell-http-client/README.md index 49b68e11b7ec..a322bacdfba8 100644 --- a/samples/client/petstore/haskell-http-client/README.md +++ b/samples/client/petstore/haskell-http-client/README.md @@ -66,6 +66,7 @@ These options allow some customization of the code generation process. | 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) | | | +| dateTimeParseFormat | overrides the format string used to parse a datetime | | | | generateEnums | Generate specific datatypes for OpenAPI enums | true | true | | generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | true | | generateLenses | Generate Lens optics for Models | true | true |