@@ -484,6 +484,50 @@ async def status(_a: str) -> dict:
484484 assert "Problem" in res ["components" ]["schemas" ]
485485 assert "ValidationError" in res ["components" ]["schemas" ]
486486
487+ assert res ["paths" ]["/status" ]["get" ]["responses" ] == {
488+ "200" : {
489+ "content" : {
490+ "application/json" : {
491+ "schema" : {
492+ "title" : "Response Status Status Get" ,
493+ "type" : "object" ,
494+ },
495+ },
496+ },
497+ "description" : "Successful Response" ,
498+ },
499+ "422" : {
500+ "content" : {
501+ "application/json" : {
502+ "schema" : {
503+ "$ref" : "#/components/schemas/HTTPValidationError" ,
504+ },
505+ },
506+ },
507+ "description" : "Validation Error" ,
508+ },
509+ "4XX" : {
510+ "content" : {
511+ "application/json" : {
512+ "schema" : {
513+ "$ref" : "#/components/schemas/Problem" ,
514+ },
515+ },
516+ },
517+ "description" : "Client Error" ,
518+ },
519+ "5XX" : {
520+ "content" : {
521+ "application/json" : {
522+ "schema" : {
523+ "$ref" : "#/components/schemas/Problem" ,
524+ },
525+ },
526+ },
527+ "description" : "Server Error" ,
528+ },
529+ }
530+
487531
488532async def test_customise_openapi_handles_no_components ():
489533 app = FastAPI ()
@@ -493,3 +537,71 @@ async def test_customise_openapi_handles_no_components():
493537 res = app .openapi ()
494538 assert res ["paths" ] == {}
495539 assert "components" not in res
540+
541+
542+ async def test_customise_openapi_generic_opt_out ():
543+ app = FastAPI ()
544+
545+ app .openapi = handler .customise_openapi (app .openapi , generic_defaults = False )
546+
547+ @app .get ("/status" )
548+ async def status (_a : str ) -> dict :
549+ return {}
550+
551+ res = app .openapi ()
552+ assert res ["components" ]["schemas" ]["HTTPValidationError" ] == {
553+ "properties" : {
554+ "title" : {
555+ "type" : "string" ,
556+ "title" : "Problem Title" ,
557+ },
558+ "type" : {
559+ "type" : "string" ,
560+ "title" : "Problem type" ,
561+ },
562+ "status" : {
563+ "type" : "integer" ,
564+ "title" : "Status code" ,
565+ },
566+ "errors" : {
567+ "type" : "array" ,
568+ "items" : {
569+ "$ref" : "#/components/schemas/ValidationError" ,
570+ },
571+ },
572+ },
573+ "type" : "object" ,
574+ "required" : [
575+ "type" ,
576+ "title" ,
577+ "errors" ,
578+ "status" ,
579+ ],
580+ "title" : "ValidationError" ,
581+ }
582+ assert "Problem" in res ["components" ]["schemas" ]
583+ assert "ValidationError" in res ["components" ]["schemas" ]
584+
585+ assert res ["paths" ]["/status" ]["get" ]["responses" ] == {
586+ "200" : {
587+ "content" : {
588+ "application/json" : {
589+ "schema" : {
590+ "title" : "Response Status Status Get" ,
591+ "type" : "object" ,
592+ },
593+ },
594+ },
595+ "description" : "Successful Response" ,
596+ },
597+ "422" : {
598+ "content" : {
599+ "application/json" : {
600+ "schema" : {
601+ "$ref" : "#/components/schemas/HTTPValidationError" ,
602+ },
603+ },
604+ },
605+ "description" : "Validation Error" ,
606+ },
607+ }
0 commit comments