turner-townsend / flask-pydantic-spec

An Flask OpenAPI library using Pydantic
Apache License 2.0
99 stars 19 forks source link

Latest release 0.4.2 cannot handle __root__ lists anymore #47

Closed CarstenKarbach closed 1 year ago

CarstenKarbach commented 1 year ago

Example:

class Item(BaseModel):
    key: str

class ItemList(BaseModel):
    __root__: list[Item]

produces this generic openapi schema, which cannot really be used:

"ItemList": {
        "title": "ItemList",
        "type": "array"
},

While with version 0.4.1 I am getting this schema:

"ItemList": {
        "items": {
          "$ref": "#/components/schemas/Item"
        },
        "title": "ItemList",
        "type": "array"
      },

It looks like the __root__ attribute is not handled as before. When I replace this with any other attribute name like this:

class ItemList(BaseModel):
    test: list[Item]

the schema is correctly generated.

cgearing commented 1 year ago

Thanks for raising! I'll take a look and fix this