forked from loafle/openapi-generator-original
Fix a bunch of minor bugs in the Haskell generator
This commit is contained in:
parent
b8d723b7ae
commit
6d386aaa90
@ -156,6 +156,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
typeMapping.put("file", "FilePath");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("any", "Value");
|
||||
|
||||
importMapping.clear();
|
||||
importMapping.put("Map", "qualified Data.Map as Map");
|
||||
@ -216,6 +217,9 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
additionalProperties.put("titleLower", apiName.substring(0, 1).toLowerCase() + apiName.substring(1));
|
||||
additionalProperties.put("package", cabalName);
|
||||
|
||||
// Due to the way servant resolves types, we need a high context stack limit
|
||||
additionalProperties.put("contextStackLimit", swagger.getPaths().size() * 2 + 300);
|
||||
|
||||
List<Map<String, Object>> replacements = new ArrayList<>();
|
||||
Object[] replacementChars = specialCharReplacements.keySet().toArray();
|
||||
for(int i = 0; i < replacementChars.length; i++) {
|
||||
@ -269,6 +273,8 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
return toModelName(type);
|
||||
} else if(swaggerType == "object") {
|
||||
type = "Value";
|
||||
} else if(typeMapping.containsValue(swaggerType)) {
|
||||
type = swaggerType + "_";
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
@ -423,7 +429,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
if (returnType.indexOf(" ") >= 0) {
|
||||
returnType = "(" + returnType + ")";
|
||||
}
|
||||
path.add(camelize(op.httpMethod.toLowerCase()) + " '[JSON] " + returnType);
|
||||
path.add("Verb '" + op.httpMethod.toUpperCase() + " 200 '[JSON] " + returnType);
|
||||
type.add("m " + returnType);
|
||||
|
||||
op.vendorExtensions.put("x-routeType", joinStrings(" :> ", path));
|
||||
@ -473,6 +479,9 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
// Clean up the class name to remove invalid characters
|
||||
model.classname = fixModelChars(model.classname);
|
||||
if(typeMapping.containsValue(model.classname)) {
|
||||
model.classname += "_";
|
||||
}
|
||||
|
||||
// From the model name, compute the prefix for the fields.
|
||||
String prefix = camelize(model.classname, true);
|
||||
@ -499,6 +508,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
|
||||
CodegenParameter p = super.fromParameter(param, imports);
|
||||
p.vendorExtensions.put("x-formParamName", camelize(p.baseName));
|
||||
p.dataType = fixModelChars(p.dataType);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{-# LANGUAGE DataKinds, TypeFamilies, TypeOperators, FlexibleInstances, OverloadedStrings, ViewPatterns #-}
|
||||
{-# LANGUAGE RecordWildCards, GeneralizedNewtypeDeriving, DeriveTraversable, FlexibleContexts, DeriveGeneric #-}
|
||||
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-unused-imports #-}
|
||||
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-unused-imports -fcontext-stack={{contextStackLimit}} #-}
|
||||
module {{title}}.API (
|
||||
-- * Client and Server
|
||||
ServerConfig(..),
|
||||
@ -33,13 +33,13 @@ import GHC.Exts (IsString(..))
|
||||
import qualified Data.Map as Map
|
||||
import GHC.Generics (Generic)
|
||||
import Data.Monoid ((<>))
|
||||
import Servant.API.Verbs (Verb, StdMethod(HEAD))
|
||||
import Servant.API.Verbs (Verb, StdMethod(..))
|
||||
import Control.Monad.Except (ExceptT)
|
||||
import Network.HTTP.Client (Manager, newManager, defaultManagerSettings)
|
||||
import Network.HTTP.Types.Method (methodOptions)
|
||||
|
||||
|
||||
-- | HEAD with 200 status code.
|
||||
type Head = Verb 'HEAD 200
|
||||
instance ReflectMethod 'OPTIONS where
|
||||
reflectMethod _ = methodOptions
|
||||
|
||||
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#hasFormParams}}
|
||||
|
@ -29,4 +29,5 @@ library
|
||||
, transformers
|
||||
, mtl
|
||||
, http-client
|
||||
, http-types
|
||||
default-language: Haskell2010
|
||||
|
Loading…
x
Reference in New Issue
Block a user