forked from loafle/openapi-generator-original
[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`
This commit is contained in:
@@ -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|
|
||||
|
||||
@@ -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 class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
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 class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
}
|
||||
}
|
||||
|
||||
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 class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}}} |
|
||||
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user