[BUG][Elixir] Wrong api client spec on multiple result types
Created by: bigardone
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When a reponse has different types, the generated client's spec ony refers to the type corresponding to a 200
as the result, when it should list all the possible types. Example:
Current generated version:
@doc """
Returns an user by `id`
Returns an user account
## Parameters
- connection (Connection): Connection to server
- id (String.t): User ID
- opts (KeywordList): [optional] Optional parameters
## Returns
{:ok, %Model.UserShowSuccess{}} on success
{:error, info} on failure
"""
@spec fetch_user_by_id(Tesla.Env.client(), String.t(), keyword()) ::
{:ok, Model.UserShowSuccess.t()} | {:error, Tesla.Env.t()}
def fetch_user_by_id(connection, id, _opts \\ []) do
%{}
|> method(:get)
|> url("/internal/users/#{id}")
|> Enum.into([])
|> (&request(connection, &1)).()
|> evaluate_response([
{200, %Model.UserShowSuccess{}},
{404, %Model.NotFoundError{}},
{500, %Model.InternalServerError{}}
])
end
This, however, makes dialyzer throw warnings, because the @spec fetch_user_by_id
shoud be:
@spec fetch_user_by_id(Tesla.Env.client(), String.t(), keyword()) ::
{:ok, Model.UserShowSuccess.t()} | {:ok, Model.NotFoundError.t()} | {:ok, Model.InternalServerError.t()} | {:error, Tesla.Env.t()}
def fetch_user_by_id(connection, id, _opts \\ []) do
# ...
end
openapi-generator version
0.0.19-4.1.2
OpenAPI declaration file content or url
https://gist.github.com/bigardone/c656634c18d2e713c16de30537e013da
Command line used for generation
openapi-generator generate -i https://gist.githubusercontent.com/bigardone/c656634c18d2e713c16de30537e013da/raw/53d378b195de969712bf6db5d43154763449a8f7/OpenAPISpec.json -g elixir
Steps to reproduce
Related issues/PRs
Suggest a fix
All possible return types should be listed separated by |
in here https://github.com/OpenAPITools/openapi-generator/blob/44e4dc3ff4765ae03ce5f1c91799d347b09ec498/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java#L694