Commit dc28b95
feat(config): add additionalProperties support to generated config models (#5131)
* add additional_properties support to generated config models
Schema types with additionalProperties (Sampler, SpanExporter,
TextMapPropagator, ExperimentalResourceDetector, etc.) now capture
unknown keyword arguments in an additional_properties dict field.
This enables plugin/custom component names to flow through typed
dataclasses without modifying the codegen tool.
Implementation:
- _additional_properties_support decorator in _common.py wraps the
dataclass __init__ to route unknown kwargs into additional_properties
- Custom dataclass.jinja2 template for datamodel-codegen conditionally
applies the decorator and field when additionalPropertiesType is set
- pyproject.toml updated with custom-template-dir and additional-imports
- models.py regenerated via tox -e generate-config-from-jsonschema
Assisted-by: Claude Opus 4.6
* update CHANGELOG with PR number #5131
* fix CI: plain assignment, pylint suppression for intentional unknown kwargs
- Replace object.__setattr__ with plain self.additional_properties = extra
(no frozen dataclasses, simpler and more Pythonic)
- Add pylint disable=unexpected-keyword-arg on test lines that intentionally
pass unknown kwargs to verify the decorator captures them
- Add comment explaining setattr usage for __signature__ (pyright workaround)
Assisted-by: Claude Opus 4.6
* use ClassVar annotation instead of dataclass field for additional_properties
ClassVar tells type checkers the attribute exists without creating a
dataclass field. This means additional_properties doesn't appear in
__init__ signature, dataclasses.fields(), asdict(), or repr() — only
schema-defined fields show up. The decorator sets it as a plain
instance attribute at runtime.
Assisted-by: Claude Opus 4.6
* rename _additional_properties_support to _additional_properties
Shorter name, aligns with the attribute it creates.
Assisted-by: Claude Opus 4.6
---------
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>1 parent 44d8911 commit dc28b95
8 files changed
Lines changed: 264 additions & 3 deletions
File tree
- opentelemetry-sdk
- codegen
- src/opentelemetry/sdk/_configuration
- tests/_configuration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
26 | 62 | | |
27 | 63 | | |
28 | 64 | | |
| |||
Lines changed: 28 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
350 | 352 | | |
351 | 353 | | |
352 | 354 | | |
| 355 | + | |
353 | 356 | | |
354 | 357 | | |
355 | 358 | | |
356 | 359 | | |
357 | 360 | | |
358 | 361 | | |
| 362 | + | |
359 | 363 | | |
360 | 364 | | |
361 | 365 | | |
| |||
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| 507 | + | |
503 | 508 | | |
504 | 509 | | |
505 | 510 | | |
506 | 511 | | |
507 | 512 | | |
508 | 513 | | |
| 514 | + | |
509 | 515 | | |
510 | 516 | | |
511 | 517 | | |
| |||
524 | 530 | | |
525 | 531 | | |
526 | 532 | | |
| 533 | + | |
527 | 534 | | |
528 | 535 | | |
529 | 536 | | |
530 | 537 | | |
531 | 538 | | |
532 | 539 | | |
| 540 | + | |
533 | 541 | | |
534 | 542 | | |
| 543 | + | |
535 | 544 | | |
536 | 545 | | |
537 | 546 | | |
| 547 | + | |
538 | 548 | | |
539 | 549 | | |
| 550 | + | |
540 | 551 | | |
541 | 552 | | |
542 | 553 | | |
| 554 | + | |
543 | 555 | | |
544 | 556 | | |
545 | 557 | | |
| |||
549 | 561 | | |
550 | 562 | | |
551 | 563 | | |
| 564 | + | |
552 | 565 | | |
553 | 566 | | |
554 | 567 | | |
555 | 568 | | |
556 | 569 | | |
557 | 570 | | |
| 571 | + | |
558 | 572 | | |
559 | 573 | | |
560 | 574 | | |
| |||
567 | 581 | | |
568 | 582 | | |
569 | 583 | | |
| 584 | + | |
570 | 585 | | |
571 | 586 | | |
572 | 587 | | |
573 | 588 | | |
| 589 | + | |
574 | 590 | | |
575 | 591 | | |
| 592 | + | |
576 | 593 | | |
577 | 594 | | |
578 | 595 | | |
579 | 596 | | |
580 | 597 | | |
581 | 598 | | |
| 599 | + | |
582 | 600 | | |
583 | 601 | | |
584 | 602 | | |
| |||
639 | 657 | | |
640 | 658 | | |
641 | 659 | | |
| 660 | + | |
642 | 661 | | |
643 | 662 | | |
644 | 663 | | |
645 | 664 | | |
| 665 | + | |
646 | 666 | | |
647 | 667 | | |
648 | 668 | | |
| |||
697 | 717 | | |
698 | 718 | | |
699 | 719 | | |
| 720 | + | |
700 | 721 | | |
701 | 722 | | |
702 | 723 | | |
| |||
710 | 731 | | |
711 | 732 | | |
712 | 733 | | |
| 734 | + | |
713 | 735 | | |
714 | 736 | | |
715 | 737 | | |
| |||
741 | 763 | | |
742 | 764 | | |
743 | 765 | | |
| 766 | + | |
744 | 767 | | |
745 | 768 | | |
746 | 769 | | |
| |||
750 | 773 | | |
751 | 774 | | |
752 | 775 | | |
| 776 | + | |
753 | 777 | | |
754 | 778 | | |
755 | 779 | | |
| |||
768 | 792 | | |
769 | 793 | | |
770 | 794 | | |
| 795 | + | |
771 | 796 | | |
772 | 797 | | |
773 | 798 | | |
| |||
777 | 802 | | |
778 | 803 | | |
779 | 804 | | |
| 805 | + | |
780 | 806 | | |
781 | 807 | | |
782 | 808 | | |
| |||
0 commit comments