File tree Expand file tree Collapse file tree
samples/server/petstore/python-fastapi/src/openapi_server/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ def from_dict(cls, obj: Dict) -> Self:
8484 if not isinstance (obj , dict ):
8585 return cls .model_validate (obj )
8686
87+ # raise errors for additional fields in the input
88+ for _key in obj .keys ():
89+ if _key not in cls .__properties :
90+ raise ValueError ("Error due to additional fields (not defined in ApiResponse) in the input: " + _key )
91+
8792 _obj = cls .model_validate ({
8893 "code" : obj .get ("code" ),
8994 "type" : obj .get ("type" ),
Original file line number Diff line number Diff line change @@ -94,6 +94,11 @@ def from_dict(cls, obj: Dict) -> Self:
9494 if not isinstance (obj , dict ):
9595 return cls .model_validate (obj )
9696
97+ # raise errors for additional fields in the input
98+ for _key in obj .keys ():
99+ if _key not in cls .__properties :
100+ raise ValueError ("Error due to additional fields (not defined in Category) in the input: " + _key )
101+
97102 _obj = cls .model_validate ({
98103 "id" : obj .get ("id" ),
99104 "name" : obj .get ("name" )
Original file line number Diff line number Diff line change @@ -98,6 +98,11 @@ def from_dict(cls, obj: Dict) -> Self:
9898 if not isinstance (obj , dict ):
9999 return cls .model_validate (obj )
100100
101+ # raise errors for additional fields in the input
102+ for _key in obj .keys ():
103+ if _key not in cls .__properties :
104+ raise ValueError ("Error due to additional fields (not defined in Order) in the input: " + _key )
105+
101106 _obj = cls .model_validate ({
102107 "id" : obj .get ("id" ),
103108 "petId" : obj .get ("petId" ),
Original file line number Diff line number Diff line change @@ -109,6 +109,11 @@ def from_dict(cls, obj: Dict) -> Self:
109109 if not isinstance (obj , dict ):
110110 return cls .model_validate (obj )
111111
112+ # raise errors for additional fields in the input
113+ for _key in obj .keys ():
114+ if _key not in cls .__properties :
115+ raise ValueError ("Error due to additional fields (not defined in Pet) in the input: " + _key )
116+
112117 _obj = cls .model_validate ({
113118 "id" : obj .get ("id" ),
114119 "category" : Category .from_dict (obj .get ("category" )) if obj .get ("category" ) is not None else None ,
Original file line number Diff line number Diff line change @@ -83,6 +83,11 @@ def from_dict(cls, obj: Dict) -> Self:
8383 if not isinstance (obj , dict ):
8484 return cls .model_validate (obj )
8585
86+ # raise errors for additional fields in the input
87+ for _key in obj .keys ():
88+ if _key not in cls .__properties :
89+ raise ValueError ("Error due to additional fields (not defined in Tag) in the input: " + _key )
90+
8691 _obj = cls .model_validate ({
8792 "id" : obj .get ("id" ),
8893 "name" : obj .get ("name" )
Original file line number Diff line number Diff line change @@ -89,6 +89,11 @@ def from_dict(cls, obj: Dict) -> Self:
8989 if not isinstance (obj , dict ):
9090 return cls .model_validate (obj )
9191
92+ # raise errors for additional fields in the input
93+ for _key in obj .keys ():
94+ if _key not in cls .__properties :
95+ raise ValueError ("Error due to additional fields (not defined in User) in the input: " + _key )
96+
9297 _obj = cls .model_validate ({
9398 "id" : obj .get ("id" ),
9499 "username" : obj .get ("username" ),
You can’t perform that action at this time.
0 commit comments