MarcoMuellner / openapi-python-generator

A client generator from openapi for python.
MIT License
56 stars 25 forks source link

null converts to Any #52

Closed jessemyers-lettuce closed 1 year ago

jessemyers-lettuce commented 1 year ago

OpenAPI type null is converted to Python type Any, most likely here:

    elif schema.type is None or schema.type == "null":
        converted_type = pre_type + "Any" + post_type

In Fast API (probably among other sources), Foo | None is expressed as:

"anyOf": [
      {
        "$ref": "#/components/schemas/Foo"
      },
      {
        "type": "null"
      }
    ]

because of this issue, we end up with a generated type that uses Union[Foo | Any] instead of Union[Foo | None]

If this is intentional, I'd love to understand why so I can create a fix that doesn't break some implicit, non-obvious behavior.

jessemyers-lettuce commented 1 year ago

For my usage, the fix in #53 works.

MarcoMuellner commented 1 year ago

Fixed in #53