pgjones / quart-schema

Quart-Schema is a Quart extension that provides schema validation and auto-generated API documentation.
MIT License
76 stars 24 forks source link

servers field doesn't work with Pydantic V2 #65

Closed mst-ableton closed 7 months ago

mst-ableton commented 10 months ago

Hello, thanks for quart-schema!

It looks like the servers argument to the QuartSchema class causes a serialization error with Pydantic V2. Here is some example code:

from quart import Quart
from quart_schema import QuartSchema, Server

app = Quart(__name__)

QuartSchema(app, servers=[Server(url='http://cool.internet')])

@app.route("/")
async def root() -> str:
    """Root page."""
    return "Hello!"

Accessing /openapi.json yields the following error:

TypeError: Object of type 'Url' is not JSON serializable

We've tried all different combinations of Pydantic object magic, but as far as we can tell quart-schema forces the type to be Server, which can't be serialized with Pydantic V2. Any assistance would be welcome!

For reference, this was with Python 3.10.12, and pip list says:

Package           Version
----------------- -------
aiofiles          23.2.1
annotated-types   0.6.0
blinker           1.6.3
click             8.1.7
Flask             3.0.0
h11               0.14.0
h2                4.1.0
hpack             4.0.0
hypercorn         0.14.4
hyperframe        6.0.1
itsdangerous      2.1.2
Jinja2            3.1.2
MarkupSafe        2.1.3
pip               23.0.1
priority          2.0.0
pydantic          2.4.2
pydantic_core     2.10.1
pyhumps           3.8.0
Quart             0.19.3
quart-schema      0.17.1
setuptools        65.5.0
tomli             2.0.1
typing_extensions 4.8.0
Werkzeug          3.0.0
wsproto           1.2.0
pgjones commented 7 months ago

This should be fixed with 0.19.0 onwards