-
First Check
Commit to Help
Example Codeimport pytest
from fastapi import FastAPI
from starlette.testclient import TestClient
@pytest.fixture(name="client")
def get_client():
app = FastAPI(separate_input_output_schemas=False)
from pydantic import BaseModel, computed_field
class Rectangle(BaseModel):
width: int
length: int
@computed_field
@property
def area(self) -> int:
return self.width * self.length
@app.get("/")
def read_root() -> Rectangle:
return Rectangle(width=3, length=4)
client = TestClient(app)
return client
def test_get(client: TestClient):
response = client.get("/openapi.json")
data = response.json()
rectangle_model = data["components"]["schemas"]["Rectangle"]["properties"]
assert "area" in rectangle_model.keys()DescriptionI expect that even with Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.103.1 Pydantic Version2.4.1 Python Version3.8.16 Additional ContextI think it may come from here |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
@ldthorne I encountered the same issue. Changing |
Beta Was this translation helpful? Give feedback.
-
|
I just hit the same issue too. @krugi can you explain the solution you mentioned? |
Beta Was this translation helpful? Give feedback.
-
|
There's no way to directly create new issues, so I opened a PR here adding a test that should help maintainers: #13207 |
Beta Was this translation helpful? Give feedback.
There's no way to directly create new issues, so I opened a PR here adding a test that should help maintainers: #13207