Unable to get any validation working with quart-schema

68 Views Asked by At

I've tried running the example on the main Github page and have gotten it down to a bare minimum for a POC.

I have the following code in 'schema.py'

from dataclasses import dataclass

from quart import Quart
from quart_schema import QuartSchema, validate_response

app = Quart(__name__)
QuartSchema(app)

@dataclass
class Info:
    msg: str

@app.get("/info")
@validate_response(Info, 200)
async def info() -> tuple[Info, int]:
    return {"msg": "info"}, 200

That should return a simple message, but I get a 500 and the following error instead:

quart_schema.validation.ResponseSchemaValidationError: Cannot load <class 'schema.Info'>

I can load that dataclass myself, but the validate_response fails. If I remove the validation it works as expected. What am I missing?

Also, I'm running the following versions, if that matters:

Quart        0.19.4
quart-schema 0.19.0
msgspec      0.18.6

Thanks

-mS

1

There are 1 best solutions below

1
pgjones On

You need to install either msgspec or Pydantic either directly or with Quart-Schema as an extra (pip install quart-schema[msgspec]) to get validation. See installation documentation.