Fix NPE in Elm path parameter (#4116)

* fix NPE in elm path parameter

* replace paramName with baseName

* install elm format in circleci

* switch to /usr/bin/env
This commit is contained in:
William Cheng 2019-10-10 18:20:46 +08:00 committed by GitHub
parent ceb021cc54
commit 3141e483ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 192 additions and 354 deletions

View File

@ -21,6 +21,9 @@ elif [ "$NODE_INDEX" = "2" ]; then
echo "Running node $NODE_INDEX to test ensure-up-to-date" echo "Running node $NODE_INDEX to test ensure-up-to-date"
java -version java -version
# install elm-format
npm install -g elm-format
./bin/utils/ensure-up-to-date ./bin/utils/ensure-up-to-date
fi fi
#elif [ "$NODE_INDEX" = "3" ]; then #elif [ "$NODE_INDEX" = "3" ]; then

View File

@ -26,7 +26,7 @@ then
fi fi
# auto format elm code using elm-format # 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. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"

View File

@ -26,7 +26,7 @@ then
fi fi
# auto format elm code using elm-format # 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. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"

View File

@ -68,7 +68,7 @@ declare -a scripts=(
"./bin/dart-petstore.sh" "./bin/dart-petstore.sh"
"./bin/dart2-petstore.sh" "./bin/dart2-petstore.sh"
"./bin/java-play-framework-petstore-server-all.sh" "./bin/java-play-framework-petstore-server-all.sh"
#"./bin/elm-petstore-all.sh" "./bin/elm-petstore-all.sh"
"./bin/meta-codegen.sh" "./bin/meta-codegen.sh"
# OTHERS # OTHERS
"./bin/utils/export_docs_generators.sh" "./bin/utils/export_docs_generators.sh"

View File

@ -437,18 +437,18 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
final Set<String> dependencies = new HashSet<>(); final Set<String> dependencies = new HashSet<>();
for (CodegenOperation op : ops) { for (CodegenOperation op : ops) {
if (ElmVersion.ELM_018.equals(elmVersion)) { if (ElmVersion.ELM_018.equals(elmVersion)) { // elm 0.18
String path = op.path; String path = op.path;
for (CodegenParameter param : op.pathParams) { for (CodegenParameter param : op.pathParams) {
final String var = paramToString("params", param, false, null); final String var = paramToString("params", param, false, null);
path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \""); path = path.replace("{" + param.baseName + "}", "\" ++ " + var + " ++ \"");
} }
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", ""); op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
} else { } else { // elm 0.19 or later
final List<Object> pathParams = Arrays.asList(op.path.substring(1).split("/")).stream() final List<Object> pathParams = Arrays.asList(op.path.substring(1).split("/")).stream()
.map(str -> { .map(str -> {
if (str.startsWith("{") && str.endsWith("}")) { if (str.startsWith("{") && str.endsWith("}")) {
return op.pathParams.stream().filter(p -> str.equals("{" + p.paramName + "}")).findFirst().orElse(null); return op.pathParams.stream().filter(p -> str.equals("{" + p.baseName + "}")).findFirst().orElse(null);
} else { } else {
return "\"" + str + "\""; return "\"" + str + "\"";
} }

View File

@ -1 +1 @@
4.1.3-SNAPSHOT 4.2.0-SNAPSHOT

View File

@ -21,9 +21,9 @@ import Json.Encode as Encode
{-| Describes the result of uploading an image resource {-| Describes the result of uploading an image resource
-} -}
type alias ApiResponse = type alias ApiResponse =
{ code : Maybe (Int) { code : Maybe Int
, type_ : Maybe (String) , type_ : Maybe String
, message : Maybe (String) , message : Maybe String
} }
@ -35,22 +35,15 @@ decoder =
|> optional "message" (Decode.nullable Decode.string) Nothing |> optional "message" (Decode.nullable Decode.string) Nothing
encode : ApiResponse -> Encode.Value encode : ApiResponse -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) )
, ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) )
, ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) )
] ]
toString : ApiResponse -> String toString : ApiResponse -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A category for a pet {-| A category for a pet
-} -}
type alias Category = type alias Category =
{ id : Maybe (Int) { id : Maybe Int
, name : Maybe (String) , name : Maybe String
} }
@ -33,21 +33,14 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing |> optional "name" (Decode.nullable Decode.string) Nothing
encode : Category -> Encode.Value encode : Category -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
] ]
toString : Category -> String toString : Category -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -22,12 +22,12 @@ import Json.Encode as Encode
{-| An order for a pets from the pet store {-| An order for a pets from the pet store
-} -}
type alias Order_ = type alias Order_ =
{ id : Maybe (Int) { id : Maybe Int
, petId : Maybe (Int) , petId : Maybe Int
, quantity : Maybe (Int) , quantity : Maybe Int
, shipDate : Maybe (DateTime) , shipDate : Maybe DateTime
, status : Maybe (Status) , status : Maybe Status
, complete : Maybe (Bool) , complete : Maybe Bool
} }
@ -37,7 +37,6 @@ type Status
| Delivered | Delivered
decoder : Decoder Order_ decoder : Decoder Order_
decoder = decoder =
decode Order_ decode Order_
@ -49,7 +48,6 @@ decoder =
|> optional "complete" (Decode.nullable Decode.bool) (Just False) |> optional "complete" (Decode.nullable Decode.bool) (Just False)
encode : Order_ -> Encode.Value encode : Order_ -> Encode.Value
encode model = encode model =
Encode.object Encode.object
@ -59,18 +57,14 @@ encode model =
, ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) )
, ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) )
] ]
toString : Order_ -> String toString : Order_ -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode
statusDecoder : Decoder Status statusDecoder : Decoder Status
statusDecoder = statusDecoder =
Decode.string Decode.string
@ -91,7 +85,6 @@ statusDecoder =
) )
encodeStatus : Status -> Encode.Value encodeStatus : Status -> Encode.Value
encodeStatus model = encodeStatus model =
case model of case model of
@ -103,7 +96,3 @@ encodeStatus model =
Delivered -> Delivered ->
Encode.string "delivered" Encode.string "delivered"

