@@ -70,6 +70,21 @@ def constructor(self) -> str:
70
70
return f"{ self .python_type } (response.text)"
71
71
72
72
73
+ @dataclass
74
+ class BytesResponse (Response ):
75
+ """ Response is a basic type """
76
+
77
+ python_type : str = "bytes"
78
+
79
+ def return_string (self ) -> str :
80
+ """ How this Response should be represented as a return type """
81
+ return self .python_type
82
+
83
+ def constructor (self ) -> str :
84
+ """ How the return value of this response should be constructed """
85
+ return f"{ self .python_type } (response.content)"
86
+
87
+
73
88
openapi_types_to_python_type_strings = {
74
89
"string" : "str" ,
75
90
"number" : "float" ,
@@ -88,6 +103,8 @@ def response_from_data(*, status_code: int, data: Union[oai.Response, oai.Refere
88
103
schema_data = None
89
104
if "application/json" in content :
90
105
schema_data = data .content ["application/json" ].media_type_schema
106
+ elif "application/octet-stream" in content :
107
+ schema_data = data .content ["application/octet-stream" ].media_type_schema
91
108
elif "text/html" in content :
92
109
schema_data = data .content ["text/html" ].media_type_schema
93
110
@@ -101,6 +118,8 @@ def response_from_data(*, status_code: int, data: Union[oai.Response, oai.Refere
101
118
return Response (status_code = status_code )
102
119
if response_type == "array" and isinstance (schema_data .items , oai .Reference ):
103
120
return ListRefResponse (status_code = status_code , reference = Reference .from_ref (schema_data .items .ref ),)
121
+ if response_type == "string" and schema_data .schema_format in {"binary" , "base64" }:
122
+ return BytesResponse (status_code = status_code )
104
123
if response_type in openapi_types_to_python_type_strings :
105
124
return BasicResponse (status_code = status_code , openapi_type = response_type )
106
125
return ParseError (data = data , detail = f"Unrecognized type { schema_data .type } " )
0 commit comments