-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/Question: Adding Records to Array Objects #278
Comments
This feature or capability is also important for me as instances of the array need to be dynamically updated. |
Also a bug fix to handle literals being passed in
The way you do this is by setting the item validation to a reference in the schema so it gets a named object. You can then instantiate that object and add it to the array. You can also do this with the anonymous object, but if the array item type is complicated (i.e. an object) that isn't going to be as obvious. See an example of how this works here (specifically line 178): python-jsonschema-objects/test/test_pytest.py Lines 147 to 179 in 0dde416
I just added a fix to handle an instantiation error I saw when making sure that example worked, as part of the linked PR. |
tests: Add a test to validate expected behavior on #278
Fix included in 0.5.3. |
Thanks, really appreciate the pointer and the fix, working great. I am inferring the type name and using getattr to get it from the schema, there is probably a place in the special vars to grab that name from (e.g., in the list, vs inferring it), but it's working fine as is for now. |
What are you trying to do?
I have a schema which has a list of other objects in it. This is read in and recognized as an item by the library as type=='array', and the array of typed objects are under the 'data' attribute.
Do you have an idea about how this should work?
I'd like to be able to programmatically add new elements to the array. I may be missing something - likely am - but don't see how I can ask the object to let me initalize a new object of the list element, so that I can add it.
For example:
Data has:
I wish to programatically add to the itemList array to add:
<item name='another', id=59>
Is there a generator/init accessible that I'm missing somewhere?
The text was updated successfully, but these errors were encountered: