Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[haskell-http-client] add dateTimeParseFormat cli option - overrides the format string used to parse a datetime #4037

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/generators/haskell-http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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); }

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}} |
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/haskell-http-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down