From 63f789ae3173680b531b4e4590fa2564832898ba Mon Sep 17 00:00:00 2001 From: Ivan Chetverikov Date: Mon, 5 Feb 2024 18:27:40 +0300 Subject: [PATCH] Fix body hiding in openapi schema - Fixed condition to hide Body from openapi --- fastapi/openapi/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index 5bfb5acef..628a9978d 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -138,7 +138,11 @@ def get_openapi_operation_request_body( ], separate_input_output_schemas: bool = True, ) -> Optional[Dict[str, Any]]: - if not body_field: + if ( + not body_field + or not isinstance(body_field.field_info, Body) + or not body_field.field_info.include_in_schema + ): return None assert isinstance(body_field, ModelField) body_schema = get_schema_from_model_field( @@ -148,7 +152,7 @@ def get_openapi_operation_request_body( field_mapping=field_mapping, separate_input_output_schemas=separate_input_output_schemas, ) - field_info = cast(Body, body_field.field_info) + field_info = body_field.field_info request_media_type = field_info.media_type required = body_field.required request_body_oai: Dict[str, Any] = {}