File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
python_jsonschema_objects Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class ProtocolBase(collections.MutableMapping):
3636 """
3737 __propinfo__ = {}
3838 __required__ = set ()
39+ __object_attr_list__ = set (["_properties" , "_extended_properties" ])
3940
4041 def as_dict (self ):
4142 """ Return a dictionary containing the current values
@@ -164,7 +165,7 @@ def __init__(self, **props):
164165 # self.validate()
165166
166167 def __setattr__ (self , name , val ):
167- if name . startswith ( "_" ) :
168+ if name in self . __object_attr_list__ :
168169 object .__setattr__ (self , name , val )
169170 elif name in self .__propinfo__ :
170171 # If its in __propinfo__, then it actually has a property defined.
Original file line number Diff line number Diff line change @@ -23,6 +23,37 @@ def test_regression_9():
2323 builder = pjs .ObjectBuilder (schema )
2424 builder .build_classes ()
2525
26+
27+ def test_underscore_properties ():
28+ schema = {
29+ "$schema" : "http://json-schema.org/schema#" ,
30+ "title" : "AggregateQuery" ,
31+ "type" : "object" ,
32+ "properties" : {
33+ "group" : {
34+ "type" : "object" ,
35+ "properties" : {}
36+ }
37+ }
38+ }
39+
40+ builder = pjs .ObjectBuilder (schema )
41+ ns = builder .build_classes ()
42+ my_obj_type = ns .Aggregatequery
43+ request_object = my_obj_type (
44+ group = {
45+ "_id" : {"foo_id" : "$foo_id" ,
46+ "foo_type" : "$foo_type" },
47+ "foo" : {"$sum" : 1 }, }
48+ )
49+
50+ assert request_object .group ._id == {
51+ "foo_id" : "$foo_id" ,
52+ "foo_type" : "$foo_type"
53+ }
54+
55+
56+
2657def test_array_regressions ():
2758 schema = {
2859 "$schema" : "http://json-schema.org/schema#" ,
@@ -399,4 +430,4 @@ def test_strict_mode():
399430 with pytest .raises (pjs .ValidationError ):
400431 ns = builder .build_classes (strict = True )
401432 NameData = ns .NameData
402- NameData (lastName = "hello" )
433+ NameData (lastName = "hello" )
You can’t perform that action at this time.
0 commit comments