diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2019-11-05 12:56:48 +0100 |
---|---|---|
committer | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2019-11-05 12:58:06 +0100 |
commit | 3f059ec1e0408c71d43d3b9be1b5b1c76dd4fab0 (patch) | |
tree | 9fc00b7aa024fc23d579b8178c6f55c641ab99fb /openapi/generate_openapi.py | |
parent | 8cb3974eff47481744cc60ac1901bced5c760daf (diff) | |
download | wekan-3f059ec1e0408c71d43d3b9be1b5b1c76dd4fab0.tar.gz wekan-3f059ec1e0408c71d43d3b9be1b5b1c76dd4fab0.tar.bz2 wekan-3f059ec1e0408c71d43d3b9be1b5b1c76dd4fab0.zip |
generate_openapi: fix enums when they are declared as const
Fixes: #2781
Diffstat (limited to 'openapi/generate_openapi.py')
-rw-r--r-- | openapi/generate_openapi.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/openapi/generate_openapi.py b/openapi/generate_openapi.py index 9c15b0d3..54526416 100644 --- a/openapi/generate_openapi.py +++ b/openapi/generate_openapi.py @@ -474,7 +474,41 @@ class SchemaProperty(object): elif p.key.name == 'allowedValues': self.type = 'enum' - self.enum = [e.value.lower() for e in p.value.elements] + if p.value.type == 'ArrayExpression': + self.enum = [e.value.lower() for e in p.value.elements] + elif p.value.type == 'Identifier': + # tree wide lookout for the identifier + def find_variable(elem, match): + if isinstance(elem, list): + for value in elem: + ret = find_variable(value, match) + if ret is not None: + return ret + + try: + items = elem.items() + except AttributeError: + return None + except TypeError: + return None + + if (elem.type == 'VariableDeclarator' and + elem.id.name == match): + return elem + + for type, value in items: + ret = find_variable(value, match) + if ret is not None: + return ret + + return None + + elem = find_variable(context.program.body, p.value.name) + + if elem.init.type != 'ArrayExpression': + raise TypeError('can not find "{}"'.format(p.value.name)) + + self.enum = [e.value.lower() for e in elem.init.elements] elif p.key.name == 'blackbox': self.blackbox = True |