summaryrefslogtreecommitdiffstats
path: root/openapi
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2019-11-05 11:22:02 +0100
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>2019-11-05 12:01:04 +0100
commit7d62d0920c438ea36819005c642d76668c49cdc7 (patch)
treeb748d6f27d681286327e9f4c235222ccef5628e7 /openapi
parentb7878542895335c9bdd16ec8d3bf972cf1762faa (diff)
downloadwekan-7d62d0920c438ea36819005c642d76668c49cdc7.tar.gz
wekan-7d62d0920c438ea36819005c642d76668c49cdc7.tar.bz2
wekan-7d62d0920c438ea36819005c642d76668c49cdc7.zip
generate_openapi: add a little bit more verbosity when we get an Error
Diffstat (limited to 'openapi')
-rw-r--r--openapi/generate_openapi.py50
1 files changed, 40 insertions, 10 deletions
diff --git a/openapi/generate_openapi.py b/openapi/generate_openapi.py
index b1d7ab84..7c152f3c 100644
--- a/openapi/generate_openapi.py
+++ b/openapi/generate_openapi.py
@@ -677,6 +677,27 @@ class Schemas(object):
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):
schemas = {}
@@ -686,17 +707,19 @@ def parse_schemas(schemas_dir):
files.sort()
for filename in files:
path = os.path.join(root, filename)
- with open(path) as f:
- data = ''.join(f.readlines())
- try:
- # if the file failed, it's likely it doesn't contain a schema
- program = esprima.parseModule(data, options={'comment': True, 'loc': True})
- except:
- continue
+ try:
+ # if the file failed, it's likely it doesn't contain a schema
+ context = Context(path)
+ except:
+ continue
- current_schema = None
- jsdocs = [c for c in program.comments
- if c.type == 'Block' and c.value.startswith('*\n')]
+ program = context.program
+
+ 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:
@@ -742,6 +765,13 @@ def parse_schemas(schemas_dir):
if j.loc.end.line + 1 == operation.loc.start.line]
if bool(jsdoc):
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