Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flask_openapi3/models/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ class Schema(BaseModel):
externalDocs: ExternalDocumentation | None = None
example: Any | None = None
deprecated: bool | None = None
const: str | None = None

model_config = {"populate_by_name": True}
22 changes: 22 additions & 0 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,25 @@ def test_schema_bigint(request):
max_nr = 9223372036854775807
obj = Schema(maximum=max_nr)
assert obj.model_dump()["maximum"] == max_nr


def test_convert_literal_with_single_value_to_const(request):
test_app = OpenAPI(request.node.name)
test_app.config["TESTING"] = True

class MyResponse(BaseModel):
foobar: Literal["baz"]

@test_app.post("/test", responses={200: MyResponse})
def endpoint_test():
print("do nothing")

with test_app.test_client() as client:
resp = client.get("/openapi/openapi.json")
assert resp.status_code == 200
print("###", resp.json)
assert resp.json["components"]["schemas"]["MyResponse"]["properties"]["foobar"] == {
"const": "baz",
"title": "Foobar",
"type": "string",
}