forked from loafle/openapi-generator-original
[elm] Add support for sending headers (#1704)
This commit is contained in:
parent
321416e960
commit
a0e5b74b2b
@ -447,7 +447,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (ElmVersion.ELM_018.equals(elmVersion)) {
|
||||
String path = op.path;
|
||||
for (CodegenParameter param : op.pathParams) {
|
||||
final String var = paramToString(param, false, null);
|
||||
final String var = paramToString("params", param, false, null);
|
||||
path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \"");
|
||||
hasDateTime = hasDateTime || param.isDateTime;
|
||||
hasDate = hasDate || param.isDate;
|
||||
@ -457,7 +457,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
final List<String> paths = Arrays.asList(op.path.substring(1).split("/"));
|
||||
String path = paths.stream().map(str -> str.charAt(0) == '{' ? str : "\"" + str + "\"").collect(Collectors.joining(", "));
|
||||
for (CodegenParameter param : op.pathParams) {
|
||||
String str = paramToString(param, false, null);
|
||||
String str = paramToString("params", param, false, null);
|
||||
path = path.replace("{" + param.paramName + "}", str);
|
||||
hasDateTime = hasDateTime || param.isDateTime;
|
||||
hasDate = hasDate || param.isDate;
|
||||
@ -465,10 +465,15 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
op.path = path;
|
||||
|
||||
final String query = op.queryParams.stream()
|
||||
.map(param -> paramToString(param, true, "Url.string \"" + param.paramName + "\""))
|
||||
.map(param -> paramToString("params", param, true, "Url.string \"" + param.baseName + "\""))
|
||||
.collect(Collectors.joining(", "));
|
||||
op.vendorExtensions.put("query", query);
|
||||
// TODO headers
|
||||
|
||||
final String headers = op.headerParams.stream()
|
||||
.map(param -> paramToString("headers", param, true, "Http.header \"" + param.baseName + "\""))
|
||||
.collect(Collectors.joining(", "));
|
||||
op.vendorExtensions.put("headers", headers);
|
||||
// TODO cookies
|
||||
// TODO forms
|
||||
}
|
||||
|
||||
@ -563,8 +568,8 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return "(Just " + value + ")";
|
||||
}
|
||||
|
||||
private String paramToString(final CodegenParameter param, final boolean useMaybe, final String maybeMapResult) {
|
||||
final String paramName = (ElmVersion.ELM_018.equals(elmVersion) ? "" : "params.") + param.paramName;
|
||||
private String paramToString(final String prefix, final CodegenParameter param, final boolean useMaybe, final String maybeMapResult) {
|
||||
final String paramName = (ElmVersion.ELM_018.equals(elmVersion) ? "" : prefix + ".") + param.paramName;
|
||||
if (!useMaybe) {
|
||||
param.required = true;
|
||||
}
|
||||
@ -601,11 +606,15 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
String mapResult = "";
|
||||
if (maybeMapResult != null) {
|
||||
mapResult = maybeMapResult + (param.required ? " <|" : " <<");
|
||||
if (mapFn == "") {
|
||||
mapResult = maybeMapResult;
|
||||
} else {
|
||||
mapResult = maybeMapResult + (param.required ? " <|" : " <<");
|
||||
}
|
||||
}
|
||||
final String just = useMaybe ? "Just (" : "";
|
||||
final String justEnd = useMaybe ? ")" : "";
|
||||
return (param.required ? just : "Maybe.map") + mapResult + " " + mapFn + " " + paramName + (param.required ? justEnd : "");
|
||||
return (param.required ? just : "Maybe.map (") + mapResult + " " + mapFn + (param.required ? " " : ") ") + paramName + (param.required ? justEnd : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,10 @@ basePath =
|
||||
-}
|
||||
{{/notes}}
|
||||
{{operationId}} :
|
||||
{{#headerParams}}
|
||||
{{#-first}} { {{/-first}}{{^-first}} , {{/-first}}{{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{dataType}}{{^required}}){{/required}}
|
||||
{{#-last}} } -> {{/-last}}
|
||||
{{/headerParams}}
|
||||
{ onSend : Result Http.Error {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}} -> msg
|
||||
{{#enableCustomBasePaths}} , basePath : String{{/enableCustomBasePaths}}
|
||||
{{#enableHttpRequestTrackers}} , tracker : Maybe String{{/enableHttpRequestTrackers}}
|
||||
@ -29,13 +33,13 @@ basePath =
|
||||
{{#queryParams}} , {{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{dataType}}{{^required}}){{/required}}{{/queryParams}}
|
||||
}
|
||||
-> Cmd msg
|
||||
{{operationId}} params =
|
||||
{{operationId}} {{#headerParams.0}}headers {{/headerParams.0}}params =
|
||||
Http.request
|
||||
{ method = "{{httpMethod}}"
|
||||
, headers = []
|
||||
, headers = {{#headerParams.0}}List.filterMap identity {{/headerParams.0}}[{{{vendorExtensions.headers}}}]
|
||||
, url = Url.crossOrigin {{#enableCustomBasePaths}}params.{{/enableCustomBasePaths}}basePath
|
||||
[{{{path}}}]
|
||||
(List.filterMap identity [{{{vendorExtensions.query}}}])
|
||||
{{#queryParams.0}}(List.filterMap identity {{/queryParams.0}}[{{{vendorExtensions.query}}}]{{#queryParams.0}}){{/queryParams.0}}
|
||||
, body = {{#bodyParam}}{{^required}}Maybe.withDefault Http.emptyBody <| Maybe.map ({{/required}}Http.jsonBody {{#required}}<|{{/required}}{{^required}}<<{{/required}} {{vendorExtensions.elmEncoder}}{{^required}}){{/required}} params.body{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}}
|
||||
, expect = {{^responses}}Http.expectWhatever params.onSend{{/responses}}{{#responses}}{{#-first}}{{^dataType}}Http.expectWhatever params.onSend{{/dataType}}{{#dataType}}Http.expectJson params.onSend {{#isMapContainer}}(Decode.dict {{/isMapContainer}}{{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{elmDecoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/dataType}}{{/-first}}{{/responses}}
|
||||
, timeout = Just 30000
|
||||
|
@ -37,7 +37,7 @@ addPet params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "pet" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| Pet.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -46,18 +46,21 @@ addPet params =
|
||||
|
||||
|
||||
deletePet :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
, petId : Int
|
||||
{ apiKey : Maybe String
|
||||
}
|
||||
->
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
, petId : Int
|
||||
}
|
||||
-> Cmd msg
|
||||
deletePet params =
|
||||
deletePet headers params =
|
||||
Http.request
|
||||
{ method = "DELETE"
|
||||
, headers = []
|
||||
, headers = List.filterMap identity [ Maybe.map (Http.header "api_key") headers.apiKey ]
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "pet", String.fromInt params.petId ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -123,7 +126,7 @@ getPetById params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "pet", String.fromInt params.petId ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend Pet.decoder
|
||||
, timeout = Just 30000
|
||||
@ -143,7 +146,7 @@ updatePet params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "pet" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| Pet.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -163,7 +166,7 @@ updatePetWithForm params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "pet", String.fromInt params.petId ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -183,7 +186,7 @@ uploadFile params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "pet", String.fromInt params.petId, "uploadImage" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend ApiResponse.decoder
|
||||
, timeout = Just 30000
|
||||
|
@ -38,7 +38,7 @@ deleteOrder params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "store", "order", params.orderId ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -59,7 +59,7 @@ getInventory params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "store", "inventory" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend (Decode.dict Decode.int)
|
||||
, timeout = Just 30000
|
||||
@ -81,7 +81,7 @@ getOrderById params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "store", "order", String.fromInt params.orderId ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend Order_.decoder
|
||||
, timeout = Just 30000
|
||||
@ -101,7 +101,7 @@ placeOrder params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "store", "order" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| Order_.encode params.body
|
||||
, expect = Http.expectJson params.onSend Order_.decoder
|
||||
, timeout = Just 30000
|
||||
|
@ -38,7 +38,7 @@ createUser params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -58,7 +58,7 @@ createUsersWithArrayInput params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", "createWithArray" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -78,7 +78,7 @@ createUsersWithListInput params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", "createWithList" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -100,7 +100,7 @@ deleteUser params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", params.username ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -120,7 +120,7 @@ getUserByName params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", params.username ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend User.decoder
|
||||
, timeout = Just 30000
|
||||
@ -141,7 +141,7 @@ loginUser params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", "login" ]
|
||||
(List.filterMap identity [ Just (Url.string "username" <| params.username), Just (Url.string "password" <| params.password) ])
|
||||
(List.filterMap identity [ Just (Url.string "username" params.username), Just (Url.string "password" params.password) ])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend Decode.string
|
||||
, timeout = Just 30000
|
||||
@ -160,7 +160,7 @@ logoutUser params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", "logout" ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
@ -183,7 +183,7 @@ updateUser params =
|
||||
, url =
|
||||
Url.crossOrigin basePath
|
||||
[ "user", params.username ]
|
||||
(List.filterMap identity [])
|
||||
[]
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
|
Loading…
x
Reference in New Issue
Block a user