Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Provide context for errors #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions flask_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
- Added basic_path parameter
"""
import inspect
import logging
import yaml
import re
import os

from collections import defaultdict

logger = logging.getLogger(__name__)

def _sanitize(comment):
return comment.replace('\n', '<br/>') if comment else comment
Expand Down Expand Up @@ -47,27 +49,31 @@ def _doc_from_file(path):


def _parse_docstring(obj, process_doc, from_file_keyword, base_path):
first_line, other_lines, swag = None, None, None
full_doc = inspect.getdoc(obj)
if full_doc:
if from_file_keyword is not None:
from_file = _find_from_file(full_doc, from_file_keyword, base_path)
if from_file:
full_doc_from_file = _doc_from_file(from_file)
if full_doc_from_file:
full_doc = full_doc_from_file
line_feed = full_doc.find('\n')
if line_feed != -1:
first_line = process_doc(full_doc[:line_feed])
yaml_sep = full_doc[line_feed+1:].find('---')
if yaml_sep != -1:
other_lines = process_doc(full_doc[line_feed+1:line_feed+yaml_sep])
swag = yaml.full_load(full_doc[line_feed+yaml_sep:])
try:
first_line, other_lines, swag = None, None, None
full_doc = inspect.getdoc(obj)
if full_doc:
if from_file_keyword is not None:
from_file = _find_from_file(full_doc, from_file_keyword, base_path)
if from_file:
full_doc_from_file = _doc_from_file(from_file)
if full_doc_from_file:
full_doc = full_doc_from_file
line_feed = full_doc.find('\n')
if line_feed != -1:
first_line = process_doc(full_doc[:line_feed])
yaml_sep = full_doc[line_feed+1:].find('---')
if yaml_sep != -1:
other_lines = process_doc(full_doc[line_feed+1:line_feed+yaml_sep])
swag = yaml.full_load(full_doc[line_feed+yaml_sep:])
else:
other_lines = process_doc(full_doc[line_feed+1:])
else:
other_lines = process_doc(full_doc[line_feed+1:])
else:
first_line = full_doc
return first_line, other_lines, swag
first_line = full_doc
return first_line, other_lines, swag
except Exception as e:
logger.error("Failed to parse docstring for %s: %s", obj, e)
raise


def _extract_definitions(alist, level=None):
Expand Down