aj-foster / open-api-generator

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

generation error with content types other than json #45

Closed flaviogrossi closed 4 months ago

flaviogrossi commented 4 months ago

hi, after updating to the latest version, the code generation fails if a content type other than json is used with the following exception:

** (FunctionClauseError) no function clause matching in OpenAPI.Processor.Naming.readable_content_type/1    

    The following arguments were given to OpenAPI.Processor.Naming.readable_content_type/1:

        # 1
        "application/x-www-form-urlencoded"

    Attempted function clauses (showing 3 out of 3):

        def readable_content_type("application/json")
        def readable_content_type(<<"application/json+", _::binary>>)
        def readable_content_type("")

    (oapi_generator 0.1.0-rc.4) lib/open_api/processor/naming.ex:650: OpenAPI.Processor.Naming.readable_content_type/1
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor/naming.ex:582: OpenAPI.Processor.Naming.raw_schema_module_and_type/3
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor/naming.ex:227: OpenAPI.Processor.Naming.schema_module_and_type/2
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor.ex:493: anonymous fn/3 in OpenAPI.Processor.record_schema_module_and_type/1
    (stdlib 5.2) maps.erl:416: :maps.fold_1/4
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor.ex:45: OpenAPI.Processor.run/1
    (oapi_generator 0.1.0-rc.4) lib/open_api.ex:50: OpenAPI.run/2
    (mix 1.14.5) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4

am i reading the sources wrong or this was meant to be instead def readable_content_type(_), do: "" to also match unknown content types?

aj-foster commented 4 months ago

Hello there 👋🏼

You read that right — I meant to use an open _ clause for the fallback. On main I just added an additional clause for URL-encoded form data as well. This will be available in a release soon.

Thank you!

aj-foster commented 4 months ago

The fix for this is available in version 0.1.0. ❤️