pythogen icon indicating copy to clipboard operation
pythogen copied to clipboard

Incorrect attribute type in anyOf

Open pradishb opened this issue 1 year ago • 0 comments

OpenAPI json to reproduce the bug.

{
  "openapi": "3.1.0",
  "info": {
    "title": "NinjaAPI",
    "version": "1.0.0",
    "description": ""
  },
  "components": {
    "schemas": {
      "Schema1": {
        "properties": {
          "value": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [],
        "title": "Schema1",
        "type": "object"
      },
      "Schema2": {
        "properties": {
          "value": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [],
        "title": "Schema2",
        "type": "object"
      }
    }
  }
}

Here, value attribute of both Schema1 and Schema2 has type ValueObj > str | None but Schema1 should be int | None and Schema2 should be str | None.


class ValueObj(RootModel):
    """
    None

    """

    root: str | None


class Schema2(BaseModel):
    """
    Schema2

    """

    model_config = ConfigDict(
        populate_by_name=True,  # Addressing by field name, even if there is an alias.
    )
    value: ValueObj | None = None


class Schema1(BaseModel):
    """
    Schema1

    """

    model_config = ConfigDict(
        populate_by_name=True,  # Addressing by field name, even if there is an alias.
    )
    value: ValueObj | None = None # It should be int | None, instead it is annotated as str | None
    ```

pradishb avatar Sep 23 '24 20:09 pradishb