[haskell-http-client] add config options: cabalPackage, cabalVersion, baseModule, requestType, configType (#7515)

- add new config options:

    cabalPackage
      Set the cabal package name, which consists of one or more alphanumeric words separated by hyphens

    cabalVersion
      Set the cabal version number, consisting of a sequence of one or more integers separated by dots

    baseModule
      Set the base module namespace

    requestType
      Set the name of the type used to generate requests

    configType
      Set the name of the type used for configuration
This commit is contained in:
Jon Schoning 2018-01-28 00:59:04 -06:00 committed by William Cheng
parent 0de7f972fe
commit 9fba9c3255
26 changed files with 240 additions and 162 deletions

View File

@ -31,10 +31,9 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
// source folder where to write the files
protected String sourceFolder = "lib";
protected String artifactId = "swagger-haskell-http-client";
protected String artifactVersion = "1.0.0";
protected String defaultDateFormat = "%Y-%m-%d";
protected String defaultCabalVersion = "0.1.0.0";
protected String modulePath = null;
protected Boolean useMonadLogger = false;
protected Boolean allowNonUniqueOperationIds = false;
@ -42,8 +41,12 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
// CLI PROPS
public static final String PROP_ALLOW_FROMJSON_NULLS = "allowFromJsonNulls";
public static final String PROP_ALLOW_TOJSON_NULLS = "allowToJsonNulls";
public static final String PROP_ALLOW_NONUNIQUE_OPERATION_IDS = "allowNonUniqueOperationIds";
public static final String PROP_ALLOW_TOJSON_NULLS = "allowToJsonNulls";
public static final String PROP_BASE_MODULE = "baseModule";
public static final String PROP_CABAL_PACKAGE = "cabalPackage";
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_DATE_FORMAT = "dateFormat";
public static final String PROP_GENERATE_ENUMS = "generateEnums";
@ -52,6 +55,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
public static final String PROP_GENERATE_MODEL_CONSTRUCTORS = "generateModelConstructors";
public static final String PROP_INLINE_MIME_TYPES = "inlineMimeTypes";
public static final String PROP_MODEL_DERIVING = "modelDeriving";
public static final String PROP_REQUEST_TYPE = "requestType";
public static final String PROP_STRICT_FIELDS = "strictFields";
public static final String PROP_USE_MONAD_LOGGER = "useMonadLogger";
@ -134,7 +138,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
outputFolder = "generated-code/haskell-http-client";
embeddedTemplateDir = templateDir = "haskell-http-client";
//apiPackage = "API";
apiPackage = "API";
//modelPackage = "Model";
// Haskell keywords and reserved function names, taken mostly from https://wiki.haskell.org/Keywords
@ -155,9 +159,6 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
)
);
additionalProperties.put("artifactId", artifactId);
additionalProperties.put("artifactVersion", artifactVersion);
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
@ -218,8 +219,14 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
importMapping.clear();
cliOptions.add(CliOption.newString(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
cliOptions.add(CliOption.newString(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
//cliOptions.add(CliOption.newString(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
//cliOptions.add(CliOption.newString(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
cliOptions.add(CliOption.newString(PROP_CABAL_PACKAGE, "Set the cabal package name, which consists of one or more alphanumeric words separated by hyphens"));
cliOptions.add(CliOption.newString(PROP_CABAL_VERSION, "Set the cabal version number, consisting of a sequence of one or more integers separated by dots"));
cliOptions.add(CliOption.newString(PROP_BASE_MODULE, "Set the base module namespace"));
cliOptions.add(CliOption.newString(PROP_REQUEST_TYPE, "Set the name of the type used to generate requests"));
cliOptions.add(CliOption.newString(PROP_CONFIG_TYPE, "Set the name of the type used for configuration"));
cliOptions.add(CliOption.newBoolean(PROP_ALLOW_FROMJSON_NULLS, "allow JSON Null during model decoding from JSON").defaultValue(Boolean.TRUE.toString()));
cliOptions.add(CliOption.newBoolean(PROP_ALLOW_TOJSON_NULLS, "allow emitting JSON Null during model encoding to JSON").defaultValue(Boolean.FALSE.toString()));
@ -281,20 +288,31 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
}
public void setDateTimeFormat(String value) {
if (StringUtils.isBlank(value)) {
additionalProperties.remove(PROP_DATETIME_FORMAT);
} else {
additionalProperties.put(PROP_DATETIME_FORMAT, value);
}
setStringProp(PROP_DATETIME_FORMAT, value);
}
public void setDateFormat(String value) {
if (StringUtils.isBlank(value)) {
additionalProperties.remove(PROP_DATE_FORMAT);
} else {
additionalProperties.put(PROP_DATE_FORMAT, value);
setStringProp(PROP_DATE_FORMAT, value);
}
public void setCabalPackage(String value) {
setStringProp(PROP_CABAL_PACKAGE, value);
}
public void setCabalVersion(String value) {
setStringProp(PROP_CABAL_VERSION, value);
}
public void setBaseModule(String value) {
setStringProp(PROP_BASE_MODULE, value);
}
public void setRequestType(String value) {
setStringProp(PROP_REQUEST_TYPE, value);
}
public void setConfigType(String value) {
setStringProp(PROP_CONFIG_TYPE, value);
}
public void setStrictFields(Boolean value) {
@ -306,6 +324,18 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
this.useMonadLogger = value;
}
private void setStringProp(String key, String value) {
if (StringUtils.isBlank(value)) {
additionalProperties.remove(key);
} else {
additionalProperties.put(key, value);
}
}
private String getStringProp(String key) {
return (String)additionalProperties.get(key);
}
@Override
public void processOpts() {
super.processOpts();
@ -393,75 +423,99 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
setUseMonadLogger(false);
}
if (additionalProperties.containsKey(PROP_CABAL_PACKAGE)) {
setCabalPackage(additionalProperties.get(PROP_CABAL_PACKAGE).toString());
}
if (additionalProperties.containsKey(PROP_CABAL_VERSION)) {
setCabalVersion(additionalProperties.get(PROP_CABAL_VERSION).toString());
} else {
setCabalVersion(defaultCabalVersion);
}
if (additionalProperties.containsKey(PROP_BASE_MODULE)) {
setBaseModule(additionalProperties.get(PROP_BASE_MODULE).toString());
}
if (additionalProperties.containsKey(PROP_REQUEST_TYPE)) {
setRequestType(additionalProperties.get(PROP_REQUEST_TYPE).toString());
}
if (additionalProperties.containsKey(PROP_CONFIG_TYPE)) {
setConfigType(additionalProperties.get(PROP_CONFIG_TYPE).toString());
}
}
@Override
public void preprocessSwagger(Swagger swagger) {
// From the title, compute a reasonable name for the package and the API
String title = swagger.getInfo().getTitle();
String baseTitle = swagger.getInfo().getTitle();
// Drop any API suffix
if (title == null) {
title = "Swagger";
if (baseTitle == null) {
baseTitle = "Swagger";
} else {
title = title.trim();
if (title.toUpperCase().endsWith("API")) {
title = title.substring(0, title.length() - 3);
baseTitle = baseTitle.trim();
// Drop any API suffix
if (baseTitle.toUpperCase().endsWith("API")) {
baseTitle = baseTitle.substring(0, baseTitle.length() - 3);
}
}
String[] words = title.split(" ");
// The package name is made by appending the lowercased words of the title interspersed with dashes
List<String> wordsLower = new ArrayList<String>();
for (String word : words) {
wordsLower.add(word.toLowerCase());
if (!additionalProperties.containsKey(PROP_CABAL_PACKAGE)) {
List<String> words = new ArrayList<>();
for (String word : baseTitle.split(" ")) {
words.add(word.toLowerCase());
}
setCabalPackage(StringUtils.join(words, "-"));
}
String cabalName = StringUtils.join(wordsLower, "-");
String pathsName = StringUtils.join(wordsLower, "_");
// The API name is made by appending the capitalized words of the title
if (!additionalProperties.containsKey(PROP_BASE_MODULE)) {
List<String> wordsCaps = new ArrayList<String>();
for (String word : words) {
for (String word : baseTitle.split(" ")) {
wordsCaps.add(firstLetterToUpper(word));
}
apiPackage = StringUtils.join(wordsCaps, "");
setBaseModule(StringUtils.join(wordsCaps, ""));
}
// Set the filenames to write for the API
modulePath = sourceFolder + File.separator + getStringProp(PROP_BASE_MODULE).replace('.', File.separatorChar);
String topLevelPath = StringUtils.substringBeforeLast(modulePath, String.valueOf(File.separatorChar));
String lastPath = StringUtils.substringAfterLast(modulePath, String.valueOf(File.separatorChar));
if (!additionalProperties.containsKey(PROP_REQUEST_TYPE)) {
setRequestType(lastPath + "Request");
}
if (!additionalProperties.containsKey(PROP_CONFIG_TYPE)) {
setConfigType(lastPath + "Config");
}
// root
supportingFiles.add(new SupportingFile("haskell-http-client.cabal.mustache", "", cabalName + ".cabal"));
supportingFiles.add(new SupportingFile("haskell-http-client.cabal.mustache", "", getStringProp(PROP_CABAL_PACKAGE) + ".cabal"));
supportingFiles.add(new SupportingFile("swagger.mustache", "", "swagger.yaml"));
// lib
supportingFiles.add(new SupportingFile("TopLevel.mustache", sourceFolder + File.separator, apiPackage + ".hs"));
supportingFiles.add(new SupportingFile("Client.mustache", sourceFolder + File.separator + apiPackage, "Client.hs"));
supportingFiles.add(new SupportingFile("TopLevel.mustache", topLevelPath, lastPath + ".hs"));
supportingFiles.add(new SupportingFile("Client.mustache", modulePath, "Client.hs"));
if(!allowNonUniqueOperationIds) {
supportingFiles.add(new SupportingFile("APIS.mustache", sourceFolder + File.separator + apiPackage, "API.hs"));
supportingFiles.add(new SupportingFile("APIS.mustache", modulePath, "API.hs"));
}
supportingFiles.add(new SupportingFile("Core.mustache", sourceFolder + File.separator + apiPackage, "Core.hs"));
supportingFiles.add(new SupportingFile("Model.mustache", sourceFolder + File.separator + apiPackage, "Model.hs"));
supportingFiles.add(new SupportingFile("MimeTypes.mustache", sourceFolder + File.separator + apiPackage, "MimeTypes.hs"));
supportingFiles.add(new SupportingFile("Core.mustache", modulePath, "Core.hs"));
supportingFiles.add(new SupportingFile("Model.mustache", modulePath, "Model.hs"));
supportingFiles.add(new SupportingFile("MimeTypes.mustache", modulePath, "MimeTypes.hs"));
// logger
supportingFiles.add(new SupportingFile(useMonadLogger ? "LoggingMonadLogger.mustache" : "LoggingKatip.mustache", sourceFolder + File.separator + apiPackage, "Logging.hs"));
supportingFiles.add(new SupportingFile(useMonadLogger ? "LoggingMonadLogger.mustache" : "LoggingKatip.mustache", modulePath, "Logging.hs"));
apiTemplateFiles.put("API.mustache", ".hs");
// modelTemplateFiles.put("Model.mustache", ".hs");
// lens
if ((boolean)additionalProperties.get(PROP_GENERATE_LENSES)) {
supportingFiles.add(new SupportingFile("ModelLens.mustache", sourceFolder + File.separator + apiPackage, "ModelLens.hs"));
supportingFiles.add(new SupportingFile("ModelLens.mustache", modulePath, "ModelLens.hs"));
}
additionalProperties.put("title", apiPackage);
additionalProperties.put("titleLower", firstLetterToLower(apiPackage));
additionalProperties.put("package", cabalName);
additionalProperties.put("pathsName", pathsName);
additionalProperties.put("requestType", apiPackage + "Request");
additionalProperties.put("configType", apiPackage + "Config");
additionalProperties.put("cabalName", getStringProp(PROP_CABAL_PACKAGE));
additionalProperties.put("pathsName", getStringProp(PROP_CABAL_PACKAGE).replace('-','_'));
additionalProperties.put("requestType", getStringProp(PROP_REQUEST_TYPE));
additionalProperties.put("configType", getStringProp(PROP_CONFIG_TYPE));
additionalProperties.put("swaggerVersion", swagger.getSwagger());
super.preprocessSwagger(swagger);
@ -1035,7 +1089,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
}
@Override
public String apiFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar) + File.separator + "API";
return outputFolder + File.separator + this.modulePath + File.separator + "API";
}
public String toTypeName(String prefix, String name) {
name = escapeIdentifier(prefix, camelize(sanitizeName(name)));

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.API.{{classname}}
Module : {{baseModule}}.API.{{classname}}
-}
{-# LANGUAGE FlexibleContexts #-}
@ -10,11 +10,11 @@ Module : {{title}}.API.{{classname}}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-binds -fno-warn-unused-imports #-}
module {{title}}.API.{{classname}} where
module {{baseModule}}.API.{{classname}} where
import {{title}}.Core
import {{title}}.MimeTypes
import {{title}}.Model as M
import {{baseModule}}.Core
import {{baseModule}}.MimeTypes
import {{baseModule}}.Model as M
import qualified Data.Aeson as A
import qualified Data.ByteString as B

View File

@ -1,10 +1,10 @@
{{>partial_header}}
{-|
Module : {{title}}.API
Module : {{baseModule}}.API
-}
module {{title}}.API
( {{#apiInfo}}{{#apis}}module {{title}}.API.{{classname}}
module {{baseModule}}.API
( {{#apiInfo}}{{#apis}}module {{baseModule}}.API.{{classname}}
{{#hasMore}}, {{/hasMore}}{{/apis}}{{/apiInfo}}) where
{{#apiInfo}}{{#apis}}
import {{title}}.API.{{classname}}{{/apis}}{{/apiInfo}}
import {{baseModule}}.API.{{classname}}{{/apis}}{{/apiInfo}}

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.Client
Module : {{baseModule}}.Client
-}
{-# LANGUAGE OverloadedStrings #-}
@ -13,11 +13,11 @@ Module : {{title}}.Client
{-# LANGUAGE DeriveTraversable #-}
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-unused-imports #-}
module {{title}}.Client where
module {{baseModule}}.Client where
import {{title}}.Core
import {{title}}.Logging
import {{title}}.MimeTypes
import {{baseModule}}.Core
import {{baseModule}}.Logging
import {{baseModule}}.MimeTypes
import qualified Control.Exception.Safe as E
import qualified Control.Monad.IO.Class as P

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.Core
Module : {{baseModule}}.Core
-}
{-# LANGUAGE DeriveDataTypeable #-}
@ -16,10 +16,10 @@ Module : {{title}}.Core
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-binds #-}
module {{title}}.Core where
module {{baseModule}}.Core where
import {{title}}.MimeTypes
import {{title}}.Logging
import {{baseModule}}.MimeTypes
import {{baseModule}}.Logging
import qualified Control.Arrow as P (left)
import qualified Control.DeepSeq as NF
@ -86,14 +86,14 @@ instance P.Show {{configType}} where
--
-- configUserAgent:
--
-- @"{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}{{{artifactId}}}/{{{artifactVersion}}}{{/httpUserAgent}}"@
-- @"{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}{{{cabalName}}}/{{{cabalVersion}}}{{/httpUserAgent}}"@
--
newConfig :: IO {{configType}}
newConfig = do
logCxt <- initLogContext
return $ {{configType}}
{ configHost = "{{{basePath}}}"
, configUserAgent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}{{{artifactId}}}/{{{artifactVersion}}}{{/httpUserAgent}}"
, configUserAgent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}{{{cabalName}}}/{{{cabalVersion}}}{{/httpUserAgent}}"
, configLogExecWithContext = runDefaultLogExecWithContext
, configLogContext = logCxt
, configAuthMethods = []

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.Logging
Module : {{baseModule}}.Logging
Katip Logging functions
-}
@ -8,7 +8,7 @@ Katip Logging functions
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module {{title}}.Logging where
module {{baseModule}}.Logging where
import qualified Control.Exception.Safe as E
import qualified Control.Monad.IO.Class as P
@ -41,7 +41,7 @@ type LogLevel = LG.Severity
-- | the default log environment
initLogContext :: IO LogContext
initLogContext = LG.initLogEnv "{{title}}" "dev"
initLogContext = LG.initLogEnv "{{baseModule}}" "dev"
-- | Runs a Katip logging block with the Log environment
runDefaultLogExecWithContext :: LogExecWithContext

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.Logging
Module : {{baseModule}}.Logging
monad-logger Logging functions
-}
@ -8,7 +8,7 @@ monad-logger Logging functions
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module {{title}}.Logging where
module {{baseModule}}.Logging where
import qualified Control.Exception.Safe as E
import qualified Control.Monad.IO.Class as P
@ -81,7 +81,7 @@ nullLogger _ _ _ _ = return ()
_log :: (P.MonadIO m, LG.MonadLogger m) => Text -> LG.LogLevel -> Text -> m ()
_log src level msg = do
now <- P.liftIO (formatTimeLog <$> TI.getCurrentTime)
LG.logOtherNS ("{{title}}." <> src) level ("[" <> now <> "] " <> msg)
LG.logOtherNS ("{{baseModule}}." <> src) level ("[" <> now <> "] " <> msg)
where
formatTimeLog =
T.pack . TI.formatTime TI.defaultTimeLocale "%Y-%m-%dT%H:%M:%S%Z"

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.MimeTypes
Module : {{baseModule}}.MimeTypes
-}
{-# LANGUAGE ConstraintKinds #-}
@ -12,7 +12,7 @@ Module : {{title}}.MimeTypes
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-unused-imports #-}
module {{title}}.MimeTypes where
module {{baseModule}}.MimeTypes where
import qualified Control.Arrow as P (left)
import qualified Data.Aeson as A

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.Model
Module : {{baseModule}}.Model
-}
{-# LANGUAGE DeriveDataTypeable #-}
@ -17,10 +17,10 @@ Module : {{title}}.Model
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-unused-matches -fno-warn-unused-binds -fno-warn-unused-imports #-}
module {{title}}.Model where
module {{baseModule}}.Model where
import {{title}}.Core
import {{title}}.MimeTypes
import {{baseModule}}.Core
import {{baseModule}}.MimeTypes
import Data.Aeson ((.:),(.:!),(.:?),(.=))

View File

@ -1,6 +1,6 @@
{{>partial_header}}
{-|
Module : {{title}}.Lens
Module : {{baseModule}}.Lens
-}
{-# LANGUAGE KindSignatures #-}
@ -9,7 +9,7 @@ Module : {{title}}.Lens
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-matches -fno-warn-unused-binds -fno-warn-unused-imports #-}
module {{title}}.ModelLens where
module {{baseModule}}.ModelLens where
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as BL
@ -23,8 +23,8 @@ import Data.Text (Text)
import Prelude (($), (.),(<$>),(<*>),(=<<),Maybe(..),Bool(..),Char,Double,FilePath,Float,Int,Integer,String,fmap,undefined,mempty,maybe,pure,Monad,Applicative,Functor)
import qualified Prelude as P
import {{title}}.Model
import {{title}}.Core
import {{baseModule}}.Model
import {{baseModule}}.Core
{{#models}}
{{#model}}

View File

@ -1,6 +1,6 @@
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) Bindings to `{{title}}`
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) Bindings to `{{baseModule}}`
The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) bindings to the {{title}} API.
The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) bindings to the {{baseModule}} API.
Targeted swagger version: {{swaggerVersion}}
@ -58,9 +58,13 @@ These options allow some customization of the code generation process.
| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------- |
| allowNonUniqueOperationIds | allow *different* API modules to contain the same operationId. Each API must be imported qualified | false | {{{x-allowNonUniqueOperationIds}}} |
| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | {{{allowFromJsonNulls}}} |
| allowNonUniqueOperationIds | allow *different* API modules to contain the same operationId. Each API must be imported qualified | false | {{{x-allowNonUniqueOperationIds}}} |
| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | {{{allowToJsonNulls}}} |
| 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}}} |
| 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}}} |
| generateEnums | Generate specific datatypes for swagger enums | true | {{{generateEnums}}} |
@ -69,6 +73,7 @@ These options allow some customization of the code generation process.
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | {{{generateModelConstructors}}} |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | false | {{{inlineMimeTypes}}} |
| modelDeriving | Additional classes to include in the deriving() clause of Models | | {{{modelDeriving}}} |
| requestType | Set the name of the type used to generate requests | | {{{requestType}}} |
| strictFields | Add strictness annotations to all model fields | true | {{{x-strictFields}}} |
| useMonadLogger | Use the monad-logger package to provide logging (if instead false, use the katip logging package) | false | {{{x-useMonadLogger}}} |
@ -106,13 +111,13 @@ This library is intended to be imported qualified.
| MODULE | NOTES |
| ------------------- | --------------------------------------------------- |
| {{title}}.Client | use the "dispatch" functions to send requests |
| {{title}}.Core | core funcions, config and request types |
| {{title}}.API | construct api requests |
| {{title}}.Model | describes api models |
| {{title}}.MimeTypes | encoding/decoding MIME types (content-types/accept) |
| {{title}}.ModelLens | lenses for model fields |
| {{title}}.Logging | logging functions and utils |
| {{baseModule}}.Client | use the "dispatch" functions to send requests |
| {{baseModule}}.Core | core funcions, config and request types |
| {{baseModule}}.API | construct api requests |
| {{baseModule}}.Model | describes api models |
| {{baseModule}}.MimeTypes | encoding/decoding MIME types (content-types/accept) |
| {{baseModule}}.ModelLens | lenses for model fields |
| {{baseModule}}.Logging | logging functions and utils |
### MimeTypes

View File

@ -1,22 +1,22 @@
{{>partial_header}}
{-|
Module : {{title}}
Module : {{baseModule}}
-}
module {{title}}
( {{^x-allowNonUniqueOperationIds}} module {{title}}.API
,{{/x-allowNonUniqueOperationIds}} module {{title}}.Client
, module {{title}}.Core
, module {{title}}.Logging
, module {{title}}.MimeTypes
, module {{title}}.Model
, module {{title}}.ModelLens
module {{baseModule}}
( {{^x-allowNonUniqueOperationIds}} module {{baseModule}}.API
,{{/x-allowNonUniqueOperationIds}} module {{baseModule}}.Client
, module {{baseModule}}.Core
, module {{baseModule}}.Logging
, module {{baseModule}}.MimeTypes
, module {{baseModule}}.Model
, module {{baseModule}}.ModelLens
) where
{{^x-allowNonUniqueOperationIds}}import {{title}}.API{{/x-allowNonUniqueOperationIds}}
import {{title}}.Client
import {{title}}.Core
import {{title}}.Logging
import {{title}}.MimeTypes
import {{title}}.Model
import {{title}}.ModelLens
{{^x-allowNonUniqueOperationIds}}import {{baseModule}}.API{{/x-allowNonUniqueOperationIds}}
import {{baseModule}}.Client
import {{baseModule}}.Core
import {{baseModule}}.Logging
import {{baseModule}}.MimeTypes
import {{baseModule}}.Model
import {{baseModule}}.ModelLens

View File

@ -1,8 +1,8 @@
name: {{package}}
version: 0.1.0.0
synopsis: Auto-generated {{package}} API Client
name: {{cabalPackage}}
version: {{cabalVersion}}
synopsis: Auto-generated {{cabalPackage}} API Client
description: .
Client library for calling the {{package}} API based on http-client.
Client library for calling the {{appName}} API based on http-client.
.
host: {{host}}
.
@ -61,18 +61,18 @@ library
, unordered-containers
, vector >=0.10.9 && <0.13
, {{^x-useMonadLogger}}katip >=0.4 && < 0.6{{/x-useMonadLogger}}{{#x-useMonadLogger}}monad-logger >=0.3 && <0.4{{/x-useMonadLogger}}
exposed-modules:
{{title}}{{^x-allowNonUniqueOperationIds}}
{{title}}.API{{/x-allowNonUniqueOperationIds}}{{#apiInfo}}{{#apis}}
{{title}}.API.{{classname}}{{/apis}}{{/apiInfo}}
{{title}}.Client
{{title}}.Core
{{title}}.Logging
{{title}}.MimeTypes
{{title}}.Model
{{title}}.ModelLens
other-modules:
Paths_{{pathsName}}
exposed-modules:
{{baseModule}}{{^x-allowNonUniqueOperationIds}}
{{baseModule}}.API{{/x-allowNonUniqueOperationIds}}{{#apiInfo}}{{#apis}}
{{baseModule}}.API.{{classname}}{{/apis}}{{/apiInfo}}
{{baseModule}}.Client
{{baseModule}}.Core
{{baseModule}}.Logging
{{baseModule}}.MimeTypes
{{baseModule}}.Model
{{baseModule}}.ModelLens
default-language: Haskell2010
test-suite tests
@ -82,7 +82,7 @@ test-suite tests
tests
ghc-options: -Wall -fno-warn-orphans
build-depends:
{{package}}
{{cabalPackage}}
, QuickCheck
, aeson
, base >=4.7 && <5.0

View File

@ -2,8 +2,8 @@
module Instances where
import {{title}}.Model
import {{title}}.Core
import {{baseModule}}.Model
import {{baseModule}}.Core
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as BL

View File

@ -15,7 +15,7 @@ import Test.QuickCheck
import Test.QuickCheck.Property
import Test.Hspec.QuickCheck (prop)
import {{title}}.MimeTypes
import {{baseModule}}.MimeTypes
import ApproxEq

View File

@ -12,8 +12,8 @@ import Test.Hspec.QuickCheck
import PropMime
import Instances ()
import {{title}}.Model
import {{title}}.MimeTypes
import {{baseModule}}.Model
import {{baseModule}}.MimeTypes
main :: IO ()
main =

View File

@ -24,10 +24,6 @@ public class HaskellHttpClientOptionsTest extends AbstractOptionsTest {
@Override
protected void setExpectations() {
new Expectations(clientCodegen) {{
clientCodegen.setModelPackage(HaskellHttpClientOptionsProvider.MODEL_PACKAGE_VALUE);
times = 1;
clientCodegen.setApiPackage(HaskellHttpClientOptionsProvider.API_PACKAGE_VALUE);
times = 1;
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(HaskellHttpClientOptionsProvider.SORT_PARAMS_VALUE));
times = 1;
clientCodegen.setAllowNonUniqueOperationIds(Boolean.valueOf(HaskellHttpClientOptionsProvider.ALLOW_NONUNIQUE_OPERATION_IDS));
@ -56,7 +52,16 @@ public class HaskellHttpClientOptionsTest extends AbstractOptionsTest {
times = 1;
clientCodegen.setUseMonadLogger(Boolean.valueOf(HaskellHttpClientOptionsProvider.USE_MONAD_LOGGER));
times = 1;
clientCodegen.setCabalPackage(HaskellHttpClientOptionsProvider.CABAL_PACKAGE);
times = 1;
clientCodegen.setCabalVersion(HaskellHttpClientOptionsProvider.CABAL_VERSION);
times = 1;
clientCodegen.setBaseModule(HaskellHttpClientOptionsProvider.BASE_MODULE);
times = 1;
clientCodegen.setRequestType(HaskellHttpClientOptionsProvider.REQUEST_TYPE);
times = 1;
clientCodegen.setConfigType(HaskellHttpClientOptionsProvider.CONFIG_TYPE);
times = 1;
}};
}
}

View File

@ -28,6 +28,12 @@ public class HaskellHttpClientOptionsProvider implements OptionsProvider {
public static final String INLINE_MIME_TYPES = "false";
public static final String USE_MONAD_LOGGER = "false";
public static final String CABAL_PACKAGE = "cabal-package";
public static final String CABAL_VERSION = "1.0.0.0";
public static final String BASE_MODULE = "Network.Module";
public static final String REQUEST_TYPE = "RequestType";
public static final String CONFIG_TYPE = "ConfigType";
@Override
public String getLanguage() {
return "haskell-http-client";
@ -36,8 +42,7 @@ public class HaskellHttpClientOptionsProvider implements OptionsProvider {
@Override
public Map<String, String> createOptions() {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE)
.put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE)
return builder
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
@ -56,7 +61,11 @@ public class HaskellHttpClientOptionsProvider implements OptionsProvider {
.put(HaskellHttpClientCodegen.PROP_INLINE_MIME_TYPES, INLINE_MIME_TYPES)
.put(HaskellHttpClientCodegen.PROP_STRICT_FIELDS, STRICT_FIELDS)
.put(HaskellHttpClientCodegen.PROP_USE_MONAD_LOGGER, USE_MONAD_LOGGER)
.put(HaskellHttpClientCodegen.PROP_CABAL_PACKAGE, CABAL_PACKAGE)
.put(HaskellHttpClientCodegen.PROP_CABAL_VERSION, CABAL_VERSION)
.put(HaskellHttpClientCodegen.PROP_BASE_MODULE, BASE_MODULE)
.put(HaskellHttpClientCodegen.PROP_REQUEST_TYPE, REQUEST_TYPE)
.put(HaskellHttpClientCodegen.PROP_CONFIG_TYPE, CONFIG_TYPE)
.build();
}

View File

@ -1 +1 @@
2.3.0
2.4.0-SNAPSHOT

View File

@ -58,9 +58,13 @@ These options allow some customization of the code generation process.
| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------- |
| allowNonUniqueOperationIds | allow *different* API modules to contain the same operationId. Each API must be imported qualified | false | false |
| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | true |
| allowNonUniqueOperationIds | allow *different* API modules to contain the same operationId. Each API must be imported qualified | false | false |
| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | false |
| baseModule | Set the base module namespace | | SwaggerPetstore |
| cabalPackage | Set the cabal package name, which consists of one or more alphanumeric words separated by hyphens | | swagger-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 |
| configType | Set the name of the type used for configuration | | SwaggerPetstoreConfig |
| 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) | | |
| generateEnums | Generate specific datatypes for swagger enums | true | true |
@ -69,6 +73,7 @@ These options allow some customization of the code generation process.
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | true |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | false | false |
| modelDeriving | Additional classes to include in the deriving() clause of Models | | |
| requestType | Set the name of the type used to generate requests | | SwaggerPetstoreRequest |
| strictFields | Add strictness annotations to all model fields | true | true |
| useMonadLogger | Use the monad-logger package to provide logging (if instead false, use the katip logging package) | false | false |

File diff suppressed because one or more lines are too long

View File

@ -2,4 +2,4 @@
window.onload = function () {pageLoad();};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">swagger-petstore-0.1.0.0: Auto-generated swagger-petstore API Client</p></div><div id="content"><div id="description"><h1>swagger-petstore-0.1.0.0: Auto-generated swagger-petstore API Client</h1><div class="doc"><p>.
Client library for calling the swagger-petstore API based on http-client.</p><p>host: petstore.swagger.io:80</p><p>base path: <a href="http://petstore.swagger.io:80/v2">http://petstore.swagger.io:80/v2</a></p><p>Swagger Petstore API version: 1.0.0</p><p>OpenAPI spec version: 2.0</p><p>OpenAPI-Specification: <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md">https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md</a></p></div></div><div id="module-list"><p class="caption">Signatures</p></div><div id="module-list"><p class="caption">Modules</p><ul><li><span class="module"><span id="control.n.1" class="collapser" onclick="toggleSection('n.1')">&nbsp;</span><a href="SwaggerPetstore.html">SwaggerPetstore</a></span><ul id="section.n.1" class="show"><li><span class="module"><span id="control.n.1.1" class="collapser" onclick="toggleSection('n.1.1')">&nbsp;</span><a href="SwaggerPetstore-API.html">SwaggerPetstore.API</a></span><ul id="section.n.1.1" class="show"><li><span class="module"><a href="SwaggerPetstore-API-AnotherFake.html">SwaggerPetstore.API.AnotherFake</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-Fake.html">SwaggerPetstore.API.Fake</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-FakeClassnameTags123.html">SwaggerPetstore.API.FakeClassnameTags123</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-Pet.html">SwaggerPetstore.API.Pet</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-Store.html">SwaggerPetstore.API.Store</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-User.html">SwaggerPetstore.API.User</a></span></li></ul></li><li><span class="module"><a href="SwaggerPetstore-Client.html">SwaggerPetstore.Client</a></span></li><li><span class="module"><a href="SwaggerPetstore-Core.html">SwaggerPetstore.Core</a></span></li><li><span class="module"><a href="SwaggerPetstore-Logging.html">SwaggerPetstore.Logging</a></span></li><li><span class="module"><a href="SwaggerPetstore-MimeTypes.html">SwaggerPetstore.MimeTypes</a></span></li><li><span class="module"><a href="SwaggerPetstore-Model.html">SwaggerPetstore.Model</a></span></li><li><span class="module"><a href="SwaggerPetstore-ModelLens.html">SwaggerPetstore.ModelLens</a></span></li></ul></li></ul></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.18.1</p></div></body></html>
Client library for calling the Swagger Petstore API based on http-client.</p><p>host: petstore.swagger.io:80</p><p>base path: <a href="http://petstore.swagger.io:80/v2">http://petstore.swagger.io:80/v2</a></p><p>Swagger Petstore API version: 1.0.0</p><p>OpenAPI spec version: 2.0</p><p>OpenAPI-Specification: <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md">https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md</a></p></div></div><div id="module-list"><p class="caption">Signatures</p></div><div id="module-list"><p class="caption">Modules</p><ul><li><span class="module"><span id="control.n.1" class="collapser" onclick="toggleSection('n.1')">&nbsp;</span><a href="SwaggerPetstore.html">SwaggerPetstore</a></span><ul id="section.n.1" class="show"><li><span class="module"><span id="control.n.1.1" class="collapser" onclick="toggleSection('n.1.1')">&nbsp;</span><a href="SwaggerPetstore-API.html">SwaggerPetstore.API</a></span><ul id="section.n.1.1" class="show"><li><span class="module"><a href="SwaggerPetstore-API-AnotherFake.html">SwaggerPetstore.API.AnotherFake</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-Fake.html">SwaggerPetstore.API.Fake</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-FakeClassnameTags123.html">SwaggerPetstore.API.FakeClassnameTags123</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-Pet.html">SwaggerPetstore.API.Pet</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-Store.html">SwaggerPetstore.API.Store</a></span></li><li><span class="module"><a href="SwaggerPetstore-API-User.html">SwaggerPetstore.API.User</a></span></li></ul></li><li><span class="module"><a href="SwaggerPetstore-Client.html">SwaggerPetstore.Client</a></span></li><li><span class="module"><a href="SwaggerPetstore-Core.html">SwaggerPetstore.Core</a></span></li><li><span class="module"><a href="SwaggerPetstore-Logging.html">SwaggerPetstore.Logging</a></span></li><li><span class="module"><a href="SwaggerPetstore-MimeTypes.html">SwaggerPetstore.MimeTypes</a></span></li><li><span class="module"><a href="SwaggerPetstore-Model.html">SwaggerPetstore.Model</a></span></li><li><span class="module"><a href="SwaggerPetstore-ModelLens.html">SwaggerPetstore.ModelLens</a></span></li></ul></li></ul></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.18.1</p></div></body></html>

View File

@ -96,14 +96,14 @@ Module : SwaggerPetstore.Core
</span><a name="line-96"></a><span class="hs-comment">--</span><span>
</span><a name="line-97"></a><span class="hs-comment">-- configUserAgent:</span><span>
</span><a name="line-98"></a><span class="hs-comment">--</span><span>
</span><a name="line-99"></a><span class="hs-comment">-- @&quot;swagger-haskell-http-client/1.0.0&quot;@</span><span>
</span><a name="line-99"></a><span class="hs-comment">-- @&quot;swagger-petstore/0.1.0.0&quot;@</span><span>
</span><a name="line-100"></a><span class="hs-comment">--</span><span>
</span><a name="line-101"></a><span class="hs-identifier">newConfig</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier hs-type">IO</span><span> </span><a href="SwaggerPetstore.Core.html#SwaggerPetstoreConfig"><span class="hs-identifier hs-type">SwaggerPetstoreConfig</span></a><span>
</span><a name="line-102"></a><a name="newConfig"><a href="SwaggerPetstore.Core.html#newConfig"><span class="hs-identifier">newConfig</span></a></a><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><a name="line-103"></a><span> </span><a name="local-6989586621679115241"><a href="#local-6989586621679115241"><span class="hs-identifier">logCxt</span></a></a><span> </span><span class="hs-glyph">&lt;-</span><span> </span><a href="SwaggerPetstore.Logging.html#initLogContext"><span class="hs-identifier hs-var">initLogContext</span></a><span>
</span><a name="line-104"></a><span> </span><span class="hs-identifier hs-var">return</span><span> </span><span class="hs-operator hs-var">$</span><span> </span><a href="SwaggerPetstore.Core.html#SwaggerPetstoreConfig"><span class="hs-identifier hs-var">SwaggerPetstoreConfig</span></a><span>
</span><a name="line-105"></a><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">configHost</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-string">&quot;http://petstore.swagger.io:80/v2&quot;</span><span>
</span><a name="line-106"></a><span> </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">configUserAgent</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-string">&quot;swagger-haskell-http-client/1.0.0&quot;</span><span>
</span><a name="line-106"></a><span> </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">configUserAgent</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-string">&quot;swagger-petstore/0.1.0.0&quot;</span><span>
</span><a name="line-107"></a><span> </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">configLogExecWithContext</span><span> </span><span class="hs-glyph">=</span><span> </span><a href="SwaggerPetstore.Logging.html#runDefaultLogExecWithContext"><span class="hs-identifier hs-var">runDefaultLogExecWithContext</span></a><span>
</span><a name="line-108"></a><span> </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">configLogContext</span><span> </span><span class="hs-glyph">=</span><span> </span><a href="#local-6989586621679115241"><span class="hs-identifier hs-var">logCxt</span></a><span>
</span><a name="line-109"></a><span> </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">configAuthMethods</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>

View File

@ -4,7 +4,7 @@
-- | Auto-generated swagger-petstore API Client
--
-- . Client library for calling the swagger-petstore API based on
-- . Client library for calling the Swagger Petstore API based on
-- http-client.
--
-- host: petstore.swagger.io:80
@ -296,7 +296,7 @@ SwaggerPetstoreConfig :: ByteString -> Text -> LogExecWithContext -> LogContext
-- configUserAgent:
--
-- <pre>
-- "swagger-haskell-http-client/1.0.0"
-- "swagger-petstore/0.1.0.0"
-- </pre>
newConfig :: IO SwaggerPetstoreConfig

View File

@ -96,14 +96,14 @@ instance P.Show SwaggerPetstoreConfig where
--
-- configUserAgent:
--
-- @"swagger-haskell-http-client/1.0.0"@
-- @"swagger-petstore/0.1.0.0"@
--
newConfig :: IO SwaggerPetstoreConfig
newConfig = do
logCxt <- initLogContext
return $ SwaggerPetstoreConfig
{ configHost = "http://petstore.swagger.io:80/v2"
, configUserAgent = "swagger-haskell-http-client/1.0.0"
, configUserAgent = "swagger-petstore/0.1.0.0"
, configLogExecWithContext = runDefaultLogExecWithContext
, configLogContext = logCxt
, configAuthMethods = []

View File

@ -2,7 +2,7 @@ name: swagger-petstore
version: 0.1.0.0
synopsis: Auto-generated swagger-petstore API Client
description: .
Client library for calling the swagger-petstore API based on http-client.
Client library for calling the Swagger Petstore API based on http-client.
.
host: petstore.swagger.io:80
.
@ -57,6 +57,8 @@ library
, unordered-containers
, vector >=0.10.9 && <0.13
, katip >=0.4 && < 0.6
other-modules:
Paths_swagger_petstore
exposed-modules:
SwaggerPetstore
SwaggerPetstore.API
@ -72,8 +74,6 @@ library
SwaggerPetstore.MimeTypes
SwaggerPetstore.Model
SwaggerPetstore.ModelLens
other-modules:
Paths_swagger_petstore
default-language: Haskell2010
test-suite tests