When specifying a subclass of pydantic.BaseModel in spectree.Response, an AssertionError: invalid pydantic.BaseModel is raised. This issue seems to be caused by the assertion at line 87 in spectree/response.py, which checks the model using issubclass(model, BaseModel). Despite importing BaseModel from spectree._pydantic, the assertion does not use the is_base_model() function from spectree._pydantic, which would correctly identify pydantic.BaseModel subclasses.
To Reproduce
Create a Flask application with pydantic and spectree.
Define a response model using pydantic.BaseModel.
Use the response model in spectree.Response.
Run the Flask application and make a request to the endpoint.
Example code:
from flask import Flask, jsonify
from pydantic import BaseModel, Field
from spectree import Response, SpecTree
class MyResponse(BaseModel):
message: str = Field(..., description="response message")
app = Flask(__name__)
spec = SpecTree('flask')
@app.route('/hello', methods=['GET'])
@spec.validate(resp=Response(HTTP_200=MyResponse))
def hello():
return jsonify(message='hello world')
if __name__ == '__main__':
spec.register(app)
app.run(debug=True)
Expected behavior
The response model should be validated correctly without raising an AssertionError.
The spectree version
SpecTree: 1.2.11
Flask: 3.0.2
pydantic: 2.9.2
Additional context
The issue seems to be caused by the assertion at line 87 in spectree/response.py, which checks the model using issubclass(model, BaseModel). A potential fix could be to adjust the assertion to use the is_base_model() function from spectree._pydantic to correctly identify pydantic.BaseModel subclasses.
Describe the bug
When specifying a subclass of pydantic.BaseModel in spectree.Response, an
AssertionError: invalid pydantic.BaseModel
is raised. This issue seems to be caused by the assertion at line 87 in spectree/response.py, which checks the model usingissubclass(model, BaseModel)
. Despite importing BaseModel from spectree._pydantic, the assertion does not use theis_base_model()
function from spectree._pydantic, which would correctly identify pydantic.BaseModel subclasses.To Reproduce
Example code:
Expected behavior
The response model should be validated correctly without raising an
AssertionError
.The spectree version
Additional context
The issue seems to be caused by the assertion at line 87 in spectree/response.py, which checks the model using
issubclass(model, BaseModel)
. A potential fix could be to adjust the assertion to use theis_base_model()
function from spectree._pydantic to correctly identify pydantic.BaseModel subclasses.