@@ -41,15 +41,36 @@ def test_vetiver_model_array_prototype():
4141 description = None ,
4242 metadata = None ,
4343 )
44+ try :
45+ json_schema = v .prototype .model_json_schema ()
46+ expected = {
47+ "properties" : {
48+ "0" : {"example" : 96 , "title" : "0" , "type" : "integer" },
49+ "1" : {"example" : 11 , "title" : "1" , "type" : "integer" },
50+ "2" : {"example" : 33 , "title" : "2" , "type" : "integer" },
51+ },
52+ "required" : ["0" , "1" , "2" ],
53+ "title" : "prototype" ,
54+ "type" : "object" ,
55+ }
56+ except AttributeError : # pydantic v1
57+ json_schema = v .prototype .schema_json ()
58+ expected = '{\
59+ "title": "prototype", \
60+ "type": "object", \
61+ "properties": {"0": {"title": "0", "example": 96, "type": "integer"}, \
62+ "1": {"title": "1", "example": 11, "type": "integer"}, \
63+ "2": {"title": "2", "example": 33, "type": "integer"}}, \
64+ "required": ["0", "1", "2"]}'
4465
4566 assert v .model == model
4667 assert issubclass (v .prototype , vetiver .Prototype )
4768 # change to model_construct for pydantic v3
4869 assert isinstance (v .prototype .construct (), pydantic .BaseModel )
49- assert v . prototype . construct (). __dict__ == { "0" : 96 , "1" : 11 , "2" : 33 }
70+ assert json_schema == expected
5071
5172
52- @pytest .mark .parametrize ("prototype_data" , [{"B" : 96 , "C" : 0 , "D" : 0 }, X_df ])
73+ @pytest .mark .parametrize ("prototype_data" , [{"B" : 96 , "C" : 11 , "D" : 33 }, X_df ])
5374def test_vetiver_model_dict_like_prototype (prototype_data ):
5475 v = VetiverModel (
5576 model = model ,
@@ -63,7 +84,30 @@ def test_vetiver_model_dict_like_prototype(prototype_data):
6384 assert v .model == model
6485 # change to model_construct for pydantic v3
6586 assert isinstance (v .prototype .construct (), pydantic .BaseModel )
66- assert v .prototype .construct ().B == 96
87+
88+ try :
89+ json_schema = v .prototype .model_json_schema ()
90+ expected = {
91+ "properties" : {
92+ "B" : {"example" : 96 , "title" : "B" , "type" : "integer" },
93+ "C" : {"example" : 11 , "title" : "C" , "type" : "integer" },
94+ "D" : {"example" : 33 , "title" : "D" , "type" : "integer" },
95+ },
96+ "required" : ["B" , "C" , "D" ],
97+ "title" : "prototype" ,
98+ "type" : "object" ,
99+ }
100+ except AttributeError : # pydantic v1
101+ json_schema = v .prototype .schema_json ()
102+ expected = '{\
103+ "title": "prototype", \
104+ "type": "object", \
105+ "properties": {"B": {"title": "B", "example": 96, "type": "integer"}, \
106+ "C": {"title": "C", "example": 11, "type": "integer"}, \
107+ "D": {"title": "D", "example": 33, "type": "integer"}}, \
108+ "required": ["B", "C", "D"]}'
109+
110+ assert json_schema == expected
67111
68112
69113@pytest .mark .parametrize ("prototype_data" , [MockPrototype (B = 4 , C = 0 , D = 0 ), None ])
0 commit comments