aj-foster / open-api-generator

Open API code generator for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mix task crash when api have path params and parameters defined under path only

wingyplus opened this issue · comments

I have a project that want to generate against https://github.com/line/line-openapi/blob/main/messaging-api.yml and found mix task crash:

$ mix api.gen default line-openapi/messaging-api.yml
===> Analyzing applications...
===> Compiling yamerl
==> yaml_elixir
Compiling 6 files (.ex)
Generated yaml_elixir app
==> oapi_generator
Compiling 35 files (.ex)
Generated oapi_generator app
** (KeyError) key :schema not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
    (oapi_generator 0.0.7) lib/open_api/generator/operation.ex:133: anonymous fn/3 in OpenAPI.Generator.Operation.path_params/3
    (elixir 1.14.4) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
    (oapi_generator 0.0.7) lib/open_api/generator/operation.ex:17: OpenAPI.Generator.Operation.process/4
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (stdlib 4.3.1.1) maps.erl:411: :maps.fold_1/3
    (oapi_generator 0.0.7) lib/open_api/generator.ex:14: OpenAPI.Generator.run/1
    (mix 1.14.4) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
    (mix 1.14.4) lib/mix/cli.ex:84: Mix.CLI.run_task/2

After investigation, I found that they have APIs that defined path parameters under path item object but no parameters under operation object. One of this example is https://github.com/line/line-openapi/blob/main/messaging-api.yml#L1209

Hi @wingyplus,

Thanks for investigating this and pointing me right to the cause. I have a possible fix in #23 — if you have a chance, could you try it out and see if it does what you expect?

Thanks!