View File

@ -23,12 +23,12 @@ import Json.Encode as Encode
{-| A pet for sale in the pet store {-| A pet for sale in the pet store
-} -}
type alias Pet = type alias Pet =
{ id : Maybe (Int) { id : Maybe Int
, category : Maybe (Category) , category : Maybe Category
, name : String , name : String
, photoUrls : (List String) , photoUrls : List String
, tags : Maybe ((List Tag)) , tags : Maybe (List Tag)
, status : Maybe (Status) , status : Maybe Status
} }
@ -38,7 +38,6 @@ type Status
| Sold | Sold
decoder : Decoder Pet decoder : Decoder Pet
decoder = decoder =
decode Pet decode Pet
@ -50,7 +49,6 @@ decoder =
|> optional "status" (Decode.nullable statusDecoder) Nothing |> optional "status" (Decode.nullable statusDecoder) Nothing
encode : Pet -> Encode.Value encode : Pet -> Encode.Value
encode model = encode model =
Encode.object Encode.object
@ -60,18 +58,14 @@ encode model =
, ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls ) , ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls )
, ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list << List.map Tag.encode) model.tags) ) , ( "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) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) )
] ]
toString : Pet -> String toString : Pet -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode
statusDecoder : Decoder Status statusDecoder : Decoder Status
statusDecoder = statusDecoder =
Decode.string Decode.string
@ -92,7 +86,6 @@ statusDecoder =
) )
encodeStatus : Status -> Encode.Value encodeStatus : Status -> Encode.Value
encodeStatus model = encodeStatus model =
case model of case model of
@ -104,7 +97,3 @@ encodeStatus model =
Sold -> Sold ->
Encode.string "sold" Encode.string "sold"

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A tag for a pet {-| A tag for a pet
-} -}
type alias Tag = type alias Tag =
{ id : Maybe (Int) { id : Maybe Int
, name : Maybe (String) , name : Maybe String
} }
@ -33,21 +33,14 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing |> optional "name" (Decode.nullable Decode.string) Nothing
encode : Tag -> Encode.Value encode : Tag -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
] ]
toString : Tag -> String toString : Tag -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -21,14 +21,14 @@ import Json.Encode as Encode
{-| A User who is purchasing from the pet store {-| A User who is purchasing from the pet store
-} -}
type alias User = type alias User =
{ id : Maybe (Int) { id : Maybe Int
, username : Maybe (String) , username : Maybe String
, firstName : Maybe (String) , firstName : Maybe String
, lastName : Maybe (String) , lastName : Maybe String
, email : Maybe (String) , email : Maybe String
, password : Maybe (String) , password : Maybe String
, phone : Maybe (String) , phone : Maybe String
, userStatus : Maybe (Int) , userStatus : Maybe Int
} }
@ -45,7 +45,6 @@ decoder =
|> optional "userStatus" (Decode.nullable Decode.int) Nothing |> optional "userStatus" (Decode.nullable Decode.int) Nothing
encode : User -> Encode.Value encode : User -> Encode.Value
encode model = encode model =
Encode.object Encode.object
@ -57,15 +56,9 @@ encode model =
, ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) )
, ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) )
, ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) )
] ]
toString : User -> String toString : User -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -12,8 +12,8 @@
module Request.Pet exposing (addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) 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.ApiResponse as ApiResponse exposing (ApiResponse)
import Data.Pet as Pet exposing (Pet)
import Dict import Dict
import Http import Http
import Json.Decode as Decode import Json.Decode as Decode

