mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 23:40:13 +01:00
generate_openapi: add a little bit more verbosity when we get an Error
This commit is contained in:
parent
b787854289
commit
7d62d0920c
1 changed files with 40 additions and 10 deletions
|
|
@ -677,6 +677,27 @@ class Schemas(object):
|
||||||
print(' - {}'.format(f))
|
print(' - {}'.format(f))
|
||||||
|
|
||||||
|
|
||||||
|
class Context(object):
|
||||||
|
def __init__(self, path):
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
with open(path) as f:
|
||||||
|
self._txt = f.readlines()
|
||||||
|
|
||||||
|
data = ''.join(self._txt)
|
||||||
|
self.program = esprima.parseModule(data,
|
||||||
|
options={
|
||||||
|
'comment': True,
|
||||||
|
'loc': True
|
||||||
|
})
|
||||||
|
|
||||||
|
def txt_for(self, statement):
|
||||||
|
return self.text_at(statement.loc.start.line, statement.loc.end.line)
|
||||||
|
|
||||||
|
def text_at(self, begin, end):
|
||||||
|
return ''.join(self._txt[begin - 1:end])
|
||||||
|
|
||||||
|
|
||||||
def parse_schemas(schemas_dir):
|
def parse_schemas(schemas_dir):
|
||||||
|
|
||||||
schemas = {}
|
schemas = {}
|
||||||
|
|
@ -686,17 +707,19 @@ def parse_schemas(schemas_dir):
|
||||||
files.sort()
|
files.sort()
|
||||||
for filename in files:
|
for filename in files:
|
||||||
path = os.path.join(root, filename)
|
path = os.path.join(root, filename)
|
||||||
with open(path) as f:
|
try:
|
||||||
data = ''.join(f.readlines())
|
# if the file failed, it's likely it doesn't contain a schema
|
||||||
try:
|
context = Context(path)
|
||||||
# if the file failed, it's likely it doesn't contain a schema
|
except:
|
||||||
program = esprima.parseModule(data, options={'comment': True, 'loc': True})
|
continue
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
current_schema = None
|
program = context.program
|
||||||
jsdocs = [c for c in program.comments
|
|
||||||
if c.type == 'Block' and c.value.startswith('*\n')]
|
current_schema = None
|
||||||
|
jsdocs = [c for c in program.comments
|
||||||
|
if c.type == 'Block' and c.value.startswith('*\n')]
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
for statement in program.body:
|
for statement in program.body:
|
||||||
|
|
||||||
|
|
@ -742,6 +765,13 @@ def parse_schemas(schemas_dir):
|
||||||
if j.loc.end.line + 1 == operation.loc.start.line]
|
if j.loc.end.line + 1 == operation.loc.start.line]
|
||||||
if bool(jsdoc):
|
if bool(jsdoc):
|
||||||
entry_point.doc = jsdoc[0]
|
entry_point.doc = jsdoc[0]
|
||||||
|
except TypeError:
|
||||||
|
logger.warning(context.txt_for(statement))
|
||||||
|
logger.error('{}:{}-{} can not parse {}'.format(path,
|
||||||
|
statement.loc.start.line,
|
||||||
|
statement.loc.end.line,
|
||||||
|
statement.type))
|
||||||
|
raise
|
||||||
|
|
||||||
return schemas, entry_points
|
return schemas, entry_points
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue