aj-foster / open-api-generator

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

:erlang.binary_to_integer("4XX") - 1st argument: not a textual representation of an integer #40

Closed addstar34 closed 6 months ago

addstar34 commented 6 months ago

Getting this error when running mix api.gen:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a textual representation of an integer

    :erlang.binary_to_integer("4XX")
    (oapi_generator 0.0.8) lib/open_api/spec/path/operation.ex:109: anonymous fn/2 in OpenAPI.Spec.Path.Operation.decode_responses/2
    (stdlib 4.2) maps.erl:411: :maps.fold_1/3
    (oapi_generator 0.0.8) lib/open_api/spec/helper.ex:21: OpenAPI.Spec.Helper.with_path/4
    (oapi_generator 0.0.8) lib/open_api/spec/path/operation.ex:46: OpenAPI.Spec.Path.Operation.decode/2
    (oapi_generator 0.0.8) lib/open_api/spec/helper.ex:21: OpenAPI.Spec.Helper.with_path/4
    (oapi_generator 0.0.8) lib/open_api/spec/path/item.ex:41: OpenAPI.Spec.Path.Item.decode/2
    (oapi_generator 0.0.8) lib/open_api/spec/helper.ex:21: OpenAPI.Spec.Helper.with_path/4

I'm guessing it can't handle the spec having this sort of thing:

"responses": {
  "200": {
    "description": "Success",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/GetAccountResponseCollection"
        }
      }
    }
  },
  "4XX": {
    "$ref": "#/components/responses/ClientError"
  },
  "5XX": {
    "$ref": "#/components/responses/ServerError"
  }
}

Full spec can be found here https://github.com/klaviyo/openapi/blob/main/openapi/stable.json

aj-foster commented 6 months ago

This is a pretty good one. I suppose the best course of action would be to manually add handlers for 1XX, 2XX, etc. similar to the way we handle default responses today. Thanks for the example!

aj-foster commented 6 months ago

Hi @addstar34 sorry for the difficulty. I looked into this, and the issue is already resolved in the latest release candidate. Making a 1.0.0 release is my next priority after fixing a few issues.