Skip to content

Commit cc1bfe5

Browse files
authored
[haskell-http-client] add dateTimeParseFormat cli option - overrides the format string used to parse a datetime (#4037)
This allows specifying a different formatString for parsing than for rendering, which is useful because padding widths are not supported in `parseTimeMSource`
1 parent 0ebc2f7 commit cc1bfe5

5 files changed

Lines changed: 17 additions & 6 deletions

File tree

docs/generators/haskell-http-client.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ sidebar_label: haskell-http-client
2828
|strictFields|Add strictness annotations to all model fields| |true|
2929
|useKatip|Sets the default value for the UseKatip cabal flag. If true, the katip package provides logging instead of monad-logger| |true|
3030
|dateTimeFormat|format string used to parse/render a datetime| |null|
31+
|dateTimeParseFormat|overrides the format string used to parse a datetime| |null|
3132
|dateFormat|format string used to parse/render a date| |%Y-%m-%d|
3233
|customTestInstanceModule|test module used to provide typeclass instances for types not known by the generator| |null|
3334
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
6363
public static final String PROP_CABAL_VERSION = "cabalVersion";
6464
public static final String PROP_CONFIG_TYPE = "configType";
6565
public static final String PROP_DATETIME_FORMAT = "dateTimeFormat";
66+
public static final String PROP_DATETIME_PARSE_FORMAT = "dateTimeParseFormat";
6667
public static final String PROP_CUSTOM_TEST_INSTANCE_MODULE = "customTestInstanceModule";
6768
public static final String PROP_DATE_FORMAT = "dateFormat";
6869
public static final String PROP_GENERATE_ENUMS = "generateEnums";
@@ -271,6 +272,7 @@ public HaskellHttpClientCodegen() {
271272
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())));
272273

273274
cliOptions.add(CliOption.newString(PROP_DATETIME_FORMAT, "format string used to parse/render a datetime"));
275+
cliOptions.add(CliOption.newString(PROP_DATETIME_PARSE_FORMAT, "overrides the format string used to parse a datetime"));
274276
cliOptions.add(CliOption.newString(PROP_DATE_FORMAT, "format string used to parse/render a date").defaultValue(defaultDateFormat));
275277

276278
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) {
321323
}
322324
}
323325

324-
public void setDateTimeFormat(String value) {
325-
setStringProp(PROP_DATETIME_FORMAT, value);
326-
}
326+
public void setDateTimeFormat(String value) { setStringProp(PROP_DATETIME_FORMAT, value); }
327+
328+
public void setDateTimeParseFormat(String value) { setStringProp(PROP_DATETIME_PARSE_FORMAT, value); }
327329

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

@@ -438,6 +440,12 @@ public void processOpts() {
438440
setDateTimeFormat(null); // default should be null
439441
}
440442

443+
if (additionalProperties.containsKey(PROP_DATETIME_PARSE_FORMAT)) {
444+
setDateTimeParseFormat(additionalProperties.get(PROP_DATETIME_PARSE_FORMAT).toString());
445+
} else {
446+
setDateTimeParseFormat(null); // default should be null
447+
}
448+
441449
if (additionalProperties.containsKey(PROP_DATE_FORMAT)) {
442450
setDateFormat(additionalProperties.get(PROP_DATE_FORMAT).toString());
443451
} else {

modules/openapi-generator/src/main/resources/haskell-http-client/Core.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,16 @@ instance P.Show DateTime where
425425
instance MimeRender MimeMultipartFormData DateTime where
426426
mimeRender _ = mimeRenderDefaultMultipartFormData
427427

428-
-- | @{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}@
428+
-- | @{{#dateTimeParseFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeParseFormat}}}"{{/dateTimeParseFormat}}{{^dateTimeParseFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{/dateTimeParseFormat}}@
429429
_readDateTime :: (TI.ParseTime t, Monad m{{^dateTimeFormat}}, Alternative m{{/dateTimeFormat}}) => String -> m t
430430
_readDateTime =
431-
{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}
431+
{{#dateTimeParseFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeParseFormat}}}"{{/dateTimeParseFormat}}{{^dateTimeParseFormat}}{{#dateTimeFormat}}TI.parseTimeM True TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}{{^dateTimeFormat}}_parseISO8601{{/dateTimeFormat}}{{/dateTimeParseFormat}}
432432
{-# INLINE _readDateTime #-}
433433

434434
-- | @{{^dateTimeFormat}}TI.formatISO8601Millis{{/dateTimeFormat}}{{#dateTimeFormat}}TI.formatTime TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}@
435435
_showDateTime :: ({{^dateTimeFormat}}t ~ TI.UTCTime, {{/dateTimeFormat}}TI.FormatTime t) => t -> String
436436
_showDateTime =
437-
{{^dateTimeFormat}}TI.formatISO8601Millis{{/dateTimeFormat}}{{#dateTimeFormat}}TI.formatTime TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}
437+
{{#dateTimeFormat}}TI.formatTime TI.defaultTimeLocale "{{{dateTimeFormat}}}"{{/dateTimeFormat}}{{^dateTimeFormat}}TI.formatISO8601Millis{{/dateTimeFormat}}
438438
{-# INLINE _showDateTime #-}
439439

440440
-- | parse an ISO8601 date-time string

modules/openapi-generator/src/main/resources/haskell-http-client/README.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ These options allow some customization of the code generation process.
6666
| configType | Set the name of the type used for configuration | | {{{configType}}} |
6767
| dateFormat | format string used to parse/render a date | %Y-%m-%d | {{{dateFormat}}} |
6868
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | {{{dateTimeFormat}}} |
69+
| dateTimeParseFormat | overrides the format string used to parse a datetime | | {{{dateTimeParseFormat}}} |
6970
| generateEnums | Generate specific datatypes for OpenAPI enums | true | {{{generateEnums}}} |
7071
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | {{{generateFormUrlEncodedInstances}}} |
7172
| generateLenses | Generate Lens optics for Models | true | {{{generateLenses}}} |

samples/client/petstore/haskell-http-client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ These options allow some customization of the code generation process.
6666
| configType | Set the name of the type used for configuration | | OpenAPIPetstoreConfig |
6767
| dateFormat | format string used to parse/render a date | %Y-%m-%d | %Y-%m-%d |
6868
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | |
69+
| dateTimeParseFormat | overrides the format string used to parse a datetime | | |
6970
| generateEnums | Generate specific datatypes for OpenAPI enums | true | true |
7071
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | true |
7172
| generateLenses | Generate Lens optics for Models | true | true |

0 commit comments

Comments
 (0)