73
73
_DEFAULT_OPENAPI_RESPONSE_DESCRIPTION = "Successful Response"
74
74
_ROUTE_REGEX = "^{}$"
75
75
_JSON_DUMP_CALL = partial (json .dumps , separators = ("," , ":" ), cls = Encoder )
76
+ _DEFAULT_CONTENT_TYPE = "application/json"
76
77
77
78
ResponseEventT = TypeVar ("ResponseEventT" , bound = BaseProxyEvent )
78
79
ResponseT = TypeVar ("ResponseT" )
@@ -265,7 +266,7 @@ def __init__(
265
266
self ,
266
267
body : Any = None ,
267
268
status_code : int = 200 ,
268
- content_type : str = "application/json" ,
269
+ content_type : str = _DEFAULT_CONTENT_TYPE ,
269
270
session_attributes : dict [str , Any ] | None = None ,
270
271
prompt_session_attributes : dict [str , Any ] | None = None ,
271
272
knowledge_bases_configuration : list [dict [str , Any ]] | None = None ,
@@ -329,7 +330,7 @@ def is_json(self) -> bool:
329
330
content_type = self .headers .get ("Content-Type" , "" )
330
331
if isinstance (content_type , list ):
331
332
content_type = content_type [0 ]
332
- return content_type .startswith ("application/json" )
333
+ return content_type .startswith (_DEFAULT_CONTENT_TYPE )
333
334
334
335
335
336
class Route :
@@ -601,7 +602,7 @@ def _get_openapi_path(
601
602
operation_responses : dict [int , OpenAPIResponse ] = {
602
603
422 : {
603
604
"description" : "Validation Error" ,
604
- "content" : {"application/json" : {"schema" : {"$ref" : f"{ COMPONENT_REF_PREFIX } HTTPValidationError" }}},
605
+ "content" : {_DEFAULT_CONTENT_TYPE : {"schema" : {"$ref" : f"{ COMPONENT_REF_PREFIX } HTTPValidationError" }}},
605
606
},
606
607
}
607
608
@@ -610,7 +611,9 @@ def _get_openapi_path(
610
611
http_code = self .custom_response_validation_http_code .value
611
612
operation_responses [http_code ] = {
612
613
"description" : "Response Validation Error" ,
613
- "content" : {"application/json" : {"schema" : {"$ref" : f"{ COMPONENT_REF_PREFIX } ResponseValidationError" }}},
614
+ "content" : {
615
+ _DEFAULT_CONTENT_TYPE : {"schema" : {"$ref" : f"{ COMPONENT_REF_PREFIX } ResponseValidationError" }},
616
+ },
614
617
}
615
618
# Add model definition
616
619
definitions ["ResponseValidationError" ] = response_validation_error_response_definition
@@ -623,7 +626,7 @@ def _get_openapi_path(
623
626
# Case 1: there is not 'content' key
624
627
if "content" not in response :
625
628
response ["content" ] = {
626
- "application/json" : self ._openapi_operation_return (
629
+ _DEFAULT_CONTENT_TYPE : self ._openapi_operation_return (
627
630
param = dependant .return_param ,
628
631
model_name_map = model_name_map ,
629
632
field_mapping = field_mapping ,
@@ -674,7 +677,7 @@ def _get_openapi_path(
674
677
# Add the response schema to the OpenAPI 200 response
675
678
operation_responses [200 ] = {
676
679
"description" : self .response_description or _DEFAULT_OPENAPI_RESPONSE_DESCRIPTION ,
677
- "content" : {"application/json" : response_schema },
680
+ "content" : {_DEFAULT_CONTENT_TYPE : response_schema },
678
681
}
679
682
680
683
operation ["responses" ] = operation_responses
@@ -1664,7 +1667,7 @@ def _add_resolver_response_validation_error_response_to_route(
1664
1667
response_validation_error_response = {
1665
1668
"description" : "Response Validation Error" ,
1666
1669
"content" : {
1667
- "application/json" : {
1670
+ _DEFAULT_CONTENT_TYPE : {
1668
1671
"schema" : {"$ref" : f"{ COMPONENT_REF_PREFIX } ResponseValidationError" },
1669
1672
},
1670
1673
},
@@ -2183,7 +2186,7 @@ def swagger_handler():
2183
2186
if query_params .get ("format" ) == "json" :
2184
2187
return Response (
2185
2188
status_code = 200 ,
2186
- content_type = "application/json" ,
2189
+ content_type = _DEFAULT_CONTENT_TYPE ,
2187
2190
body = escaped_spec ,
2188
2191
)
2189
2192
0 commit comments