View File

@ -1 +1 @@
4.1.3-SNAPSHOT 4.2.0-SNAPSHOT

View File

@ -21,9 +21,9 @@ import Json.Encode as Encode
{-| Describes the result of uploading an image resource {-| Describes the result of uploading an image resource
-} -}
type alias ApiResponse = type alias ApiResponse =
{ code : Maybe (Int) { code : Maybe Int
, type_ : Maybe (String) , type_ : Maybe String
, message : Maybe (String) , message : Maybe String
} }
@ -35,22 +35,15 @@ decoder =
|> optional "message" (Decode.nullable Decode.string) Nothing |> optional "message" (Decode.nullable Decode.string) Nothing
encode : ApiResponse -> Encode.Value encode : ApiResponse -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) )
, ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) )
, ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) )
] ]
toString : ApiResponse -> String toString : ApiResponse -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A category for a pet {-| A category for a pet
-} -}
type alias Category = type alias Category =
{ id : Maybe (Int) { id : Maybe Int
, name : Maybe (String) , name : Maybe String
} }
@ -33,21 +33,14 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing |> optional "name" (Decode.nullable Decode.string) Nothing
encode : Category -> Encode.Value encode : Category -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
] ]
toString : Category -> String toString : Category -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -22,12 +22,12 @@ import Json.Encode as Encode
{-| An order for a pets from the pet store {-| An order for a pets from the pet store
-} -}
type alias Order_ = type alias Order_ =
{ id : Maybe (Int) { id : Maybe Int
, petId : Maybe (Int) , petId : Maybe Int
, quantity : Maybe (Int) , quantity : Maybe Int
, shipDate : Maybe (DateTime) , shipDate : Maybe DateTime
, status : Maybe (Status) , status : Maybe Status
, complete : Maybe (Bool) , complete : Maybe Bool
} }
@ -37,7 +37,6 @@ type Status
| Delivered | Delivered
decoder : Decoder Order_ decoder : Decoder Order_
decoder = decoder =
Decode.succeed Order_ Decode.succeed Order_
@ -49,7 +48,6 @@ decoder =
|> optional "complete" (Decode.nullable Decode.bool) (Just False) |> optional "complete" (Decode.nullable Decode.bool) (Just False)
encode : Order_ -> Encode.Value encode : Order_ -> Encode.Value
encode model = encode model =
Encode.object Encode.object
@ -59,18 +57,14 @@ encode model =
, ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) )
, ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) )
] ]
toString : Order_ -> String toString : Order_ -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode
statusDecoder : Decoder Status statusDecoder : Decoder Status
statusDecoder = statusDecoder =
Decode.string Decode.string
@ -91,7 +85,6 @@ statusDecoder =
) )
encodeStatus : Status -> Encode.Value encodeStatus : Status -> Encode.Value
encodeStatus model = encodeStatus model =
case model of case model of
@ -103,7 +96,3 @@ encodeStatus model =
Delivered -> Delivered ->
Encode.string "delivered" Encode.string "delivered"

View File

