forked from loafle/openapi-generator-original
Resolve Elm merge conflicts
This commit is contained in:
@@ -37,30 +37,10 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElmClientCodegen.class);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
private Set<String> customPrimitives = new HashSet<String>();
|
||||
private ElmVersion elmVersion = ElmVersion.ELM_019;
|
||||
private Boolean elmPrefixCustomTypeVariants = false;
|
||||
|
||||
private static final String ELM_VERSION = "elmVersion";
|
||||
private static final String ELM_PREFIX_CUSTOM_TYPE_VARIANTS = "elmPrefixCustomTypeVariants";
|
||||
private static final String ELM_ENABLE_CUSTOM_BASE_PATHS = "elmEnableCustomBasePaths";
|
||||
private static final String ELM_ENABLE_HTTP_REQUEST_TRACKERS = "elmEnableHttpRequestTrackers";
|
||||
private static final String ENCODER = "elmEncoder"; // TODO: 5.0 Remove
|
||||
private static final String VENDOR_EXTENSION_ENCODER = "x-elm-encoder";
|
||||
private static final String DECODER = "elmDecoder"; // TODO: 5.0 Remove
|
||||
private static final String VENDOR_EXTENSION_DECODER = "x-elm-decoder";
|
||||
private static final String DISCRIMINATOR_NAME = "discriminatorName"; // TODO: 5.0 Remove
|
||||
private static final String VENDOR_EXTENSION_DISCRIMINATOR_NAME = "x-discriminator-name";
|
||||
private static final String CUSTOM_TYPE = "elmCustomType"; // TODO: 5.0 Remove
|
||||
private static final String VENDOR_EXTENSION_CUSTOM_TYPE = "x-elm-custom-type";
|
||||
>>>>>>> origin/master
|
||||
|
||||
protected String packageName = "openapi";
|
||||
protected String packageVersion = "1.0.0";
|
||||
@@ -263,7 +243,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@SuppressWarnings({"static-method", "unchecked"})
|
||||
<<<<<<< HEAD
|
||||
public Map<String, Object> postProcessAllModels(final Map<String, Object> orgObjs) {
|
||||
final Map<String, Object> objs = super.postProcessAllModels(orgObjs);
|
||||
|
||||
@@ -299,62 +278,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.map(v -> model.classname.equals(v) ? "Base" + v : v)
|
||||
.collect(Collectors.toSet());
|
||||
});
|
||||
=======
|
||||
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
|
||||
|
||||
// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
|
||||
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");
|
||||
|
||||
// Index all CodegenModels by model name.
|
||||
Map<String, CodegenModel> allModels = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : objs.entrySet()) {
|
||||
String modelName = toModelName(entry.getKey());
|
||||
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
|
||||
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
|
||||
for (Map<String, Object> mo : models) {
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
allModels.put(modelName, cm);
|
||||
}
|
||||
}
|
||||
// Let parent know about all its children
|
||||
for (CodegenModel cm : allModels.values()) {
|
||||
CodegenModel parent = allModels.get(cm.parent);
|
||||
|
||||
if (parent != null) {
|
||||
if (parent.children == null) {
|
||||
parent.children = new ArrayList<>();
|
||||
parent.hasChildren = true;
|
||||
}
|
||||
parent.children.add(cm);
|
||||
Collections.sort(parent.children, new Comparator<CodegenModel>() {
|
||||
@Override
|
||||
public int compare(CodegenModel cm1, CodegenModel cm2) {
|
||||
return Collator.getInstance(Locale.ROOT).compare(cm1.classname, cm2.classname);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
setCircularReferences(allModels);
|
||||
for (Map.Entry<String, Object> entry : objs.entrySet()) {
|
||||
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
|
||||
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
|
||||
for (Map<String, Object> mo : models) {
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
if (cm.isEnum) {
|
||||
addEncoderAndDecoder(cm.vendorExtensions, cm.classname, DataTypeExposure.EXPOSED);
|
||||
cm.vendorExtensions.put(CUSTOM_TYPE, cm.classname); // TODO: 5.0 Remove
|
||||
cm.vendorExtensions.put(VENDOR_EXTENSION_CUSTOM_TYPE, cm.classname);
|
||||
} else if (cm.isAlias) {
|
||||
addEncoderAndDecoder(cm.vendorExtensions, cm.dataType, DataTypeExposure.EXPOSED);
|
||||
}
|
||||
|
||||
List<ElmImport> elmImports = new ArrayList<>();
|
||||
for (CodegenProperty property : cm.allVars) {
|
||||
if (property.complexType != null) {
|
||||
final ElmImport elmImport = createImport(property.complexType);
|
||||
elmImports.add(elmImport);
|
||||
}
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
// remove *AllOf
|
||||
if (model.classname.endsWith("AllOf")) {
|
||||
@@ -363,7 +286,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
model.allOf.removeIf(name -> name.endsWith("AllOf"));
|
||||
return Stream.of(obj);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -386,23 +308,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
while (prop != null) {
|
||||
if (predicate.test(prop)) {
|
||||
return true;
|
||||
=======
|
||||
if (cm.discriminator != null && cm.children != null) {
|
||||
for (CodegenModel child : cm.children) {
|
||||
// add child imports
|
||||
final ElmImport elmImport = createImport(child.classname);
|
||||
elmImports.add(elmImport);
|
||||
|
||||
final String propertyName = cm.discriminator.getPropertyName();
|
||||
final List<CodegenProperty> allVars = child.allVars.stream()
|
||||
.filter(var -> !var.baseName.equals(propertyName))
|
||||
.collect(Collectors.toList());
|
||||
child.allVars.clear();
|
||||
child.allVars.addAll(allVars);
|
||||
|
||||
child.vendorExtensions.put(DISCRIMINATOR_NAME, propertyName); // TODO: 5.0 Remove
|
||||
child.vendorExtensions.put(VENDOR_EXTENSION_DISCRIMINATOR_NAME, propertyName);
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
prop = prop.items;
|
||||
}
|
||||
@@ -455,7 +360,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
operations.put("includeTime", includeTime);
|
||||
operations.put("includeUuid", includeUuid);
|
||||
|
||||
<<<<<<< HEAD
|
||||
return operations;
|
||||
}
|
||||
|
||||
@@ -463,34 +367,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public int compare(final CodegenParameter p1, final CodegenParameter p2) {
|
||||
return index(p1) - index(p2);
|
||||
}
|
||||
=======
|
||||
// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
|
||||
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");
|
||||
|
||||
final Set<String> dependencies = new HashSet<>();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
if (ElmVersion.ELM_018.equals(elmVersion)) { // elm 0.18
|
||||
String path = op.path;
|
||||
for (CodegenParameter param : op.pathParams) {
|
||||
final String var = paramToString("params", param, false, null);
|
||||
path = path.replace("{" + param.baseName + "}", "\" ++ " + var + " ++ \"");
|
||||
}
|
||||
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
|
||||
} else { // elm 0.19 or later
|
||||
final List<Object> pathParams = Arrays.asList(op.path.substring(1).split("/")).stream()
|
||||
.map(str -> {
|
||||
if (str.startsWith("{") && str.endsWith("}")) {
|
||||
return op.pathParams.stream().filter(p -> str.equals("{" + p.baseName + "}")).findFirst().orElse(null);
|
||||
} else {
|
||||
return "\"" + str + "\"";
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
op.vendorExtensions.put("pathParams", pathParams); // TODO: 5.0 Remove
|
||||
op.vendorExtensions.put("x-path-params", pathParams);
|
||||
}
|
||||
>>>>>>> origin/master
|
||||
|
||||
private int index(final CodegenParameter p) {
|
||||
if (p.isPathParam) {
|
||||
@@ -558,156 +434,10 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
private static class RemoveWhitespaceLambda implements Mustache.Lambda {
|
||||
@Override
|
||||
public void execute(final Template.Fragment fragment, final Writer writer) throws IOException {
|
||||
writer.write(fragment.execute().replaceAll("\\s+", ""));
|
||||
=======
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Schema p) {
|
||||
final CodegenProperty property = super.fromProperty(name, p);
|
||||
|
||||
// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
|
||||
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");
|
||||
|
||||
if (property.isEnum) {
|
||||
addEncoderAndDecoder(property.vendorExtensions, property.baseName, DataTypeExposure.INTERNAL);
|
||||
property.vendorExtensions.put(CUSTOM_TYPE, property.datatypeWithEnum); // TODO: 5.0 Remove
|
||||
property.vendorExtensions.put(VENDOR_EXTENSION_CUSTOM_TYPE, property.datatypeWithEnum);
|
||||
} else {
|
||||
final boolean isPrimitiveType = property.isMapContainer ? isPrimitiveDataType(property.dataType) : property.isPrimitiveType;
|
||||
addEncoderAndDecoder(property.vendorExtensions, property.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenResponse fromResponse(String responseCode, ApiResponse resp) {
|
||||
final CodegenResponse response = super.fromResponse(responseCode, resp);
|
||||
if (response.dataType != null) {
|
||||
final boolean isPrimitiveType = response.isMapContainer ? isPrimitiveDataType(response.dataType) : response.primitiveType;
|
||||
addEncoderAndDecoder(response.vendorExtensions, response.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
final boolean isPrimitiveType = parameter.isMapContainer ? isPrimitiveDataType(parameter.dataType) : parameter.isPrimitiveType;
|
||||
addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCodegenPropertyEnum(final CodegenProperty property) {
|
||||
super.updateCodegenPropertyEnum(property);
|
||||
if (!elmPrefixCustomTypeVariants) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, Object> allowableValues = property.allowableValues;
|
||||
if (allowableValues == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Map<String, Object>> enumVars = (ArrayList<Map<String, Object>>) allowableValues.get("enumVars");
|
||||
if (enumVars == null) {
|
||||
return;
|
||||
}
|
||||
final String prefix = toEnumName(property);
|
||||
for (Map<String, Object> enumVar : enumVars) {
|
||||
if (!enumVar.containsKey("_isPrefixed")) {
|
||||
enumVar.put("name", prefix + enumVar.get("name"));
|
||||
enumVar.put("_isPrefixed", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPrimitiveDataType(String dataType) {
|
||||
return languageSpecificPrimitives.contains(dataType);
|
||||
}
|
||||
|
||||
private void addEncoderAndDecoder(final Map<String, Object> vendorExtensions, final String dataType, final DataTypeExposure dataTypeExposure) {
|
||||
final String baseName = org.openapitools.codegen.utils.StringUtils.camelize(dataType, true);
|
||||
String encodeName;
|
||||
String decoderName;
|
||||
switch (dataTypeExposure) {
|
||||
case EXPOSED:
|
||||
decoderName = "decoder";
|
||||
encodeName = "encode";
|
||||
break;
|
||||
case INTERNAL:
|
||||
encodeName = "encode" + StringUtils.capitalize(baseName);
|
||||
decoderName = baseName + "Decoder";
|
||||
break;
|
||||
case EXTERNAL:
|
||||
encodeName = dataType + ".encode";
|
||||
decoderName = dataType + ".decoder";
|
||||
break;
|
||||
case PRIMITIVE:
|
||||
encodeName = "Encode." + baseName;
|
||||
decoderName = "Decode." + baseName;
|
||||
break;
|
||||
default:
|
||||
encodeName = "";
|
||||
decoderName = "";
|
||||
}
|
||||
|
||||
vendorExtensions.putIfAbsent(ENCODER, encodeName); // TODO: 5.0 Remove
|
||||
vendorExtensions.putIfAbsent(VENDOR_EXTENSION_ENCODER, encodeName);
|
||||
|
||||
vendorExtensions.putIfAbsent(DECODER, decoderName); // TODO: 5.0 Remove
|
||||
vendorExtensions.putIfAbsent(VENDOR_EXTENSION_DECODER, decoderName);
|
||||
}
|
||||
|
||||
private enum DataTypeExposure {
|
||||
EXPOSED,
|
||||
INTERNAL,
|
||||
EXTERNAL,
|
||||
PRIMITIVE
|
||||
}
|
||||
|
||||
private static class ElmImport {
|
||||
public String moduleName;
|
||||
public String as;
|
||||
public Set<String> exposures;
|
||||
public Boolean hasExposures;
|
||||
}
|
||||
|
||||
private enum ElmVersion {
|
||||
ELM_018,
|
||||
ELM_019
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String elmPostProcessFile = System.getenv("ELM_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(elmPostProcessFile)) {
|
||||
return; // skip if ELM_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with elm extension
|
||||
if ("elm".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
// e.g. elm-format -w yourcode.elm
|
||||
String command = elmPostProcessFile + " " + file.toString();
|
||||
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
module Api exposing
|
||||
( Request
|
||||
, request
|
||||
, send
|
||||
, sendWithCustomError
|
||||
, task
|
||||
, map
|
||||
, withBasePath
|
||||
, withTimeout
|
||||
, withTracker
|
||||
, withBearerToken
|
||||
, withHeader
|
||||
, withHeaders
|
||||
)
|
||||
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import Task
|
||||
import Url.Builder
|
||||
|
||||
|
||||
type Request a =
|
||||
Request
|
||||
{ method : String
|
||||
, headers : List Http.Header
|
||||
, basePath : String
|
||||
, pathParams : List String
|
||||
, queryParams : List Url.Builder.QueryParameter
|
||||
, body : Http.Body
|
||||
, decoder : Json.Decode.Decoder a
|
||||
, timeout : Maybe Float
|
||||
, tracker : Maybe String
|
||||
}
|
||||
|
||||
|
||||
request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Json.Encode.Value -> Json.Decode.Decoder a -> Request a
|
||||
request method path pathParams queryParams headerParams body decoder =
|
||||
Request
|
||||
{ method = method
|
||||
, headers = headers headerParams
|
||||
, basePath = "{{basePath}}"
|
||||
, pathParams = interpolatePath path pathParams
|
||||
, queryParams = queries queryParams
|
||||
, body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body)
|
||||
, decoder = decoder
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
send : (Result Http.Error a -> msg) -> Request a -> Cmd msg
|
||||
send toMsg req =
|
||||
sendWithCustomError identity toMsg req
|
||||
|
||||
|
||||
sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg
|
||||
sendWithCustomError mapError toMsg (Request req) =
|
||||
Http.request
|
||||
{ method = req.method
|
||||
, headers = req.headers
|
||||
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
|
||||
, body = req.body
|
||||
, expect = expectJson mapError toMsg req.decoder
|
||||
, timeout = req.timeout
|
||||
, tracker = req.tracker
|
||||
}
|
||||
|
||||
|
||||
task : Request a -> Task.Task Http.Error a
|
||||
task (Request req) =
|
||||
Http.task
|
||||
{ method = req.method
|
||||
, headers = req.headers
|
||||
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
|
||||
, body = req.body
|
||||
, resolver = jsonResolver req.decoder
|
||||
, timeout = req.timeout
|
||||
}
|
||||
|
||||
|
||||
map : (a -> b) -> Request a -> Request b
|
||||
map fn (Request req) =
|
||||
Request
|
||||
{ method = req.method
|
||||
, headers = req.headers
|
||||
, basePath = req.basePath
|
||||
, pathParams = req.pathParams
|
||||
, queryParams = req.queryParams
|
||||
, body = req.body
|
||||
, decoder = Json.Decode.map fn req.decoder
|
||||
, timeout = req.timeout
|
||||
, tracker = req.tracker
|
||||
}
|
||||
|
||||
withBasePath : String -> Request a -> Request a
|
||||
withBasePath basePath (Request req) =
|
||||
Request { req | basePath = basePath }
|
||||
|
||||
|
||||
withTimeout : Float -> Request a -> Request a
|
||||
withTimeout timeout (Request req) =
|
||||
Request { req | timeout = Just timeout }
|
||||
|
||||
|
||||
withTracker : String -> Request a -> Request a
|
||||
withTracker tracker (Request req) =
|
||||
Request { req | tracker = Just tracker }
|
||||
|
||||
|
||||
withBearerToken : String -> Request a -> Request a
|
||||
withBearerToken token (Request req) =
|
||||
Request { req | headers = Http.header "Authorization" ("Bearer " ++ token) :: req.headers }
|
||||
|
||||
|
||||
withHeader : String -> String -> Request a -> Request a
|
||||
withHeader key value (Request req) =
|
||||
Request { req | headers = req.headers ++ [ Http.header key value ] }
|
||||
|
||||
|
||||
withHeaders : List ( String, String ) -> Request a -> Request a
|
||||
withHeaders headers_ (Request req) =
|
||||
Request { req | headers = req.headers ++ headers (List.map (Tuple.mapSecond Just) headers_) }
|
||||
|
||||
|
||||
-- HELPER
|
||||
|
||||
|
||||
headers : List (String, Maybe String) -> List Http.Header
|
||||
headers =
|
||||
List.filterMap (\(key, value) -> Maybe.map (Http.header key) value)
|
||||
|
||||
|
||||
interpolatePath : String -> List ( String, String ) -> List String
|
||||
interpolatePath rawPath pathParams =
|
||||
let
|
||||
interpolate =
|
||||
(\(name, value) path -> String.replace ("{" ++ name ++ "}") value path)
|
||||
in
|
||||
List.foldl interpolate rawPath pathParams
|
||||
|> String.split "/"
|
||||
|> List.drop 1
|
||||
|
||||
|
||||
queries : List (String, Maybe String) -> List Url.Builder.QueryParameter
|
||||
queries =
|
||||
List.filterMap (\(key, value) -> Maybe.map (Url.Builder.string key) value)
|
||||
|
||||
|
||||
expectJson : (Http.Error -> e) -> (Result e a -> msg) -> Json.Decode.Decoder a -> Http.Expect msg
|
||||
expectJson mapError toMsg decoder =
|
||||
Http.expectStringResponse toMsg (Result.mapError mapError << decodeResponse decoder)
|
||||
|
||||
|
||||
jsonResolver : Json.Decode.Decoder a -> Http.Resolver Http.Error a
|
||||
jsonResolver decoder =
|
||||
Http.stringResolver (decodeResponse decoder)
|
||||
|
||||
|
||||
decodeResponse : Json.Decode.Decoder a -> Http.Response String -> Result Http.Error a
|
||||
decodeResponse decoder response =
|
||||
case response of
|
||||
Http.BadUrl_ url ->
|
||||
Err (Http.BadUrl url)
|
||||
|
||||
Http.Timeout_ ->
|
||||
Err Http.Timeout
|
||||
|
||||
Http.NetworkError_ ->
|
||||
Err Http.NetworkError
|
||||
|
||||
Http.BadStatus_ metadata _ ->
|
||||
Err (Http.BadStatus metadata.statusCode)
|
||||
|
||||
Http.GoodStatus_ _ body ->
|
||||
if String.isEmpty body then
|
||||
-- we might 'expect' no body if the return type is `()`
|
||||
case Json.Decode.decodeString decoder "{}" of
|
||||
Ok value ->
|
||||
Ok value
|
||||
|
||||
Err _ ->
|
||||
decodeBody decoder body
|
||||
|
||||
else
|
||||
decodeBody decoder body
|
||||
|
||||
|
||||
decodeBody : Json.Decode.Decoder a -> String -> Result Http.Error a
|
||||
decodeBody decoder body =
|
||||
case Json.Decode.decodeString decoder body of
|
||||
Ok value ->
|
||||
Ok value
|
||||
|
||||
Err err ->
|
||||
Err (Http.BadBody (Json.Decode.errorToString err))
|
||||
@@ -1,33 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
module Request.{{classname}} exposing ({{#operations}}{{#operation}}{{^-first}}, {{/-first}}{{operationId}}{{/operation}}{{/operations}})
|
||||
|
||||
{{>imports}}import Dict
|
||||
import Http
|
||||
import Json.Decode as Decode
|
||||
|
||||
|
||||
basePath : String
|
||||
basePath =
|
||||
"{{basePath}}"
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
|
||||
{{#notes}}
|
||||
{-| {{{notes}}}
|
||||
-}
|
||||
{{/notes}}
|
||||
{{operationId}} : {{#pathParams}}{{dataType}} -> {{/pathParams}}{{#bodyParam}}{{dataType}} -> {{/bodyParam}}Http.Request {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}}
|
||||
{{operationId}} {{#pathParams}}{{paramName}} {{/pathParams}}{{#bodyParam}}model {{/bodyParam}}=
|
||||
{ method = "{{httpMethod}}"
|
||||
, url = basePath ++ {{{path}}}
|
||||
, headers = []
|
||||
, body = {{#bodyParam}}Http.jsonBody <| {{vendorExtensions.x-elm-encoder}} model{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}}
|
||||
, expect = {{^responses}}Http.expectStringResponse (\_ -> Ok ()){{/responses}}{{#responses}}{{#-first}}{{^dataType}}Http.expectStringResponse (\_ -> Ok ()){{/dataType}}{{#dataType}}Http.expectJson {{#isMapContainer}}(Decode.dict {{/isMapContainer}}{{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{elmDecoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/dataType}}{{/-first}}{{/responses}}
|
||||
, timeout = Just 30000
|
||||
, withCredentials = False
|
||||
}
|
||||
|> Http.request
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
@@ -1,18 +1,9 @@
|
||||
<<<<<<< HEAD
|
||||
{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}{{enumName}}Decoder : Json.Decode.Decoder {{classname}}{{nameInCamelCase}}
|
||||
{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}{{enumName}}Decoder =
|
||||
Json.Decode.{{#isString}}string{{/isString}}{{^isString}}int{{/isString}}
|
||||
|> Json.Decode.andThen
|
||||
(\value ->
|
||||
case value of
|
||||
=======
|
||||
{{vendorExtensions.x-elm-decoder}} : Decoder {{vendorExtensions.x-elm-custom-type}}
|
||||
{{vendorExtensions.x-elm-decoder}} =
|
||||
Decode.string
|
||||
|> Decode.andThen
|
||||
(\str ->
|
||||
case str of
|
||||
>>>>>>> origin/master
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{name}}{{/isString}} ->
|
||||
|
||||
@@ -1,17 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
{{>customTypeToString}}
|
||||
{{#lambda.camelcase}}encode{{classname}}{{enumName}}{{/lambda.camelcase}} : {{classname}}{{enumName}} -> Json.Encode.Value
|
||||
{{#lambda.camelcase}}encode{{classname}}{{enumName}}{{/lambda.camelcase}} =
|
||||
{{#isString}} Json.Encode.string << stringFrom{{classname}}{{enumName}}{{/isString}}{{^isString}} Json.Encode.int << intFrom{{classname}}{{enumName}}{{/isString}}
|
||||
=======
|
||||
{{vendorExtensions.x-elm-encoder}} : {{vendorExtensions.x-elm-custom-type}} -> Encode.Value
|
||||
{{vendorExtensions.x-elm-encoder}} model =
|
||||
case model of
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{name}} ->
|
||||
Encode.string {{{value}}}
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
>>>>>>> origin/master
|
||||
{{#isString}} Json.Encode.string << stringFrom{{classname}}{{enumName}}{{/isString}}{{^isString}} Json.Encode.int << intFrom{{classname}}{{enumName}}{{/isString}}
|
||||
@@ -1,14 +1,10 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
<<<<<<< HEAD
|
||||
module Api.Data exposing
|
||||
{{#models}}{{#model}} {{#-first}}( {{/-first}}{{^-first}}, {{/-first}}{{classname}}{{#discriminator}}(..){{/discriminator}}{{^discriminator}}{{#oneOf}}{{#-first}}(..){{/-first}}{{/oneOf}}{{/discriminator}}{{#isEnum}}(..), {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Variants{{/isEnum}}{{^isEnum}}{{#vars}}{{#isCircularReference}}, {{classname}}{{nameInCamelCase}}(..){{/isCircularReference}}{{#isEnum}}, {{classname}}{{nameInCamelCase}}(..), {{#lambda.camelcase}}{{classname}}{{nameInCamelCase}}{{/lambda.camelcase}}Variants{{/isEnum}}{{/vars}}{{/isEnum}}
|
||||
{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}encode{{classname}}{{/lambda.camelcase}}
|
||||
{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder
|
||||
{{/model}}{{/models}} )
|
||||
=======
|
||||
module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.x-elm-custom-type}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, decoder, encode{{^isEnum}}{{^discriminator}}{{^oneOf}}, encodeWithTag{{/oneOf}}{{/discriminator}}{{/isEnum}}, toString{{/model}}{{/models}})
|
||||
>>>>>>> origin/master
|
||||
|
||||
import Api{{#includeTime}}
|
||||
import Api.Time exposing (Posix){{/includeTime}}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
type alias {{classname}} =
|
||||
{{parent}}
|
||||
|
||||
|
||||
decoder : Decoder {{classname}}
|
||||
decoder =
|
||||
Decode.list {{vendorExtensions.x-elm-decoder}}
|
||||
|
||||
|
||||
encode : {{classname}} -> Encode.Value
|
||||
encode items =
|
||||
Encode.list {{#isElm018}}(List.map {{/isElm018}}{{vendorExtensions.x-elm-encoder}} items{{#isElm018}}){{/isElm018}}
|
||||
|
||||
|
||||
toString : {{classname}} -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
@@ -1,17 +0,0 @@
|
||||
type alias {{classname}}
|
||||
= {{dataType}}
|
||||
|
||||
|
||||
decoder : Decoder {{classname}}
|
||||
decoder =
|
||||
{{vendorExtensions.x-elm-decoder}}
|
||||
|
||||
|
||||
encode : {{classname}} -> Encode.Value
|
||||
encode =
|
||||
{{vendorExtensions.x-elm-encoder}}
|
||||
|
||||
|
||||
toString : {{classname}} -> String
|
||||
toString =
|
||||
{{>toString}}
|
||||
@@ -1,5 +1 @@
|
||||
<<<<<<< HEAD
|
||||
{{#isListContainer}}(Json.Decode.list {{/isListContainer}}{{#isMapContainer}}(Json.Decode.dict {{/isMapContainer}}{{#items}}{{>recordFieldValueDecoder}}{{/items}}{{^isContainer}}{{#isCircularReference}}(Json.Decode.lazy (\_ -> {{/isCircularReference}}{{>fieldDecoder}}{{#isCircularReference}})){{/isCircularReference}}{{/isContainer}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}
|
||||
=======
|
||||
{{#isNullable}}(Decode.nullable {{/isNullable}}{{#isContainer}}({{#isListContainer}}Decode.list{{/isListContainer}}{{#isMapContainer}}Decode.dict{{/isMapContainer}} {{#items}}{{>recordFieldValueDecoder}}{{/items}}){{/isContainer}}{{^isContainer}}{{vendorExtensions.x-elm-decoder}}{{/isContainer}}{{#isNullable}}){{^required}} {{{defaultValue}}}{{/required}}{{/isNullable}}
|
||||
>>>>>>> origin/master
|
||||
{{#isListContainer}}(Json.Decode.list {{/isListContainer}}{{#isMapContainer}}(Json.Decode.dict {{/isMapContainer}}{{#items}}{{>recordFieldValueDecoder}}{{/items}}{{^isContainer}}{{#isCircularReference}}(Json.Decode.lazy (\_ -> {{/isCircularReference}}{{>fieldDecoder}}{{#isCircularReference}})){{/isCircularReference}}{{/isContainer}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}
|
||||
@@ -1,5 +1 @@
|
||||
<<<<<<< HEAD
|
||||
{{#isContainer}}({{#isListContainer}}Json.Encode.list{{/isListContainer}}{{#isMapContainer}}Json.Encode.dict identity{{/isMapContainer}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}}
|
||||
=======
|
||||
{{#isNullable}}Maybe.withDefault Encode.null (Maybe.map {{/isNullable}}{{#isContainer}}({{#isListContainer}}Encode.list{{#isElm018}} << List.map{{/isElm018}}{{/isListContainer}}{{#isMapContainer}}Encode.dict identity{{/isMapContainer}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{vendorExtensions.x-elm-encoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}}
|
||||
>>>>>>> origin/master
|
||||
{{#isContainer}}({{#isListContainer}}Json.Encode.list{{/isListContainer}}{{#isMapContainer}}Json.Encode.dict identity{{/isMapContainer}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}}
|
||||
Reference in New Issue
Block a user