|
5 | 5 | import openapi_python_client.schema as oai
|
6 | 6 | from openapi_python_client import Config
|
7 | 7 | from openapi_python_client.parser.errors import PropertyError
|
8 |
| -from openapi_python_client.parser.properties import DateTimeProperty, ModelProperty, StringProperty |
| 8 | +from openapi_python_client.parser.properties import ( |
| 9 | + Class, |
| 10 | + EnumProperty, |
| 11 | + IntProperty, |
| 12 | + StringProperty, |
| 13 | +) |
9 | 14 |
|
10 | 15 |
|
11 | 16 | @pytest.mark.parametrize(
|
@@ -242,6 +247,156 @@ def test_conflicting_properties_same_types(self, model_property_factory, string_
|
242 | 247 |
|
243 | 248 | assert isinstance(result, PropertyError)
|
244 | 249 |
|
| 250 | + def test_allof_string_and_string_enum(self, model_property_factory): |
| 251 | + from openapi_python_client.parser.properties import Schemas |
| 252 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 253 | + |
| 254 | + data = oai.Schema.construct( |
| 255 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 256 | + ) |
| 257 | + enum_property = EnumProperty( |
| 258 | + name="", |
| 259 | + required=True, |
| 260 | + nullable=True, |
| 261 | + values={"foo": "foo"}, |
| 262 | + class_info=Class(name="AnEnum", module_name="an_enum"), |
| 263 | + value_type=str, |
| 264 | + default=None, |
| 265 | + ) |
| 266 | + schemas = Schemas( |
| 267 | + classes_by_reference={ |
| 268 | + "/First": model_property_factory(optional_properties=[string_property()]), |
| 269 | + "/Second": model_property_factory(optional_properties=[enum_property]), |
| 270 | + } |
| 271 | + ) |
| 272 | + |
| 273 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 274 | + assert result.optional_props[0] == enum_property |
| 275 | + |
| 276 | + def test_allof_string_enum_and_string(self, model_property_factory): |
| 277 | + from openapi_python_client.parser.properties import Schemas |
| 278 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 279 | + |
| 280 | + data = oai.Schema.construct( |
| 281 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 282 | + ) |
| 283 | + enum_property = EnumProperty( |
| 284 | + name="", |
| 285 | + required=True, |
| 286 | + nullable=True, |
| 287 | + values={"foo": "foo"}, |
| 288 | + class_info=Class(name="AnEnum", module_name="an_enum"), |
| 289 | + value_type=str, |
| 290 | + default=None, |
| 291 | + ) |
| 292 | + schemas = Schemas( |
| 293 | + classes_by_reference={ |
| 294 | + "/First": model_property_factory(optional_properties=[enum_property]), |
| 295 | + "/Second": model_property_factory(optional_properties=[string_property()]), |
| 296 | + } |
| 297 | + ) |
| 298 | + |
| 299 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 300 | + assert result.optional_props[0] == enum_property |
| 301 | + |
| 302 | + def test_allof_int_and_int_enum(self, model_property_factory): |
| 303 | + from openapi_python_client.parser.properties import Schemas |
| 304 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 305 | + |
| 306 | + data = oai.Schema.construct( |
| 307 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 308 | + ) |
| 309 | + enum_property = EnumProperty( |
| 310 | + name="", |
| 311 | + required=True, |
| 312 | + nullable=True, |
| 313 | + values={"foo": 1}, |
| 314 | + class_info=Class(name="AnEnum", module_name="an_enum"), |
| 315 | + value_type=int, |
| 316 | + default=None, |
| 317 | + ) |
| 318 | + schemas = Schemas( |
| 319 | + classes_by_reference={ |
| 320 | + "/First": model_property_factory( |
| 321 | + optional_properties=[IntProperty(name="", required=True, nullable=True, default=None)] |
| 322 | + ), |
| 323 | + "/Second": model_property_factory(optional_properties=[enum_property]), |
| 324 | + } |
| 325 | + ) |
| 326 | + |
| 327 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 328 | + assert result.optional_props[0] == enum_property |
| 329 | + |
| 330 | + def test_allof_string_enums(self, model_property_factory): |
| 331 | + from openapi_python_client.parser.properties import Schemas |
| 332 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 333 | + |
| 334 | + data = oai.Schema.construct( |
| 335 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 336 | + ) |
| 337 | + enum_property1 = EnumProperty( |
| 338 | + name="", |
| 339 | + required=True, |
| 340 | + nullable=True, |
| 341 | + values={"foo": "foo", "bar": "bar"}, |
| 342 | + class_info=Class(name="AnEnum1", module_name="an_enum1"), |
| 343 | + value_type=str, |
| 344 | + default=None, |
| 345 | + ) |
| 346 | + enum_property2 = EnumProperty( |
| 347 | + name="", |
| 348 | + required=True, |
| 349 | + nullable=True, |
| 350 | + values={"foo": "foo"}, |
| 351 | + class_info=Class(name="AnEnum2", module_name="an_enum2"), |
| 352 | + value_type=str, |
| 353 | + default=None, |
| 354 | + ) |
| 355 | + schemas = Schemas( |
| 356 | + classes_by_reference={ |
| 357 | + "/First": model_property_factory(optional_properties=[enum_property1]), |
| 358 | + "/Second": model_property_factory(optional_properties=[enum_property2]), |
| 359 | + } |
| 360 | + ) |
| 361 | + |
| 362 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 363 | + assert result.optional_props[0] == enum_property2 |
| 364 | + |
| 365 | + def test_allof_int_enums(self, model_property_factory): |
| 366 | + from openapi_python_client.parser.properties import Schemas |
| 367 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 368 | + |
| 369 | + data = oai.Schema.construct( |
| 370 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 371 | + ) |
| 372 | + enum_property1 = EnumProperty( |
| 373 | + name="", |
| 374 | + required=True, |
| 375 | + nullable=True, |
| 376 | + values={"foo": 1, "bar": 2}, |
| 377 | + class_info=Class(name="AnEnum1", module_name="an_enum1"), |
| 378 | + value_type=int, |
| 379 | + default=None, |
| 380 | + ) |
| 381 | + enum_property2 = EnumProperty( |
| 382 | + name="", |
| 383 | + required=True, |
| 384 | + nullable=True, |
| 385 | + values={"foo": 1}, |
| 386 | + class_info=Class(name="AnEnum2", module_name="an_enum2"), |
| 387 | + value_type=int, |
| 388 | + default=None, |
| 389 | + ) |
| 390 | + schemas = Schemas( |
| 391 | + classes_by_reference={ |
| 392 | + "/First": model_property_factory(optional_properties=[enum_property1]), |
| 393 | + "/Second": model_property_factory(optional_properties=[enum_property2]), |
| 394 | + } |
| 395 | + ) |
| 396 | + |
| 397 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 398 | + assert result.optional_props[0] == enum_property2 |
| 399 | + |
245 | 400 | def test_duplicate_properties(self, model_property_factory, string_property_factory):
|
246 | 401 | from openapi_python_client.parser.properties import Schemas
|
247 | 402 | from openapi_python_client.parser.properties.model_property import _process_properties
|
|
0 commit comments