@ -23,12 +23,12 @@ import Json.Encode as Encode
{-| A pet for sale in the pet store {-| A pet for sale in the pet store
-} -}
type alias Pet = type alias Pet =
{ id : Maybe (Int) { id : Maybe Int
, category : Maybe (Category) , category : Maybe Category
, name : String , name : String
, photoUrls : (List String) , photoUrls : List String
, tags : Maybe ((List Tag)) , tags : Maybe (List Tag)
, status : Maybe (Status) , status : Maybe Status
} }
@ -38,7 +38,6 @@ type Status
| Sold | Sold
decoder : Decoder Pet decoder : Decoder Pet
decoder = decoder =
Decode.succeed Pet Decode.succeed Pet
@ -50,28 +49,23 @@ decoder =
|> optional "status" (Decode.nullable statusDecoder) Nothing |> optional "status" (Decode.nullable statusDecoder) Nothing
encode : Pet -> Encode.Value encode : Pet -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) )
, ( "name", Encode.string model.name ) , ( "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) ) , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) )
] ]
toString : Pet -> String toString : Pet -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode
statusDecoder : Decoder Status statusDecoder : Decoder Status
statusDecoder = statusDecoder =
Decode.string Decode.string
@ -92,7 +86,6 @@ statusDecoder =
) )
encodeStatus : Status -> Encode.Value encodeStatus : Status -> Encode.Value
encodeStatus model = encodeStatus model =
case model of case model of
@ -104,7 +97,3 @@ encodeStatus model =
Sold -> Sold ->
Encode.string "sold" Encode.string "sold"

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A tag for a pet {-| A tag for a pet
-} -}
type alias Tag = type alias Tag =
{ id : Maybe (Int) { id : Maybe Int
, name : Maybe (String) , name : Maybe String
} }
@ -33,21 +33,14 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing |> optional "name" (Decode.nullable Decode.string) Nothing
encode : Tag -> Encode.Value encode : Tag -> Encode.Value
encode model = encode model =
Encode.object Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
] ]
toString : Tag -> String toString : Tag -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -21,14 +21,14 @@ import Json.Encode as Encode
{-| A User who is purchasing from the pet store {-| A User who is purchasing from the pet store
-} -}
type alias User = type alias User =
{ id : Maybe (Int) { id : Maybe Int
, username : Maybe (String) , username : Maybe String
, firstName : Maybe (String) , firstName : Maybe String
, lastName : Maybe (String) , lastName : Maybe String
, email : Maybe (String) , email : Maybe String
, password : Maybe (String) , password : Maybe String
, phone : Maybe (String) , phone : Maybe String
, userStatus : Maybe (Int) , userStatus : Maybe Int
} }
@ -45,7 +45,6 @@ decoder =
|> optional "userStatus" (Decode.nullable Decode.int) Nothing |> optional "userStatus" (Decode.nullable Decode.int) Nothing
encode : User -> Encode.Value encode : User -> Encode.Value
encode model = encode model =
Encode.object Encode.object
@ -57,15 +56,9 @@ encode model =
, ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) )
, ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) )
, ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) )
] ]
toString : User -> String toString : User -> String
toString = toString =
Encode.encode 0 << encode Encode.encode 0 << encode

View File

