Openapi-generator: [BUG] Elixir generated client does not work with optional request body

Created on 7 Feb 2020  路  2Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

If the request body of an api is optional, the generated elixir client cannot override the param correctly with the params if given.

For instance, one can do

Api.Account.account_get_transactions(
  Connection.new()
)

or

Api.Account.account_get_transactions(
  Connection.new(),
  [{:"GetAllTransactionsBodySchema", %{}}]
)

But no matter how we pass params into the function, it would not have any effect: (with limit 1, the response should only return 1 item)

Api.Account.account_get_transactions(
  Connection.new(),
  [{:"GetAllTransactionsBodySchema", %{
    limit: 1
  }}]
)

or

Api.Account.account_get_transactions(
  Connection.new(),
  [{:limit, 1}]
)
openapi-generator version

latest docker

OpenAPI declaration file content or url

https://github.com/omisego/elixir-omg/blob/862a6adfd436fbb1316be760ac6b72090127a115/apps/omg_watcher_rpc/priv/swagger/info_api_specs.yaml#L556

Command line used for generation

see this make command:
https://github.com/omisego/elixir-omg/blob/862a6adfd436fbb1316be760ac6b72090127a115/priv/Makefile#L20

Steps to reproduce
  1. clone elixir-omg
git clone https://github.com/omisego/elixir-omg
  1. run a local service in a tab
make init_test
make docker-nuke
docker-compose up
  1. in another tab:
cd elixir-omg/priv
mix deps.get
make generate_api_code
iex -S mix

alias WatcherInfoAPI.Connection
alias WatcherInfoAPI.Api

Api.Account.account_get_transactions(
  Connection.new(),
  [{:"GetAllTransactionsBodySchema", %{
    limit: 1
  }}]
)
Related issues/PRs

Workaround ourself: https://github.com/omisego/elixir-omg/pull/1302

Suggest a fix

N/A

Bug

All 2 comments

Hey @boolafish maybe reference yaml files on a certain commit rather than master. Uf we decide to fix the spec by not allowing option params the example will be missing from this issue.

Ahh I see, you're absolutely right, the body will be wrapped into a Multipart Request, which is obviously wrong,
I'll look into this..

@boolafish or @InoMurko, would it make sense to you, if the fix would look something like this: Api.Account.account_get_transactions(conn, body: %{limit: 1})

Was this page helpful?
0 / 5 - 0 ratings