@@ -69,7 +69,7 @@ def asdict(self) -> Dict[str, Any]:
69
69
"featureSchemaId" : self .feature_schema_id ,
70
70
"label" : self .label ,
71
71
"value" : self .value ,
72
- "options" : [o .asdict () for o in self .options ]
72
+ "options" : [o .asdict (is_subclass = True ) for o in self .options ]
73
73
}
74
74
75
75
def add_option (self , option : 'Classification' ) -> None :
@@ -159,29 +159,25 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
159
159
feature_schema_id = dictionary .get ("featureSchemaId" , None ),
160
160
scope = cls .Scope (dictionary .get ("scope" , cls .Scope .GLOBAL )))
161
161
162
- def asdict (self ) -> Dict [str , Any ]:
162
+ def asdict (self , is_subclass : bool = False ) -> Dict [str , Any ]:
163
163
if self .class_type in self ._REQUIRES_OPTIONS \
164
164
and len (self .options ) < 1 :
165
165
raise InconsistentOntologyException (
166
166
f"Classification '{ self .instructions } ' requires options." )
167
- return {
168
- "type" :
169
- self .class_type .value ,
170
- "instructions" :
171
- self .instructions ,
172
- "name" :
173
- self .name ,
174
- "required" :
175
- self .required ,
167
+ classification = {
168
+ "type" : self .class_type .value ,
169
+ "instructions" : self .instructions ,
170
+ "name" : self .name ,
171
+ "required" : self .required ,
176
172
"options" : [o .asdict () for o in self .options ],
177
- "schemaNodeId" :
178
- self .schema_id ,
179
- "featureSchemaId" :
180
- self .feature_schema_id ,
181
- "scope" :
182
- self .scope .value
183
- if self .scope is not None else self .Scope .GLOBAL .value
173
+ "schemaNodeId" : self .schema_id ,
174
+ "featureSchemaId" : self .feature_schema_id
184
175
}
176
+ if is_subclass :
177
+ return classification
178
+ classification [
179
+ "scope" ] = self .scope .value if self .scope is not None else self .Scope .GLOBAL .value
180
+ return classification
185
181
186
182
def add_option (self , option : Option ) -> None :
187
183
if option .value in (o .value for o in self .options ):
@@ -258,7 +254,9 @@ def asdict(self) -> Dict[str, Any]:
258
254
"name" : self .name ,
259
255
"required" : self .required ,
260
256
"color" : self .color ,
261
- "classifications" : [c .asdict () for c in self .classifications ],
257
+ "classifications" : [
258
+ c .asdict (is_subclass = True ) for c in self .classifications
259
+ ],
262
260
"schemaNodeId" : self .schema_id ,
263
261
"featureSchemaId" : self .feature_schema_id
264
262
}
0 commit comments