Implement _value_to_dict validation attribute#3434
Open
ipspace wants to merge 4 commits into
Open
Conversation
The _value_to_dict validation attribute transforms a non-dict value into a dictionary using the value of the _value_to_dict key as the template dictionary. You can use it whenever you have a dict attribute that can accept non-dict values. Sample use case included in the PR: BGP communities
Owner
Author
There was a problem hiding this comment.
Pull request overview
This PR introduces a new validation schema capability (_value_to_dict) that allows non-dict values to be transformed into dicts using a template mapping, and applies it to simplify BGP community handling by moving conversion logic from Python into the data model.
Changes:
- Added
_value_to_dictsupport in the core validation engine and documented the new schema key. - Updated BGP module attribute schema to use
_value_to_dictforbgp.community, removing the bespoke transformation/validation code frombgp.py. - Added/updated coverage and error-output fixtures to validate the new behavior (including BGP communities and a custom datatype example).
Reviewed changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/errors/bgp-community.log | Updates expected validation errors for BGP community inputs under the new schema-driven handling. |
| tests/coverage/input/value-as-dict.yml | New coverage topology exercising _value_to_dict (custom type + BGP community). |
| tests/coverage/expected/value-as-dict.yml | New expected transformed output for the _value_to_dict coverage topology. |
| netsim/modules/bgp.yml | Switches bgp.community to schema-driven transformation using _value_to_dict. |
| netsim/modules/bgp.py | Removes old imperative bgp.community transformation/validation logic now handled by the validator/schema. |
| netsim/data/validate.py | Implements _value_to_dict transformation support in the validation engine. |
| docs/dev/validation.md | Documents _value_to_dict with examples (including BGP community). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jbemmel
reviewed
Jun 3, 2026
| if not isinstance(data,dict) and '_value_to_dict' in data_type and parent is not None: | ||
| try: | ||
| parent[key] = transform_value_to_dict(data,data_type._value_to_dict) | ||
| except Exception as ex: |
Collaborator
There was a problem hiding this comment.
When does transform_value_to_dict throw?
jbemmel
reviewed
Jun 3, 2026
| attributes: | ||
| node: | ||
| role: | ||
| name: |
Collaborator
There was a problem hiding this comment.
Could add _required for name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The _value_to_dict validation attribute transforms a non-dict value into a dictionary using the value of the _value_to_dict key as the template dictionary. You can use it whenever you have a dict attribute that can accept non-dict values.
Sample use case included in the PR: BGP communities