From ef7858ed84087a42d6e88e96721a91f86137cfb1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 10 Oct 2019 11:50:07 +0800 Subject: [PATCH 1/4] fix NPE in elm path parameter --- bin/utils/ensure-up-to-date | 2 +- .../codegen/languages/ElmClientCodegen.java | 54 ++++----- .../elm-0.18/.openapi-generator/VERSION | 2 +- .../elm-0.18/src/Data/ApiResponse.elm | 13 +-- .../petstore/elm-0.18/src/Data/Category.elm | 11 +- .../petstore/elm-0.18/src/Data/Order_.elm | 23 +--- .../client/petstore/elm-0.18/src/Data/Pet.elm | 21 +--- .../client/petstore/elm-0.18/src/Data/Tag.elm | 11 +- .../petstore/elm-0.18/src/Data/User.elm | 23 ++-- .../client/petstore/elm-0.18/src/DateTime.elm | 2 +- .../petstore/elm-0.18/src/Request/Pet.elm | 10 +- .../petstore/elm-0.18/src/Request/Store.elm | 4 +- .../petstore/elm-0.18/src/Request/User.elm | 6 +- .../petstore/elm/.openapi-generator/VERSION | 2 +- .../petstore/elm/src/Data/ApiResponse.elm | 13 +-- .../client/petstore/elm/src/Data/Category.elm | 11 +- .../client/petstore/elm/src/Data/Order_.elm | 23 +--- samples/client/petstore/elm/src/Data/Pet.elm | 23 +--- samples/client/petstore/elm/src/Data/Tag.elm | 11 +- samples/client/petstore/elm/src/Data/User.elm | 23 ++-- samples/client/petstore/elm/src/DateTime.elm | 2 +- .../client/petstore/elm/src/Request/Pet.elm | 107 +++++++----------- .../client/petstore/elm/src/Request/Store.elm | 47 +++----- .../client/petstore/elm/src/Request/User.elm | 93 ++++++--------- 24 files changed, 186 insertions(+), 351 deletions(-) diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date index 8e7a87f014d4..3251835821d0 100755 --- a/bin/utils/ensure-up-to-date +++ b/bin/utils/ensure-up-to-date @@ -68,7 +68,7 @@ declare -a scripts=( "./bin/dart-petstore.sh" "./bin/dart2-petstore.sh" "./bin/java-play-framework-petstore-server-all.sh" -#"./bin/elm-petstore-all.sh" +"./bin/elm-petstore-all.sh" "./bin/meta-codegen.sh" # OTHERS "./bin/utils/export_docs_generators.sh" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 76c9c38f4806..a4d099f59e52 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -381,8 +381,8 @@ public int compare(CodegenModel cm1, CodegenModel cm2) { final String propertyName = cm.discriminator.getPropertyName(); final List allVars = child.allVars.stream() - .filter(var -> !var.baseName.equals(propertyName)) - .collect(Collectors.toList()); + .filter(var -> !var.baseName.equals(propertyName)) + .collect(Collectors.toList()); child.allVars.clear(); child.allVars.addAll(allVars); @@ -415,17 +415,17 @@ public Map postProcessModels(Map objs) { } private static boolean anyOperationParam(final List operations, final Predicate predicate) { - return operations.stream() - .flatMap(operation -> Stream.of( - operation.bodyParams.stream(), - operation.queryParams.stream(), - operation.pathParams.stream(), - operation.headerParams.stream() - )) - .flatMap(a -> a) - .filter(predicate) - .findAny() - .isPresent(); + return operations.stream() + .flatMap(operation -> Stream.of( + operation.bodyParams.stream(), + operation.queryParams.stream(), + operation.pathParams.stream(), + operation.headerParams.stream() + )) + .flatMap(a -> a) + .filter(predicate) + .findAny() + .isPresent(); } @Override @@ -437,23 +437,23 @@ public Map postProcessOperationsWithModels(Map o final Set dependencies = new HashSet<>(); for (CodegenOperation op : ops) { - if (ElmVersion.ELM_018.equals(elmVersion)) { + 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.paramName + "}", "\" ++ " + var + " ++ \""); } op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", ""); - } else { + } else { // elm 0.19 or later final List 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.paramName + "}")).findFirst().orElse(null); - } else { - return "\"" + str + "\""; - } - }) - .collect(Collectors.toList()); + .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); } @@ -737,10 +737,10 @@ private void addEncoderAndDecoder(final Map vendorExtensions, fi } private enum DataTypeExposure { - EXPOSED, - INTERNAL, - EXTERNAL, - PRIMITIVE + EXPOSED, + INTERNAL, + EXTERNAL, + PRIMITIVE } private static class ElmImport { diff --git a/samples/client/petstore/elm-0.18/.openapi-generator/VERSION b/samples/client/petstore/elm-0.18/.openapi-generator/VERSION index 0e97bd19efbf..c3a2c7076fa8 100644 --- a/samples/client/petstore/elm-0.18/.openapi-generator/VERSION +++ b/samples/client/petstore/elm-0.18/.openapi-generator/VERSION @@ -1 +1 @@ -4.1.3-SNAPSHOT \ No newline at end of file +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm b/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm index 3d5fb6f318b4..1e5d44b79417 100644 --- a/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm +++ b/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm @@ -21,9 +21,9 @@ import Json.Encode as Encode {-| Describes the result of uploading an image resource -} type alias ApiResponse = - { code : Maybe (Int) - , type_ : Maybe (String) - , message : Maybe (String) + { code : Maybe Int + , type_ : Maybe String + , message : Maybe String } @@ -35,22 +35,15 @@ decoder = |> optional "message" (Decode.nullable Decode.string) Nothing - encode : ApiResponse -> Encode.Value encode model = Encode.object [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) - ] - toString : ApiResponse -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm-0.18/src/Data/Category.elm b/samples/client/petstore/elm-0.18/src/Data/Category.elm index 432caee0d413..f8e5a7fb31d6 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Category.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Category.elm @@ -21,8 +21,8 @@ import Json.Encode as Encode {-| A category for a pet -} type alias Category = - { id : Maybe (Int) - , name : Maybe (String) + { id : Maybe Int + , name : Maybe String } @@ -33,21 +33,14 @@ decoder = |> optional "name" (Decode.nullable Decode.string) Nothing - encode : Category -> Encode.Value encode model = Encode.object [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) - ] - toString : Category -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm-0.18/src/Data/Order_.elm b/samples/client/petstore/elm-0.18/src/Data/Order_.elm index dd2955a7d15d..0d8e87810983 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Order_.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Order_.elm @@ -22,12 +22,12 @@ import Json.Encode as Encode {-| An order for a pets from the pet store -} type alias Order_ = - { id : Maybe (Int) - , petId : Maybe (Int) - , quantity : Maybe (Int) - , shipDate : Maybe (DateTime) - , status : Maybe (Status) - , complete : Maybe (Bool) + { id : Maybe Int + , petId : Maybe Int + , quantity : Maybe Int + , shipDate : Maybe DateTime + , status : Maybe Status + , complete : Maybe Bool } @@ -37,7 +37,6 @@ type Status | Delivered - decoder : Decoder Order_ decoder = decode Order_ @@ -49,7 +48,6 @@ decoder = |> optional "complete" (Decode.nullable Decode.bool) (Just False) - encode : Order_ -> Encode.Value encode model = Encode.object @@ -59,18 +57,14 @@ encode model = , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) - ] - toString : Order_ -> String toString = Encode.encode 0 << encode - - statusDecoder : Decoder Status statusDecoder = Decode.string @@ -91,7 +85,6 @@ statusDecoder = ) - encodeStatus : Status -> Encode.Value encodeStatus model = case model of @@ -103,7 +96,3 @@ encodeStatus model = Delivered -> Encode.string "delivered" - - - - diff --git a/samples/client/petstore/elm-0.18/src/Data/Pet.elm b/samples/client/petstore/elm-0.18/src/Data/Pet.elm index 900d2678294d..50f39279e10e 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Pet.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Pet.elm @@ -23,12 +23,12 @@ import Json.Encode as Encode {-| A pet for sale in the pet store -} type alias Pet = - { id : Maybe (Int) - , category : Maybe (Category) + { id : Maybe Int + , category : Maybe Category , name : String - , photoUrls : (List String) - , tags : Maybe ((List Tag)) - , status : Maybe (Status) + , photoUrls : List String + , tags : Maybe (List Tag) + , status : Maybe Status } @@ -38,7 +38,6 @@ type Status | Sold - decoder : Decoder Pet decoder = decode Pet @@ -50,7 +49,6 @@ decoder = |> optional "status" (Decode.nullable statusDecoder) Nothing - encode : Pet -> Encode.Value encode model = Encode.object @@ -60,18 +58,14 @@ encode model = , ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls ) , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list << List.map Tag.encode) model.tags) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - ] - toString : Pet -> String toString = Encode.encode 0 << encode - - statusDecoder : Decoder Status statusDecoder = Decode.string @@ -92,7 +86,6 @@ statusDecoder = ) - encodeStatus : Status -> Encode.Value encodeStatus model = case model of @@ -104,7 +97,3 @@ encodeStatus model = Sold -> Encode.string "sold" - - - - diff --git a/samples/client/petstore/elm-0.18/src/Data/Tag.elm b/samples/client/petstore/elm-0.18/src/Data/Tag.elm index 6c448df13575..81b9407409ba 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Tag.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Tag.elm @@ -21,8 +21,8 @@ import Json.Encode as Encode {-| A tag for a pet -} type alias Tag = - { id : Maybe (Int) - , name : Maybe (String) + { id : Maybe Int + , name : Maybe String } @@ -33,21 +33,14 @@ decoder = |> optional "name" (Decode.nullable Decode.string) Nothing - encode : Tag -> Encode.Value encode model = Encode.object [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) - ] - toString : Tag -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm-0.18/src/Data/User.elm b/samples/client/petstore/elm-0.18/src/Data/User.elm index d777b7369955..5b27dc8e183b 100644 --- a/samples/client/petstore/elm-0.18/src/Data/User.elm +++ b/samples/client/petstore/elm-0.18/src/Data/User.elm @@ -21,14 +21,14 @@ import Json.Encode as Encode {-| A User who is purchasing from the pet store -} type alias User = - { id : Maybe (Int) - , username : Maybe (String) - , firstName : Maybe (String) - , lastName : Maybe (String) - , email : Maybe (String) - , password : Maybe (String) - , phone : Maybe (String) - , userStatus : Maybe (Int) + { id : Maybe Int + , username : Maybe String + , firstName : Maybe String + , lastName : Maybe String + , email : Maybe String + , password : Maybe String + , phone : Maybe String + , userStatus : Maybe Int } @@ -45,7 +45,6 @@ decoder = |> optional "userStatus" (Decode.nullable Decode.int) Nothing - encode : User -> Encode.Value encode model = Encode.object @@ -57,15 +56,9 @@ encode model = , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) - ] - toString : User -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm-0.18/src/DateTime.elm b/samples/client/petstore/elm-0.18/src/DateTime.elm index 6a20f0482a1c..7e07312468c6 100644 --- a/samples/client/petstore/elm-0.18/src/DateTime.elm +++ b/samples/client/petstore/elm-0.18/src/DateTime.elm @@ -34,4 +34,4 @@ decodeIsoString str = toString : DateTime -> String toString = - toIsoString \ No newline at end of file + toIsoString diff --git a/samples/client/petstore/elm-0.18/src/Request/Pet.elm b/samples/client/petstore/elm-0.18/src/Request/Pet.elm index 5b1e3444d3a0..a1117a57d5c4 100644 --- a/samples/client/petstore/elm-0.18/src/Request/Pet.elm +++ b/samples/client/petstore/elm-0.18/src/Request/Pet.elm @@ -12,8 +12,8 @@ module Request.Pet exposing (addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) -import Data.Pet as Pet exposing (Pet) import Data.ApiResponse as ApiResponse exposing (ApiResponse) +import Data.Pet as Pet exposing (Pet) import Dict import Http import Json.Decode as Decode @@ -40,7 +40,7 @@ addPet model = deletePet : Int -> Http.Request () deletePet petId = { method = "DELETE" - , url = basePath ++ "/pet/" ++ toString petId + , url = basePath ++ "/pet/" ++ toString petId , headers = [] , body = Http.emptyBody , expect = Http.expectStringResponse (\_ -> Ok ()) @@ -85,7 +85,7 @@ findPetsByTags = getPetById : Int -> Http.Request Pet getPetById petId = { method = "GET" - , url = basePath ++ "/pet/" ++ toString petId + , url = basePath ++ "/pet/" ++ toString petId , headers = [] , body = Http.emptyBody , expect = Http.expectJson Pet.decoder @@ -111,7 +111,7 @@ updatePet model = updatePetWithForm : Int -> Http.Request () updatePetWithForm petId = { method = "POST" - , url = basePath ++ "/pet/" ++ toString petId + , url = basePath ++ "/pet/" ++ toString petId , headers = [] , body = Http.emptyBody , expect = Http.expectStringResponse (\_ -> Ok ()) @@ -124,7 +124,7 @@ updatePetWithForm petId = uploadFile : Int -> Http.Request ApiResponse uploadFile petId = { method = "POST" - , url = basePath ++ "/pet/" ++ toString petId ++ "/uploadImage" + , url = basePath ++ "/pet/" ++ toString petId ++ "/uploadImage" , headers = [] , body = Http.emptyBody , expect = Http.expectJson ApiResponse.decoder diff --git a/samples/client/petstore/elm-0.18/src/Request/Store.elm b/samples/client/petstore/elm-0.18/src/Request/Store.elm index d8f70f4177c3..2f44d25c42a9 100644 --- a/samples/client/petstore/elm-0.18/src/Request/Store.elm +++ b/samples/client/petstore/elm-0.18/src/Request/Store.elm @@ -28,7 +28,7 @@ basePath = deleteOrder : String -> Http.Request () deleteOrder orderId = { method = "DELETE" - , url = basePath ++ "/store/order/" ++ orderId + , url = basePath ++ "/store/order/" ++ orderId , headers = [] , body = Http.emptyBody , expect = Http.expectStringResponse (\_ -> Ok ()) @@ -58,7 +58,7 @@ getInventory = getOrderById : Int -> Http.Request Order_ getOrderById orderId = { method = "GET" - , url = basePath ++ "/store/order/" ++ toString orderId + , url = basePath ++ "/store/order/" ++ toString orderId , headers = [] , body = Http.emptyBody , expect = Http.expectJson Order_.decoder diff --git a/samples/client/petstore/elm-0.18/src/Request/User.elm b/samples/client/petstore/elm-0.18/src/Request/User.elm index ce6b79ca6309..a7d142cfc0c3 100644 --- a/samples/client/petstore/elm-0.18/src/Request/User.elm +++ b/samples/client/petstore/elm-0.18/src/Request/User.elm @@ -69,7 +69,7 @@ createUsersWithListInput model = deleteUser : String -> Http.Request () deleteUser username = { method = "DELETE" - , url = basePath ++ "/user/" ++ username + , url = basePath ++ "/user/" ++ username , headers = [] , body = Http.emptyBody , expect = Http.expectStringResponse (\_ -> Ok ()) @@ -82,7 +82,7 @@ deleteUser username = getUserByName : String -> Http.Request User getUserByName username = { method = "GET" - , url = basePath ++ "/user/" ++ username + , url = basePath ++ "/user/" ++ username , headers = [] , body = Http.emptyBody , expect = Http.expectJson User.decoder @@ -123,7 +123,7 @@ logoutUser = updateUser : String -> User -> Http.Request () updateUser username model = { method = "PUT" - , url = basePath ++ "/user/" ++ username + , url = basePath ++ "/user/" ++ username , headers = [] , body = Http.jsonBody <| User.encode model , expect = Http.expectStringResponse (\_ -> Ok ()) diff --git a/samples/client/petstore/elm/.openapi-generator/VERSION b/samples/client/petstore/elm/.openapi-generator/VERSION index 0e97bd19efbf..c3a2c7076fa8 100644 --- a/samples/client/petstore/elm/.openapi-generator/VERSION +++ b/samples/client/petstore/elm/.openapi-generator/VERSION @@ -1 +1 @@ -4.1.3-SNAPSHOT \ No newline at end of file +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/elm/src/Data/ApiResponse.elm b/samples/client/petstore/elm/src/Data/ApiResponse.elm index 0ae1cebf2e1f..08199cab32f7 100644 --- a/samples/client/petstore/elm/src/Data/ApiResponse.elm +++ b/samples/client/petstore/elm/src/Data/ApiResponse.elm @@ -21,9 +21,9 @@ import Json.Encode as Encode {-| Describes the result of uploading an image resource -} type alias ApiResponse = - { code : Maybe (Int) - , type_ : Maybe (String) - , message : Maybe (String) + { code : Maybe Int + , type_ : Maybe String + , message : Maybe String } @@ -35,22 +35,15 @@ decoder = |> optional "message" (Decode.nullable Decode.string) Nothing - encode : ApiResponse -> Encode.Value encode model = Encode.object [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) - ] - toString : ApiResponse -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm/src/Data/Category.elm b/samples/client/petstore/elm/src/Data/Category.elm index 7360502a7e72..cd1778b8703e 100644 --- a/samples/client/petstore/elm/src/Data/Category.elm +++ b/samples/client/petstore/elm/src/Data/Category.elm @@ -21,8 +21,8 @@ import Json.Encode as Encode {-| A category for a pet -} type alias Category = - { id : Maybe (Int) - , name : Maybe (String) + { id : Maybe Int + , name : Maybe String } @@ -33,21 +33,14 @@ decoder = |> optional "name" (Decode.nullable Decode.string) Nothing - encode : Category -> Encode.Value encode model = Encode.object [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) - ] - toString : Category -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm/src/Data/Order_.elm b/samples/client/petstore/elm/src/Data/Order_.elm index 1a5e64c608dc..aff082a6f677 100644 --- a/samples/client/petstore/elm/src/Data/Order_.elm +++ b/samples/client/petstore/elm/src/Data/Order_.elm @@ -22,12 +22,12 @@ import Json.Encode as Encode {-| An order for a pets from the pet store -} type alias Order_ = - { id : Maybe (Int) - , petId : Maybe (Int) - , quantity : Maybe (Int) - , shipDate : Maybe (DateTime) - , status : Maybe (Status) - , complete : Maybe (Bool) + { id : Maybe Int + , petId : Maybe Int + , quantity : Maybe Int + , shipDate : Maybe DateTime + , status : Maybe Status + , complete : Maybe Bool } @@ -37,7 +37,6 @@ type Status | Delivered - decoder : Decoder Order_ decoder = Decode.succeed Order_ @@ -49,7 +48,6 @@ decoder = |> optional "complete" (Decode.nullable Decode.bool) (Just False) - encode : Order_ -> Encode.Value encode model = Encode.object @@ -59,18 +57,14 @@ encode model = , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) - ] - toString : Order_ -> String toString = Encode.encode 0 << encode - - statusDecoder : Decoder Status statusDecoder = Decode.string @@ -91,7 +85,6 @@ statusDecoder = ) - encodeStatus : Status -> Encode.Value encodeStatus model = case model of @@ -103,7 +96,3 @@ encodeStatus model = Delivered -> Encode.string "delivered" - - - - diff --git a/samples/client/petstore/elm/src/Data/Pet.elm b/samples/client/petstore/elm/src/Data/Pet.elm index 5a542e6188e6..f024b79c80f6 100644 --- a/samples/client/petstore/elm/src/Data/Pet.elm +++ b/samples/client/petstore/elm/src/Data/Pet.elm @@ -23,12 +23,12 @@ import Json.Encode as Encode {-| A pet for sale in the pet store -} type alias Pet = - { id : Maybe (Int) - , category : Maybe (Category) + { id : Maybe Int + , category : Maybe Category , name : String - , photoUrls : (List String) - , tags : Maybe ((List Tag)) - , status : Maybe (Status) + , photoUrls : List String + , tags : Maybe (List Tag) + , status : Maybe Status } @@ -38,7 +38,6 @@ type Status | Sold - decoder : Decoder Pet decoder = Decode.succeed Pet @@ -50,28 +49,23 @@ decoder = |> optional "status" (Decode.nullable statusDecoder) Nothing - encode : Pet -> Encode.Value encode model = Encode.object [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) , ( "name", Encode.string model.name ) - , ( "photoUrls", (Encode.list Encode.string) model.photoUrls ) + , ( "photoUrls", Encode.list Encode.string model.photoUrls ) , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - ] - toString : Pet -> String toString = Encode.encode 0 << encode - - statusDecoder : Decoder Status statusDecoder = Decode.string @@ -92,7 +86,6 @@ statusDecoder = ) - encodeStatus : Status -> Encode.Value encodeStatus model = case model of @@ -104,7 +97,3 @@ encodeStatus model = Sold -> Encode.string "sold" - - - - diff --git a/samples/client/petstore/elm/src/Data/Tag.elm b/samples/client/petstore/elm/src/Data/Tag.elm index 601e91ecc155..052a4197b282 100644 --- a/samples/client/petstore/elm/src/Data/Tag.elm +++ b/samples/client/petstore/elm/src/Data/Tag.elm @@ -21,8 +21,8 @@ import Json.Encode as Encode {-| A tag for a pet -} type alias Tag = - { id : Maybe (Int) - , name : Maybe (String) + { id : Maybe Int + , name : Maybe String } @@ -33,21 +33,14 @@ decoder = |> optional "name" (Decode.nullable Decode.string) Nothing - encode : Tag -> Encode.Value encode model = Encode.object [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) - ] - toString : Tag -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm/src/Data/User.elm b/samples/client/petstore/elm/src/Data/User.elm index b0ae12253ebf..c4b2e3db9cc3 100644 --- a/samples/client/petstore/elm/src/Data/User.elm +++ b/samples/client/petstore/elm/src/Data/User.elm @@ -21,14 +21,14 @@ import Json.Encode as Encode {-| A User who is purchasing from the pet store -} type alias User = - { id : Maybe (Int) - , username : Maybe (String) - , firstName : Maybe (String) - , lastName : Maybe (String) - , email : Maybe (String) - , password : Maybe (String) - , phone : Maybe (String) - , userStatus : Maybe (Int) + { id : Maybe Int + , username : Maybe String + , firstName : Maybe String + , lastName : Maybe String + , email : Maybe String + , password : Maybe String + , phone : Maybe String + , userStatus : Maybe Int } @@ -45,7 +45,6 @@ decoder = |> optional "userStatus" (Decode.nullable Decode.int) Nothing - encode : User -> Encode.Value encode model = Encode.object @@ -57,15 +56,9 @@ encode model = , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) - ] - toString : User -> String toString = Encode.encode 0 << encode - - - - diff --git a/samples/client/petstore/elm/src/DateTime.elm b/samples/client/petstore/elm/src/DateTime.elm index 7d4a5c642c13..80b62fb7decb 100644 --- a/samples/client/petstore/elm/src/DateTime.elm +++ b/samples/client/petstore/elm/src/DateTime.elm @@ -34,4 +34,4 @@ decodeIsoString str = toString : DateTime -> String toString = - Iso8601.fromTime \ No newline at end of file + Iso8601.fromTime diff --git a/samples/client/petstore/elm/src/Request/Pet.elm b/samples/client/petstore/elm/src/Request/Pet.elm index a7fd8ba37a87..accf33f896f6 100644 --- a/samples/client/petstore/elm/src/Request/Pet.elm +++ b/samples/client/petstore/elm/src/Request/Pet.elm @@ -10,10 +10,10 @@ -} -module Request.Pet exposing (addPet, deletePet, findPetsByStatus, Status(..), findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) +module Request.Pet exposing (Status(..), addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) -import Data.Pet as Pet exposing (Pet) import Data.ApiResponse as ApiResponse exposing (ApiResponse) +import Data.Pet as Pet exposing (Pet) import Dict import Http import Json.Decode as Decode @@ -25,6 +25,7 @@ type Status | Pending | Sold + stringifyStatus : Status -> String stringifyStatus value = case value of @@ -38,9 +39,6 @@ stringifyStatus value = "sold" - - - basePath : String basePath = "http://petstore.swagger.io/v2" @@ -48,20 +46,17 @@ basePath = addPet : { onSend : Result Http.Error () -> msg - - , body : Pet - - } -> Cmd msg addPet params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "pet" ] + (List.filterMap identity []) , body = Http.jsonBody <| Pet.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -70,23 +65,21 @@ addPet params = deletePet : - { apiKey : Maybe (String) - } -> - { onSend : Result Http.Error () -> msg - - - - , petId : Int - + { apiKey : Maybe String } + -> + { onSend : Result Http.Error () -> msg + , petId : Int + } -> Cmd msg deletePet headers params = Http.request { method = "DELETE" - , headers = List.filterMap identity [Maybe.map (Http.header "api_key" << identity) headers.apiKey] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - (List.filterMap identity []) + , headers = List.filterMap identity [ Maybe.map (Http.header "api_key" << identity) 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 @@ -98,10 +91,6 @@ deletePet headers params = -} findPetsByStatus : { onSend : Result Http.Error (List Pet) -> msg - - - - , status : List Status } -> Cmd msg @@ -109,9 +98,10 @@ findPetsByStatus params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", "findByStatus"] - (List.filterMap identity [(Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status]) + , url = + Url.crossOrigin basePath + [ "pet", "findByStatus" ] + (List.filterMap identity [ (Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status ]) , body = Http.emptyBody , expect = Http.expectJson params.onSend (Decode.list Pet.decoder) , timeout = Just 30000 @@ -123,10 +113,6 @@ findPetsByStatus params = -} findPetsByTags : { onSend : Result Http.Error (List Pet) -> msg - - - - , tags : List String } -> Cmd msg @@ -134,9 +120,10 @@ findPetsByTags params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", "findByTags"] - (List.filterMap identity [(Just << Url.string "tags" << String.join "," << List.map identity) params.tags]) + , url = + Url.crossOrigin basePath + [ "pet", "findByTags" ] + (List.filterMap identity [ (Just << Url.string "tags" << String.join "," << List.map identity) params.tags ]) , body = Http.emptyBody , expect = Http.expectJson params.onSend (Decode.list Pet.decoder) , timeout = Just 30000 @@ -148,20 +135,17 @@ findPetsByTags params = -} getPetById : { onSend : Result Http.Error Pet -> msg - - - , petId : Int - } -> Cmd msg getPetById params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - (List.filterMap identity []) + , 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 @@ -171,20 +155,17 @@ getPetById params = updatePet : { onSend : Result Http.Error () -> msg - - , body : Pet - - } -> Cmd msg updatePet params = Http.request { method = "PUT" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "pet" ] + (List.filterMap identity []) , body = Http.jsonBody <| Pet.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -194,20 +175,17 @@ updatePet params = updatePetWithForm : { onSend : Result Http.Error () -> msg - - - , petId : Int - } -> Cmd msg updatePetWithForm params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "pet", String.fromInt params.petId ] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -217,20 +195,17 @@ updatePetWithForm params = uploadFile : { onSend : Result Http.Error ApiResponse -> msg - - - , petId : Int - } -> Cmd msg uploadFile params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId, "uploadImage"] - (List.filterMap identity []) + , 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 diff --git a/samples/client/petstore/elm/src/Request/Store.elm b/samples/client/petstore/elm/src/Request/Store.elm index e2a40d41938e..3800147a77a4 100644 --- a/samples/client/petstore/elm/src/Request/Store.elm +++ b/samples/client/petstore/elm/src/Request/Store.elm @@ -19,8 +19,6 @@ import Json.Decode as Decode import Url.Builder as Url - - basePath : String basePath = "http://petstore.swagger.io/v2" @@ -30,20 +28,17 @@ basePath = -} deleteOrder : { onSend : Result Http.Error () -> msg - - - , orderId : String - } -> Cmd msg deleteOrder params = Http.request { method = "DELETE" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "order", identity params.orderId] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "store", "order", identity params.orderId ] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -55,20 +50,16 @@ deleteOrder params = -} getInventory : { onSend : Result Http.Error (Dict.Dict String Int) -> msg - - - - - } -> Cmd msg getInventory params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "inventory"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "store", "inventory" ] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend (Decode.dict Decode.int) , timeout = Just 30000 @@ -80,20 +71,17 @@ getInventory params = -} getOrderById : { onSend : Result Http.Error Order_ -> msg - - - , orderId : Int - } -> Cmd msg getOrderById params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "order", String.fromInt params.orderId] - (List.filterMap identity []) + , 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 @@ -103,20 +91,17 @@ getOrderById params = placeOrder : { onSend : Result Http.Error Order_ -> msg - - , body : Order_ - - } -> Cmd msg placeOrder params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "order"] - (List.filterMap identity []) + , 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 diff --git a/samples/client/petstore/elm/src/Request/User.elm b/samples/client/petstore/elm/src/Request/User.elm index 0bb8411573b6..74bbe8213c0f 100644 --- a/samples/client/petstore/elm/src/Request/User.elm +++ b/samples/client/petstore/elm/src/Request/User.elm @@ -19,8 +19,6 @@ import Json.Decode as Decode import Url.Builder as Url - - basePath : String basePath = "http://petstore.swagger.io/v2" @@ -30,20 +28,17 @@ basePath = -} createUser : { onSend : Result Http.Error () -> msg - - , body : User - - } -> Cmd msg createUser params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user" ] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -53,20 +48,17 @@ createUser params = createUsersWithArrayInput : { onSend : Result Http.Error () -> msg - - , body : User - - } -> Cmd msg createUsersWithArrayInput params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "createWithArray"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user", "createWithArray" ] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -76,20 +68,17 @@ createUsersWithArrayInput params = createUsersWithListInput : { onSend : Result Http.Error () -> msg - - , body : User - - } -> Cmd msg createUsersWithListInput params = Http.request { method = "POST" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "createWithList"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user", "createWithList" ] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -101,20 +90,17 @@ createUsersWithListInput params = -} deleteUser : { onSend : Result Http.Error () -> msg - - - , username : String - } -> Cmd msg deleteUser params = Http.request { method = "DELETE" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", identity params.username] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user", identity params.username ] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -124,20 +110,17 @@ deleteUser params = getUserByName : { onSend : Result Http.Error User -> msg - - - , username : String - } -> Cmd msg getUserByName params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", identity params.username] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user", identity params.username ] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend User.decoder , timeout = Just 30000 @@ -147,20 +130,18 @@ getUserByName params = loginUser : { onSend : Result Http.Error String -> msg - - - - - , username : String , password : String + , username : String + , password : String } -> Cmd msg loginUser params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "login"] - (List.filterMap identity [(Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password]) + , url = + Url.crossOrigin basePath + [ "user", "login" ] + (List.filterMap identity [ (Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password ]) , body = Http.emptyBody , expect = Http.expectJson params.onSend Decode.string , timeout = Just 30000 @@ -170,20 +151,16 @@ loginUser params = logoutUser : { onSend : Result Http.Error () -> msg - - - - - } -> Cmd msg logoutUser params = Http.request { method = "GET" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "logout"] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user", "logout" ] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -195,20 +172,18 @@ logoutUser params = -} updateUser : { onSend : Result Http.Error () -> msg - - , body : User , username : String - } -> Cmd msg updateUser params = Http.request { method = "PUT" , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", identity params.username] - (List.filterMap identity []) + , url = + Url.crossOrigin basePath + [ "user", identity params.username ] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 From e417b421e454eebfb4a6354fadb0d0b18b8dc9a3 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 10 Oct 2019 13:11:24 +0800 Subject: [PATCH 2/4] replace paramName with baseName --- .../org/openapitools/codegen/languages/ElmClientCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index a4d099f59e52..3f08e337fa40 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -441,7 +441,7 @@ public Map postProcessOperationsWithModels(Map o String path = op.path; for (CodegenParameter param : op.pathParams) { final String var = paramToString("params", param, false, null); - path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \""); + path = path.replace("{" + param.baseName + "}", "\" ++ " + var + " ++ \""); } op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", ""); } else { // elm 0.19 or later From e37d24699aafbb5acf5d54f6a273c3fe8042baa0 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 10 Oct 2019 13:56:14 +0800 Subject: [PATCH 3/4] install elm format in circleci --- CI/circle_parallel.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 83d26c3eeaec..5ec173139656 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -21,6 +21,9 @@ elif [ "$NODE_INDEX" = "2" ]; then echo "Running node $NODE_INDEX to test ensure-up-to-date" java -version + # install elm-format + npm install -g elm-format + ./bin/utils/ensure-up-to-date fi #elif [ "$NODE_INDEX" = "3" ]; then From 4aeb514322e7f4a5546e510c9d43ae4489bb62bd Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 10 Oct 2019 16:12:26 +0800 Subject: [PATCH 4/4] switch to /usr/bin/env --- bin/elm-0.18-petstore.sh | 2 +- bin/elm-petstore.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/elm-0.18-petstore.sh b/bin/elm-0.18-petstore.sh index 9d5bcb53bc0f..4ec99604def3 100755 --- a/bin/elm-0.18-petstore.sh +++ b/bin/elm-0.18-petstore.sh @@ -26,7 +26,7 @@ then fi # auto format elm code using elm-format -export ELM_POST_PROCESS_FILE="/usr/local/bin/elm-format --elm-version=0.18 --yes" +export ELM_POST_PROCESS_FILE="/usr/bin/env elm-format --elm-version=0.18 --yes" # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" diff --git a/bin/elm-petstore.sh b/bin/elm-petstore.sh index f2dae6d27e58..dd4c67f49456 100755 --- a/bin/elm-petstore.sh +++ b/bin/elm-petstore.sh @@ -26,7 +26,7 @@ then fi # auto format elm code using elm-format -export ELM_POST_PROCESS_FILE="/usr/local/bin/elm-format --elm-version=0.19 --yes" +export ELM_POST_PROCESS_FILE="/usr/bin/env elm-format --elm-version=0.19 --yes" # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"