|
23 | 23 | INDENT2 as II,
|
24 | 24 | INDENT3 as III,
|
25 | 25 | INDENT4 as IIII,
|
| 26 | + INDENT5 as IIIII, |
26 | 27 | )
|
27 | 28 |
|
28 | 29 |
|
@@ -381,6 +382,9 @@ def _generate_from_method_for_class(
|
381 | 382 |
|
382 | 383 | blocks.append(Stripped(args_init_writer.getvalue()))
|
383 | 384 |
|
| 385 | + if cls.serialization.with_model_type: |
| 386 | + blocks.append(Stripped("string? modelType = null;")) |
| 387 | + |
384 | 388 | # endregion
|
385 | 389 |
|
386 | 390 | # region Switch on property name
|
@@ -419,11 +423,42 @@ def _generate_from_method_for_class(
|
419 | 423 | return None, errors
|
420 | 424 |
|
421 | 425 | if cls.serialization.with_model_type:
|
| 426 | + model_type = naming.json_model_type(cls.name) |
| 427 | + |
422 | 428 | cases.append(
|
423 | 429 | Stripped(
|
424 |
| - """\ |
| 430 | + f"""\ |
425 | 431 | case "modelType":
|
426 |
| - continue;""" |
| 432 | +{I}{{ |
| 433 | +{II}if (keyValue.Value == null) |
| 434 | +{II}{{ |
| 435 | +{III}error = new Reporting.Error( |
| 436 | +{IIII}"Expected a model type, but got null"); |
| 437 | +{III}return null; |
| 438 | +{II}}} |
| 439 | +{II}modelType = DeserializeImplementation.StringFrom( |
| 440 | +{III}keyValue.Value, |
| 441 | +{III}out error); |
| 442 | +{II}if (error != null) |
| 443 | +{II}{{ |
| 444 | +{III}error.PrependSegment( |
| 445 | +{IIII}new Reporting.NameSegment( |
| 446 | +{IIIII}"modelType")); |
| 447 | +{III}return null; |
| 448 | +{II}}} |
| 449 | +
|
| 450 | +{II}if (modelType != "{model_type}") |
| 451 | +{II}{{ |
| 452 | +{III}error = new Reporting.Error( |
| 453 | +{IIII}"Expected the model type '{model_type}', " + |
| 454 | +{IIII}$"but got {{modelType}}"); |
| 455 | +{III}error.PrependSegment( |
| 456 | +{IIII}new Reporting.NameSegment( |
| 457 | +{IIIII}"modelType")); |
| 458 | +{III}return null; |
| 459 | +{II}}} |
| 460 | +{II}break; |
| 461 | +{I}}}""" |
427 | 462 | )
|
428 | 463 | )
|
429 | 464 |
|
@@ -482,6 +517,19 @@ def _generate_from_method_for_class(
|
482 | 517 |
|
483 | 518 | blocks.append(Stripped(required_check_writer.getvalue()))
|
484 | 519 |
|
| 520 | + if cls.serialization.with_model_type: |
| 521 | + blocks.append( |
| 522 | + Stripped( |
| 523 | + f"""\ |
| 524 | +if (modelType == null) |
| 525 | +{{ |
| 526 | +{I}error = new Reporting.Error( |
| 527 | +{II}"Required property \\"modelType\\" is missing"); |
| 528 | +{I}return null; |
| 529 | +}}""" |
| 530 | + ) |
| 531 | + ) |
| 532 | + |
485 | 533 | # endregion
|
486 | 534 |
|
487 | 535 | # region Pass in arguments to the constructor
|
|
0 commit comments