@@ -184,14 +184,14 @@ def test_response_from_data_reference(mocker, any_property_factory):
184
184
185
185
186
186
@pytest .mark .parametrize (
187
- "ref_string" ,
187
+ "ref_string,expected_error_string " ,
188
188
[
189
- "#/components/responses/Nonexistent" ,
190
- "malformed- references-string" ,
191
- "#/components/something-that-isnt-responses/ErrorResponse" ,
189
+ ( "#/components/responses/Nonexistent" , "Could not find" ) ,
190
+ ( "https://remote-reference" , "Remote references" ) ,
191
+ ( "#/components/something-that-isnt-responses/ErrorResponse" , "not allowed in responses" ) ,
192
192
],
193
193
)
194
- def test_response_from_data_reference_errors (ref_string , mocker , any_property_factory ):
194
+ def test_response_from_data_invalid_reference (ref_string , expected_error_string , mocker , any_property_factory ):
195
195
from openapi_python_client .parser import responses
196
196
197
197
prop = any_property_factory ()
@@ -213,6 +213,38 @@ def test_response_from_data_reference_errors(ref_string, mocker, any_property_fa
213
213
)
214
214
215
215
assert isinstance (response , ParseError )
216
+ assert expected_error_string in response .detail
217
+
218
+
219
+ def test_response_from_data_ref_to_response_that_is_a_ref (mocker , any_property_factory ):
220
+ from openapi_python_client .parser import responses
221
+
222
+ prop = any_property_factory ()
223
+ mocker .patch .object (responses , "property_from_data" , return_value = (prop , Schemas ()))
224
+ predefined_response_base_data = oai .Response .model_construct (
225
+ description = "" ,
226
+ content = {"application/json" : oai .MediaType .model_construct (media_type_schema = "something" )},
227
+ )
228
+ predefined_response_data = oai .Reference .model_construct (
229
+ ref = "#/components/references/BaseResponse" ,
230
+ )
231
+ config = MagicMock ()
232
+ config .content_type_overrides = {}
233
+
234
+ response , schemas = responses .response_from_data (
235
+ status_code = 400 ,
236
+ data = oai .Reference .model_construct (ref = "#/components/schemas/ErrorResponse" ),
237
+ schemas = Schemas (),
238
+ responses = {
239
+ "BaseResponse" : predefined_response_base_data ,
240
+ "ErrorResponse" : predefined_response_data ,
241
+ },
242
+ parent_name = "parent" ,
243
+ config = config ,
244
+ )
245
+
246
+ assert isinstance (response , ParseError )
247
+ assert "not allowed in responses" in response .detail
216
248
217
249
218
250
def test_response_from_data_content_type_overrides (any_property_factory ):
0 commit comments