Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TOTOleHero committed Dec 20, 2020
1 parent 0939da9 commit b85dd3a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion swagger_to_uml.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def uml(self):
if lower or upper:
bounds = '{lower}:{upper}'.format(lower=lower, upper=upper)

type_str = '{items}[{bounds}]'.format(items=self.items, bounds=bounds)
type_str = '{items}[{bounds}]'.format(items=self.ref_type, bounds=bounds)
else:
type_str = self.type

Expand Down Expand Up @@ -381,9 +381,30 @@ def __init__(self, definitions, paths):
self.definitions = definitions # type: List[Definition]
self.paths = paths # type: List[Path]


@staticmethod
def from_dict(d):
definitions = [Definition.from_dict(name, definition) for name, definition in d.get('definitions',{}).items()]

# extract all class extensions
extensions={}
for definition in definitions:
if definition.allOf:
for ref in definition.allOf:
extensions[definition.name] = ref


# reduce ref_type if multiple
for definition in definitions:
for property in definition.properties:
if isinstance(property.ref_type,list):
ref_type={}
for ref in property.ref_type:
ref_type[extensions[ref]] = True
property.ref_type = list(ref_type.keys())
if len(property.ref_type) == 1:
property.ref_type = property.ref_type[0]

paths = [Path.from_dict(d, path_name, path) for path_name, path in d['paths'].items()]
return Swagger(definitions=definitions, paths=paths)

Expand Down

0 comments on commit b85dd3a

Please sign in to comment.