From 634c3f4eb305c7d5681ed56155cdc173b9a753b4 Mon Sep 17 00:00:00 2001 From: Philipp Feustel Date: Thu, 26 Apr 2018 18:37:38 +0200 Subject: [PATCH] Resolve relations to referenced resources when references follow a naming convention. --- swagger_to_uml.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/swagger_to_uml.py b/swagger_to_uml.py index 45b8e3c..e2c6f50 100755 --- a/swagger_to_uml.py +++ b/swagger_to_uml.py @@ -27,6 +27,9 @@ def resolve_ref(ref): return ref.split('/')[-1] +def upcase_first_letter(s): + return s[0].upper() + s[1:] + class Property: def __init__(self, name, type, required, example=None, description=None, default=None, enum=None, format=None, @@ -83,6 +86,13 @@ def from_dict(property_name, d, required): # type is given or must be resolved from $ref if 'type' in type_dict: type_str = type_dict['type'] + + if type_str == "string" and 'format' in type_dict and type_dict['format'].endswith("ResourceId"): + ref_type = upcase_first_letter(type_dict['format'][0 : -10]) + + if type_str == "array" and 'items' in type_dict and 'type' in type_dict['items'] and "string" == type_dict['items']['type'] and 'format' in type_dict['items'] and type_dict['items']['format'].endswith("ResourceId"): + ref_type = upcase_first_letter(type_dict['items']['format'][0 : -10]) + elif '$ref' in type_dict: type_str = resolve_ref(type_dict['$ref']) ref_type = type_str