[Elm] [REQ] Enum parameters in urls
Created by: andys8
Is your feature request related to a problem? Please describe.
Enum
s are supported by swagger and the openapi generator. If there is a string enum as part of a body it will be serialized and de-serialized as expected. When the enum is a query param, it will be handled as a string. The elm request data is typed to string
and the user has to manually convert the union type
/ custom type
to a string and can potentially introduce errors.
Describe the solution you'd like
If there is a path param of type enum string, the generated code should implement the serialization to string
.
Example
Rest endpoint
E.g. /users?status=WAITING
@GetMapping
public List<UserResponse> getAll(
@RequestParam(value = "status", required = false) @Nullable final Status status
) { }
Open Api Spec.
status
is "enum": ["IDLE", "OPEN", "IN_PROGRESS", "WAITING", "DONE"]
.
"/users": {
"get": {
"tags": ["user-controller"],
"summary": "getAll",
"operationId": "getAll",
"parameters": [
{
"name": "status",
"in": "query",
"description": "status",
"required": false,
"type": "string",
"enum": ["IDLE", "OPEN", "IN_PROGRESS", "WAITING", "DONE"]
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": { "$ref": "#/definitions/User" }
}
},
"401": { "description": "Unauthorized" },
"403": { "description": "Forbidden" },
"404": { "description": "Not Found" }
},
"deprecated": false
}
}
Generated elm request code
getAll :
{ onSend : Result Http.Error (List User) -> msg
, basePath : String
, status : Maybe String
}
-> Cmd msg
getAll params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin params.basePath
[ "users" ]
(List.filterMap identity [ Maybe.map (Url.string "status") params.status ])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend (Decode.list User.decoder)
, timeout = Just 30000
, tracker = Nothing
}
@eriktim