aj-foster / open-api-generator

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

Cannot generate code with HTTP response code not enclosed in quoted marks #47

Closed kianmeng closed 3 months ago

kianmeng commented 4 months ago

Spec file: https://raw.githubusercontent.com/typesense/typesense-api-spec/master/openapi.yml

mix api.gen default openapi.yml 2>&1 | tee -a error_output
03:00:00.044 [debug] Beginning code generation
Profile: "default"
Files: [
  "openapi.yml"
]

03:00:00.049 [debug] Reading file openapi.yml
** (FunctionClauseError) no function clause matching in String.match?/2

    The following arguments were given to String.match?/2:

        # 1
        200

        # 2
        ~r/^[1-5]XX$/

    Attempted function clauses (showing 1 out of 1):

        def match?(+string+, +regex+) when -is_binary(string)-

    (elixir 1.16.0) lib/string.ex:2599: String.match?/2
    (oapi_generator 0.1.0) lib/open_api/spec/path/operation.ex:138: anonymous fn/2 in OpenAPI.Spec.Path.Operation.decode_responses/2
    (stdlib 5.2) maps.erl:416: :maps.fold_1/4
    (oapi_generator 0.1.0) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4
    (oapi_generator 0.1.0) lib/open_api/spec/path/operation.ex:62: OpenAPI.Spec.Path.Operation.decode/2
    (oapi_generator 0.1.0) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4
    (oapi_generator 0.1.0) lib/open_api/spec/path/item.ex:46: OpenAPI.Spec.Path.Item.decode/2
    (oapi_generator 0.1.0) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4
    (oapi_generator 0.1.0) lib/open_api/spec.ex:147: anonymous fn/2 in OpenAPI.Spec.decode_paths/2
    (stdlib 5.2) maps.erl:416: :maps.fold_1/4
    (oapi_generator 0.1.0) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4
    (oapi_generator 0.1.0) lib/open_api/spec.ex:74: OpenAPI.Spec.decode/2
    (elixir 1.16.0) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (oapi_generator 0.1.0) lib/open_api/reader.ex:104: OpenAPI.Reader.run/1
    (oapi_generator 0.1.0) lib/open_api.ex:49: OpenAPI.run/2
    (mix 1.16.0) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.16.0) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /home/foobar/.asdf/installs/elixir/1.16.0-otp-26/bin/mix:2: (file)

I have also reported the issue to the spec file provider.

It worked for https://github.com/OpenAPITools/openapi-generator, but not open-api-generator at this moment.

aj-foster commented 3 months ago

Hi there šŸ‘‹šŸ¼

Thanks for the report. This is an unfortunate, but understandable, issue with the spec. Release 0.1.1 includes a fix to allow for integer-encoded HTTP status code keys.

Thanks again!

kianmeng commented 3 months ago

:partying_face: :partying_face: :partying_face: :partying_face: :partying_face: