From 6fd52096a3a4f97b5f22c3970e563ba625d30632 Mon Sep 17 00:00:00 2001 From: Pierre Gronlier Date: Wed, 26 Jun 2024 13:27:22 +0200 Subject: [PATCH 1/2] Exclude Acccept, Content-type and Authorization header from the list of parameters Based on the OpenAPI specs, some headers are not supposed to be listed directly as parameters https://swagger.io/docs/specification/describing-parameters/#header-parameters --- blacksheep/server/openapi/v3.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blacksheep/server/openapi/v3.py b/blacksheep/server/openapi/v3.py index 920d041..434828f 100644 --- a/blacksheep/server/openapi/v3.py +++ b/blacksheep/server/openapi/v3.py @@ -858,7 +858,9 @@ def get_parameter_location_for_binder( return ParameterLocation.QUERY if isinstance(binder, CookieBinder): return ParameterLocation.COOKIE - if isinstance(binder, HeaderBinder): + if (isinstance(binder, HeaderBinder) + # exclude those specific header value per documentation https://swagger.io/docs/specification/describing-parameters/#header-parameters + and binder.parameter_name.lower() not in ['content-type', 'accept', 'authorization']): return ParameterLocation.HEADER return None From fbce7a8bb22eb7d7e590553d49b2247d49ece594 Mon Sep 17 00:00:00 2001 From: Roberto Prevato Date: Thu, 16 Jan 2025 07:03:28 +0100 Subject: [PATCH 2/2] Make linters happy --- blacksheep/server/openapi/v3.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/blacksheep/server/openapi/v3.py b/blacksheep/server/openapi/v3.py index 3e6407b..baa8a8a 100644 --- a/blacksheep/server/openapi/v3.py +++ b/blacksheep/server/openapi/v3.py @@ -861,9 +861,14 @@ def get_parameter_location_for_binder( return ParameterLocation.QUERY if isinstance(binder, CookieBinder): return ParameterLocation.COOKIE - if (isinstance(binder, HeaderBinder) - # exclude those specific header value per documentation https://swagger.io/docs/specification/describing-parameters/#header-parameters - and binder.parameter_name.lower() not in ['content-type', 'accept', 'authorization']): + + # exclude those specific header value per documentation + # https://swagger.io/docs/specification/describing-parameters/#header-parameters + if isinstance(binder, HeaderBinder) and binder.parameter_name.lower() not in [ + "content-type", + "accept", + "authorization", + ]: return ParameterLocation.HEADER return None