mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
generate_openapi: fix enums when they are declared as const
Fixes: #2781
This commit is contained in:
parent
8cb3974eff
commit
3f059ec1e0
1 changed files with 35 additions and 1 deletions
|
@ -474,7 +474,41 @@ class SchemaProperty(object):
|
||||||
|
|
||||||
elif p.key.name == 'allowedValues':
|
elif p.key.name == 'allowedValues':
|
||||||
self.type = 'enum'
|
self.type = 'enum'
|
||||||
|
if p.value.type == 'ArrayExpression':
|
||||||
self.enum = [e.value.lower() for e in p.value.elements]
|
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':
|
elif p.key.name == 'blackbox':
|
||||||
self.blackbox = True
|
self.blackbox = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue