Browse Source

Test empty responses value

pull/5427/head
Arseny Leontev 3 years ago
parent
commit
4f8d765e59
  1. 69
      tests/test_additional_response_empty.py

69
tests/test_additional_response_empty.py

@ -0,0 +1,69 @@
from typing import Dict
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
app = FastAPI()
class Items(BaseModel):
items: Dict[str, int]
@app.post("/foo", responses={422: {}})
def foo(items: Items):
return items.items
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/foo": {
"post": {
"summary": "Foo",
"operationId": "foo_foo_post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Items"}
}
},
"required": True,
},
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
}
}
},
"components": {
"schemas": {
"Items": {
"title": "Items",
"required": ["items"],
"type": "object",
"properties": {
"items": {
"title": "Items",
"type": "object",
"additionalProperties": {"type": "integer"},
}
},
}
}
},
}
def test_additional_properties_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Loading…
Cancel
Save