File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -54,5 +54,6 @@ class Schema(BaseModel):
5454 externalDocs : ExternalDocumentation | None = None
5555 example : Any | None = None
5656 deprecated : bool | None = None
57+ const : str | None = None
5758
5859 model_config = {"populate_by_name" : True }
Original file line number Diff line number Diff line change @@ -488,3 +488,25 @@ def test_schema_bigint(request):
488488 max_nr = 9223372036854775807
489489 obj = Schema (maximum = max_nr )
490490 assert obj .model_dump ()["maximum" ] == max_nr
491+
492+
493+ def test_convert_literal_with_single_value_to_const (request ):
494+ test_app = OpenAPI (request .node .name )
495+ test_app .config ["TESTING" ] = True
496+
497+ class MyResponse (BaseModel ):
498+ foobar : Literal ["baz" ]
499+
500+ @test_app .post ("/test" , responses = {200 : MyResponse })
501+ def endpoint_test ():
502+ print ("do nothing" )
503+
504+ with test_app .test_client () as client :
505+ resp = client .get ("/openapi/openapi.json" )
506+ assert resp .status_code == 200
507+ print ("###" , resp .json )
508+ assert resp .json ["components" ]["schemas" ]["MyResponse" ]["properties" ]["foobar" ] == {
509+ "const" : "baz" ,
510+ "title" : "Foobar" ,
511+ "type" : "string" ,
512+ }
You can’t perform that action at this time.
0 commit comments