@ -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.ApiResponse as ApiResponse exposing (ApiResponse)
import Data.Pet as Pet exposing (Pet)
import Dict import Dict
import Http import Http
import Json.Decode as Decode import Json.Decode as Decode
@ -25,6 +25,7 @@ type Status
| Pending | Pending
| Sold | Sold
stringifyStatus : Status -> String stringifyStatus : Status -> String
stringifyStatus value = stringifyStatus value =
case value of case value of
@ -38,9 +39,6 @@ stringifyStatus value =
"sold" "sold"
basePath : String basePath : String
basePath = basePath =
"http://petstore.swagger.io/v2" "http://petstore.swagger.io/v2"
@ -48,18 +46,15 @@ basePath =
addPet : addPet :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, body : Pet , body : Pet
} }
-> Cmd msg -> Cmd msg
addPet params = addPet params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet" ] [ "pet" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| Pet.encode params.body , body = Http.jsonBody <| Pet.encode params.body
@ -70,21 +65,19 @@ addPet params =
deletePet : deletePet :
{ apiKey : Maybe (String) { apiKey : Maybe String
} -> }
->
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, petId : Int , petId : Int
} }
-> Cmd msg -> Cmd msg
deletePet headers params = deletePet headers params =
Http.request Http.request
{ method = "DELETE" { method = "DELETE"
, headers = List.filterMap identity [ Maybe.map (Http.header "api_key" << identity) headers.apiKey ] , headers = List.filterMap identity [ Maybe.map (Http.header "api_key" << identity) headers.apiKey ]
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId ] [ "pet", String.fromInt params.petId ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -98,10 +91,6 @@ deletePet headers params =
-} -}
findPetsByStatus : findPetsByStatus :
{ onSend : Result Http.Error (List Pet) -> msg { onSend : Result Http.Error (List Pet) -> msg
, status : List Status , status : List Status
} }
-> Cmd msg -> Cmd msg
@ -109,7 +98,8 @@ findPetsByStatus params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet", "findByStatus" ] [ "pet", "findByStatus" ]
(List.filterMap identity [ (Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status ]) (List.filterMap identity [ (Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status ])
, body = Http.emptyBody , body = Http.emptyBody
@ -123,10 +113,6 @@ findPetsByStatus params =
-} -}
findPetsByTags : findPetsByTags :
{ onSend : Result Http.Error (List Pet) -> msg { onSend : Result Http.Error (List Pet) -> msg
, tags : List String , tags : List String
} }
-> Cmd msg -> Cmd msg
@ -134,7 +120,8 @@ findPetsByTags params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet", "findByTags" ] [ "pet", "findByTags" ]
(List.filterMap identity [ (Just << Url.string "tags" << String.join "," << List.map identity) params.tags ]) (List.filterMap identity [ (Just << Url.string "tags" << String.join "," << List.map identity) params.tags ])
, body = Http.emptyBody , body = Http.emptyBody
@ -148,18 +135,15 @@ findPetsByTags params =
-} -}
getPetById : getPetById :
{ onSend : Result Http.Error Pet -> msg { onSend : Result Http.Error Pet -> msg
, petId : Int , petId : Int
} }
-> Cmd msg -> Cmd msg
getPetById params = getPetById params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId ] [ "pet", String.fromInt params.petId ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -171,18 +155,15 @@ getPetById params =
updatePet : updatePet :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, body : Pet , body : Pet
} }
-> Cmd msg -> Cmd msg
updatePet params = updatePet params =
Http.request Http.request
{ method = "PUT" { method = "PUT"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet" ] [ "pet" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| Pet.encode params.body , body = Http.jsonBody <| Pet.encode params.body
@ -194,18 +175,15 @@ updatePet params =
updatePetWithForm : updatePetWithForm :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, petId : Int , petId : Int
} }
-> Cmd msg -> Cmd msg
updatePetWithForm params = updatePetWithForm params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId ] [ "pet", String.fromInt params.petId ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -217,18 +195,15 @@ updatePetWithForm params =
uploadFile : uploadFile :
{ onSend : Result Http.Error ApiResponse -> msg { onSend : Result Http.Error ApiResponse -> msg
, petId : Int , petId : Int
} }
-> Cmd msg -> Cmd msg
uploadFile params = uploadFile params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId, "uploadImage" ] [ "pet", String.fromInt params.petId, "uploadImage" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody

View File

@ -19,8 +19,6 @@ import Json.Decode as Decode
import Url.Builder as Url import Url.Builder as Url
basePath : String basePath : String
basePath = basePath =
"http://petstore.swagger.io/v2" "http://petstore.swagger.io/v2"
@ -30,18 +28,15 @@ basePath =
-} -}
deleteOrder : deleteOrder :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, orderId : String , orderId : String
} }
-> Cmd msg -> Cmd msg
deleteOrder params = deleteOrder params =
Http.request Http.request
{ method = "DELETE" { method = "DELETE"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "store", "order", identity params.orderId ] [ "store", "order", identity params.orderId ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -55,18 +50,14 @@ deleteOrder params =
-} -}
getInventory : getInventory :
{ onSend : Result Http.Error (Dict.Dict String Int) -> msg { onSend : Result Http.Error (Dict.Dict String Int) -> msg
} }
-> Cmd msg -> Cmd msg
getInventory params = getInventory params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "store", "inventory" ] [ "store", "inventory" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -80,18 +71,15 @@ getInventory params =
-} -}
getOrderById : getOrderById :
{ onSend : Result Http.Error Order_ -> msg { onSend : Result Http.Error Order_ -> msg
, orderId : Int , orderId : Int
} }
-> Cmd msg -> Cmd msg
getOrderById params = getOrderById params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "store", "order", String.fromInt params.orderId ] [ "store", "order", String.fromInt params.orderId ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -103,18 +91,15 @@ getOrderById params =
placeOrder : placeOrder :
{ onSend : Result Http.Error Order_ -> msg { onSend : Result Http.Error Order_ -> msg
, body : Order_ , body : Order_
} }
-> Cmd msg -> Cmd msg
placeOrder params = placeOrder params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "store", "order" ] [ "store", "order" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| Order_.encode params.body , body = Http.jsonBody <| Order_.encode params.body

View File

@ -19,8 +19,6 @@ import Json.Decode as Decode
import Url.Builder as Url import Url.Builder as Url
basePath : String basePath : String
basePath = basePath =
"http://petstore.swagger.io/v2" "http://petstore.swagger.io/v2"
@ -30,18 +28,15 @@ basePath =
-} -}
createUser : createUser :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, body : User , body : User
} }
-> Cmd msg -> Cmd msg
createUser params = createUser params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user" ] [ "user" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| User.encode params.body , body = Http.jsonBody <| User.encode params.body
@ -53,18 +48,15 @@ createUser params =
createUsersWithArrayInput : createUsersWithArrayInput :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, body : User , body : User
} }
-> Cmd msg -> Cmd msg
createUsersWithArrayInput params = createUsersWithArrayInput params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", "createWithArray" ] [ "user", "createWithArray" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| User.encode params.body , body = Http.jsonBody <| User.encode params.body
@ -76,18 +68,15 @@ createUsersWithArrayInput params =
createUsersWithListInput : createUsersWithListInput :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, body : User , body : User
} }
-> Cmd msg -> Cmd msg
createUsersWithListInput params = createUsersWithListInput params =
Http.request Http.request
{ method = "POST" { method = "POST"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", "createWithList" ] [ "user", "createWithList" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| User.encode params.body , body = Http.jsonBody <| User.encode params.body
@ -101,18 +90,15 @@ createUsersWithListInput params =
-} -}
deleteUser : deleteUser :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, username : String , username : String
} }
-> Cmd msg -> Cmd msg
deleteUser params = deleteUser params =
Http.request Http.request
{ method = "DELETE" { method = "DELETE"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", identity params.username ] [ "user", identity params.username ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -124,18 +110,15 @@ deleteUser params =
getUserByName : getUserByName :
{ onSend : Result Http.Error User -> msg { onSend : Result Http.Error User -> msg
, username : String , username : String
} }
-> Cmd msg -> Cmd msg
getUserByName params = getUserByName params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", identity params.username ] [ "user", identity params.username ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -147,18 +130,16 @@ getUserByName params =
loginUser : loginUser :
{ onSend : Result Http.Error String -> msg { onSend : Result Http.Error String -> msg
, username : String
, password : String
, username : String , password : String
} }
-> Cmd msg -> Cmd msg
loginUser params = loginUser params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", "login" ] [ "user", "login" ]
(List.filterMap identity [ (Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password ]) (List.filterMap identity [ (Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password ])
, body = Http.emptyBody , body = Http.emptyBody
@ -170,18 +151,14 @@ loginUser params =
logoutUser : logoutUser :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
} }
-> Cmd msg -> Cmd msg
logoutUser params = logoutUser params =
Http.request Http.request
{ method = "GET" { method = "GET"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", "logout" ] [ "user", "logout" ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.emptyBody , body = Http.emptyBody
@ -195,18 +172,16 @@ logoutUser params =
-} -}
updateUser : updateUser :
{ onSend : Result Http.Error () -> msg { onSend : Result Http.Error () -> msg
, body : User , body : User
, username : String , username : String
} }
-> Cmd msg -> Cmd msg
updateUser params = updateUser params =
Http.request Http.request
{ method = "PUT" { method = "PUT"
, headers = List.filterMap identity [] , headers = List.filterMap identity []
, url = Url.crossOrigin basePath , url =
Url.crossOrigin basePath
[ "user", identity params.username ] [ "user", identity params.username ]
(List.filterMap identity []) (List.filterMap identity [])
, body = Http.jsonBody <| User.encode params.body , body = Http.jsonBody <| User.encode params.body