|
6 | 6 | import openapi_python_client.schema as oai
|
7 | 7 | from openapi_python_client import Config
|
8 | 8 | from openapi_python_client.parser.errors import PropertyError
|
9 |
| -from openapi_python_client.parser.properties import DateTimeProperty, ModelProperty, StringProperty |
| 9 | +from openapi_python_client.parser.properties import ( |
| 10 | + Class, |
| 11 | + DateTimeProperty, |
| 12 | + EnumProperty, |
| 13 | + IntProperty, |
| 14 | + ModelProperty, |
| 15 | + StringProperty, |
| 16 | + enum_property, |
| 17 | +) |
10 | 18 |
|
11 | 19 |
|
12 | 20 | def get_class():
|
@@ -275,6 +283,156 @@ def test_conflicting_properties_same_types(self, model_property_factory):
|
275 | 283 |
|
276 | 284 | assert isinstance(result, PropertyError)
|
277 | 285 |
|
| 286 | + def test_allof_string_and_string_enum(self, model_property_factory): |
| 287 | + from openapi_python_client.parser.properties import Schemas |
| 288 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 289 | + |
| 290 | + data = oai.Schema.construct( |
| 291 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 292 | + ) |
| 293 | + enum_property = EnumProperty( |
| 294 | + name="", |
| 295 | + required=True, |
| 296 | + nullable=True, |
| 297 | + values={"foo": "foo"}, |
| 298 | + class_info=Class(name="AnEnum", module_name="an_enum"), |
| 299 | + value_type=str, |
| 300 | + default=None, |
| 301 | + ) |
| 302 | + schemas = Schemas( |
| 303 | + classes_by_reference={ |
| 304 | + "/First": model_property_factory(optional_properties=[string_property()]), |
| 305 | + "/Second": model_property_factory(optional_properties=[enum_property]), |
| 306 | + } |
| 307 | + ) |
| 308 | + |
| 309 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 310 | + assert result.optional_props[0] == enum_property |
| 311 | + |
| 312 | + def test_allof_string_enum_and_string(self, model_property_factory): |
| 313 | + from openapi_python_client.parser.properties import Schemas |
| 314 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 315 | + |
| 316 | + data = oai.Schema.construct( |
| 317 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 318 | + ) |
| 319 | + enum_property = EnumProperty( |
| 320 | + name="", |
| 321 | + required=True, |
| 322 | + nullable=True, |
| 323 | + values={"foo": "foo"}, |
| 324 | + class_info=Class(name="AnEnum", module_name="an_enum"), |
| 325 | + value_type=str, |
| 326 | + default=None, |
| 327 | + ) |
| 328 | + schemas = Schemas( |
| 329 | + classes_by_reference={ |
| 330 | + "/First": model_property_factory(optional_properties=[enum_property]), |
| 331 | + "/Second": model_property_factory(optional_properties=[string_property()]), |
| 332 | + } |
| 333 | + ) |
| 334 | + |
| 335 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 336 | + assert result.optional_props[0] == enum_property |
| 337 | + |
| 338 | + def test_allof_int_and_int_enum(self, model_property_factory): |
| 339 | + from openapi_python_client.parser.properties import Schemas |
| 340 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 341 | + |
| 342 | + data = oai.Schema.construct( |
| 343 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 344 | + ) |
| 345 | + enum_property = EnumProperty( |
| 346 | + name="", |
| 347 | + required=True, |
| 348 | + nullable=True, |
| 349 | + values={"foo": 1}, |
| 350 | + class_info=Class(name="AnEnum", module_name="an_enum"), |
| 351 | + value_type=int, |
| 352 | + default=None, |
| 353 | + ) |
| 354 | + schemas = Schemas( |
| 355 | + classes_by_reference={ |
| 356 | + "/First": model_property_factory( |
| 357 | + optional_properties=[IntProperty(name="", required=True, nullable=True, default=None)] |
| 358 | + ), |
| 359 | + "/Second": model_property_factory(optional_properties=[enum_property]), |
| 360 | + } |
| 361 | + ) |
| 362 | + |
| 363 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 364 | + assert result.optional_props[0] == enum_property |
| 365 | + |
| 366 | + def test_allof_string_enums(self, model_property_factory): |
| 367 | + from openapi_python_client.parser.properties import Schemas |
| 368 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 369 | + |
| 370 | + data = oai.Schema.construct( |
| 371 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 372 | + ) |
| 373 | + enum_property1 = EnumProperty( |
| 374 | + name="", |
| 375 | + required=True, |
| 376 | + nullable=True, |
| 377 | + values={"foo": "foo", "bar": "bar"}, |
| 378 | + class_info=Class(name="AnEnum1", module_name="an_enum1"), |
| 379 | + value_type=str, |
| 380 | + default=None, |
| 381 | + ) |
| 382 | + enum_property2 = EnumProperty( |
| 383 | + name="", |
| 384 | + required=True, |
| 385 | + nullable=True, |
| 386 | + values={"foo": "foo"}, |
| 387 | + class_info=Class(name="AnEnum2", module_name="an_enum2"), |
| 388 | + value_type=str, |
| 389 | + default=None, |
| 390 | + ) |
| 391 | + schemas = Schemas( |
| 392 | + classes_by_reference={ |
| 393 | + "/First": model_property_factory(optional_properties=[enum_property1]), |
| 394 | + "/Second": model_property_factory(optional_properties=[enum_property2]), |
| 395 | + } |
| 396 | + ) |
| 397 | + |
| 398 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 399 | + assert result.optional_props[0] == enum_property2 |
| 400 | + |
| 401 | + def test_allof_int_enums(self, model_property_factory): |
| 402 | + from openapi_python_client.parser.properties import Schemas |
| 403 | + from openapi_python_client.parser.properties.model_property import _process_properties |
| 404 | + |
| 405 | + data = oai.Schema.construct( |
| 406 | + allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")] |
| 407 | + ) |
| 408 | + enum_property1 = EnumProperty( |
| 409 | + name="", |
| 410 | + required=True, |
| 411 | + nullable=True, |
| 412 | + values={"foo": 1, "bar": 2}, |
| 413 | + class_info=Class(name="AnEnum1", module_name="an_enum1"), |
| 414 | + value_type=int, |
| 415 | + default=None, |
| 416 | + ) |
| 417 | + enum_property2 = EnumProperty( |
| 418 | + name="", |
| 419 | + required=True, |
| 420 | + nullable=True, |
| 421 | + values={"foo": 1}, |
| 422 | + class_info=Class(name="AnEnum2", module_name="an_enum2"), |
| 423 | + value_type=int, |
| 424 | + default=None, |
| 425 | + ) |
| 426 | + schemas = Schemas( |
| 427 | + classes_by_reference={ |
| 428 | + "/First": model_property_factory(optional_properties=[enum_property1]), |
| 429 | + "/Second": model_property_factory(optional_properties=[enum_property2]), |
| 430 | + } |
| 431 | + ) |
| 432 | + |
| 433 | + result = _process_properties(data=data, schemas=schemas, class_name="", config=Config()) |
| 434 | + assert result.optional_props[0] == enum_property2 |
| 435 | + |
278 | 436 | def test_duplicate_properties(self, model_property_factory):
|
279 | 437 | from openapi_python_client.parser.properties import Schemas
|
280 | 438 | from openapi_python_client.parser.properties.model_property import _process_properties
|
|
0 commit comments