Browse Source
- Add APIRouter.query() decorator for QUERY method (IETF draft) - Add FastAPI.query() passthrough method - Exclude QUERY routes from OpenAPI by default (spec doesn't support it) - Add test coverage for runtime execution and OpenAPI behavior - Add documentation with caveats and limitationspull/14170/head
4 changed files with 136 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||||
|
from fastapi import FastAPI |
||||
|
from fastapi.testclient import TestClient |
||||
|
from pydantic import BaseModel |
||||
|
|
||||
|
|
||||
|
class Payload(BaseModel): |
||||
|
x: int |
||||
|
|
||||
|
|
||||
|
def test_query_route_executes_and_openapi_survives(): |
||||
|
app = FastAPI() |
||||
|
|
||||
|
@app.query("/items") |
||||
|
def query_items(payload: Payload): |
||||
|
return {"ok": payload.x} |
||||
|
|
||||
|
client = TestClient(app) |
||||
|
|
||||
|
# Runtime: the route is callable with QUERY |
||||
|
r = client.request("QUERY", "/items", json={"x": 42}) |
||||
|
assert r.status_code == 200 |
||||
|
assert r.json() == {"ok": 42} |
||||
|
|
||||
|
# OpenAPI: does not include the query route (excluded by default), and must not error |
||||
|
schema = app.openapi() |
||||
|
# The path is excluded from OpenAPI because include_in_schema=False by default |
||||
|
assert "/items" not in schema["paths"] |
||||
Loading…
Reference in new issue