Skip to content

Commit 3d36982

Browse files
committed
Fix optimizing Union[Unknown] or Union[None]
1 parent a7d2a1c commit 3d36982

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

json_to_models/generator.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,24 @@ def _optimize_union(self, t: DUnion):
237237

238238
types = [self.optimize_type(t) for t in other_types]
239239

240-
if Unknown in types:
241-
types.remove(Unknown)
242-
243-
optional = False
244-
if Null in types:
245-
optional = True
246-
while Null in types:
247-
types.remove(Null)
248240

249241
if len(types) > 1:
242+
if Unknown in types:
243+
types.remove(Unknown)
244+
245+
optional = False
246+
if Null in types:
247+
optional = True
248+
while Null in types:
249+
types.remove(Null)
250+
250251
meta_type = DUnion(*types)
251252
if len(meta_type.types) == 1:
252253
meta_type = meta_type.types[0]
254+
255+
if optional:
256+
return DOptional(meta_type)
253257
else:
254258
meta_type = types[0]
255259

256-
if optional:
257-
return DOptional(meta_type)
258-
else:
259-
return meta_type
260+
return meta_type

testing_tools/real_apis/swagger.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def load_data() -> dict:
2929

3030
def main():
3131
data = load_data()
32-
del data["paths"]
3332

3433
gen = MetadataGenerator(
3534
dict_keys_regex=[],

0 commit comments

Comments
 (0)