|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from fastapi import FastAPI |
| 5 | +from fastapi.responses import JSONResponse, Response |
5 | 6 | from fastapi.testclient import TestClient |
6 | 7 | from pydantic import BaseModel, ValidationError |
7 | 8 |
|
@@ -237,6 +238,16 @@ def no_response_model_annotation_union_return_model2() -> Union[User, Item]: |
237 | 238 | return Item(name="Foo", price=42.0) |
238 | 239 |
|
239 | 240 |
|
| 241 | +@app.get("/no_response_model-annotation_response_class") |
| 242 | +def no_response_model_annotation_response_class() -> Response: |
| 243 | + return Response(content="Foo") |
| 244 | + |
| 245 | + |
| 246 | +@app.get("/no_response_model-annotation_json_response_class") |
| 247 | +def no_response_model_annotation_json_response_class() -> JSONResponse: |
| 248 | + return JSONResponse(content={"foo": "bar"}) |
| 249 | + |
| 250 | + |
240 | 251 | openapi_schema = { |
241 | 252 | "openapi": "3.0.2", |
242 | 253 | "info": {"title": "FastAPI", "version": "0.1.0"}, |
@@ -789,6 +800,30 @@ def no_response_model_annotation_union_return_model2() -> Union[User, Item]: |
789 | 800 | }, |
790 | 801 | } |
791 | 802 | }, |
| 803 | + "/no_response_model-annotation_response_class": { |
| 804 | + "get": { |
| 805 | + "summary": "No Response Model Annotation Response Class", |
| 806 | + "operationId": "no_response_model_annotation_response_class_no_response_model_annotation_response_class_get", |
| 807 | + "responses": { |
| 808 | + "200": { |
| 809 | + "description": "Successful Response", |
| 810 | + "content": {"application/json": {"schema": {}}}, |
| 811 | + } |
| 812 | + }, |
| 813 | + } |
| 814 | + }, |
| 815 | + "/no_response_model-annotation_json_response_class": { |
| 816 | + "get": { |
| 817 | + "summary": "No Response Model Annotation Json Response Class", |
| 818 | + "operationId": "no_response_model_annotation_json_response_class_no_response_model_annotation_json_response_class_get", |
| 819 | + "responses": { |
| 820 | + "200": { |
| 821 | + "description": "Successful Response", |
| 822 | + "content": {"application/json": {"schema": {}}}, |
| 823 | + } |
| 824 | + }, |
| 825 | + } |
| 826 | + }, |
792 | 827 | }, |
793 | 828 | "components": { |
794 | 829 | "schemas": { |
@@ -1049,3 +1084,15 @@ def test_no_response_model_annotation_union_return_model2(): |
1049 | 1084 | response = client.get("/no_response_model-annotation_union-return_model2") |
1050 | 1085 | assert response.status_code == 200, response.text |
1051 | 1086 | assert response.json() == {"name": "Foo", "price": 42.0} |
| 1087 | + |
| 1088 | + |
| 1089 | +def test_no_response_model_annotation_return_class(): |
| 1090 | + response = client.get("/no_response_model-annotation_response_class") |
| 1091 | + assert response.status_code == 200, response.text |
| 1092 | + assert response.text == "Foo" |
| 1093 | + |
| 1094 | + |
| 1095 | +def test_no_response_model_annotation_json_response_class(): |
| 1096 | + response = client.get("/no_response_model-annotation_json_response_class") |
| 1097 | + assert response.status_code == 200, response.text |
| 1098 | + assert response.json() == {"foo": "bar"} |
0 commit comments