aj-foster / open-api-generator

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

(RuntimeError) Unknown type: nil for Sentry spec #44

Closed yujonglee closed 2 months ago

yujonglee commented 4 months ago
mix api.gen default ./openapi.json

09:53:43.016 [debug] Beginning code generation
Profile: "default"
Files: [
  "./openapi.json"
]

09:53:43.022 [debug] Reading file ./openapi.json
** (RuntimeError) Unknown type: nil
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor/type.ex:153: OpenAPI.Processor.Type.from_schema/2
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor.ex:367: anonymous fn/5 in OpenAPI.Processor.process_response_body/4
    (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor.ex:365: anonymous fn/4 in OpenAPI.Processor.process_response_body/4
    (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (oapi_generator 0.1.0-rc.4) lib/open_api/processor.ex:315: anonymous fn/9 in OpenAPI.Processor.process_operation/2
    (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (stdlib 5.2) maps.erl:416: :maps.fold_1/4    

To reproduce: https://github.com/yujonglee/open-api-sentry

aj-foster commented 4 months ago

Hello there 👋🏼

This is a very interesting case. The OpenAPI specification allows for media content objects to have empty objects, but it's usually clearer from the context what the decoded data should look like (for example, raw binary data for an image). In this case, I guess a generic map type would be appropriate — do you agree?

The offending entry in the spec:

{
  "paths": {
    "/api/0/projects/{organization_slug}/{project_slug}/files/dsyms/": {
      "get": {
        "tags": ["Projects"],
        "description": "Retrieve a list of debug information files for a given project.",
        "operationId": "List a Project's Debug Information Files",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {}
            }
          }
        }
      }
    }
  }
}
aj-foster commented 4 months ago

Version 0.1.0 includes a change to warn instead of raise on this type. It will emit a generic any type for this particular schema. This should allow you to go ahead and generate some code while we figure out what to do with this particular situation.

yujonglee commented 4 months ago

Hi, yes I think generic map type will do. Thanks for the quick patch!

aj-foster commented 2 months ago

Hello again 👋🏼 I'll go ahead and close this for now. If you discover a better type (other than any) that we could generate here, we can make further changes in the future.