aj-foster / open-api-generator

Open API code generator for Elixir
MIT License
97 stars 13 forks source link

Process nested schema references #50

Closed McSym28 closed 1 month ago

McSym28 commented 3 months ago

I was trying to generate a library using one of our local bank's Open APIs (unfortunately it's only available in Ukrainian). I've extracted the JSON spec from page's source and passed it to your great library. Unfortunately I was getting an error when processing a "nested schema reference". The error looks something like this:

** (KeyError) key {"{REDACTED}/open-api-generator/test/fixture/schema-reference.yaml", ["components", "schemas", "{REDACTED}"]} not found in: {REDACTED}
    :erlang.map_get({"{REDACTED}/test/fixture/schema-reference.yaml", ["components", "schemas", "{REDACTED}"]}, {REDACTED}
    (oapi_generator 0.1.1) lib/open_api/processor/type.ex:93: OpenAPI.Processor.Type.from_schema/2
    (oapi_generator 0.1.1) lib/open_api/processor.ex:367: anonymous fn/5 in OpenAPI.Processor.process_response_body/4
    {REDACTED}

I've added a slim spec to simulate an error. Not sure what is the best approach to tackle this or if you want to support this case in your library. I've had another attempt in a different branch, but this one looks cleaner, IMO.

P.S. Thanks for your great work!

McSym28 commented 3 months ago

I've ran the generate job on a open-api-diffs fork and the tag was created successfully - oapi_generator/527cac2. Have I missed some config/setting?

aj-foster commented 2 months ago

Hi @McSym28, thanks for reporting this. I took a slightly different route to resolving this issue in #56. If you have time, coudl you check it out and see if it works for you?

Thanks! ❤️

McSym28 commented 1 month ago

Hi @aj-foster. This works for me. I've made a similar change in my first attempt. The only difference is that my solution is limited to only #/components/schemas/* references. Thanks!