Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f77ea0a
Author: Isaac Hernandez <isaacfi@gmail.com>
Date:   Tue Jul 9 21:12:29 2019 -0500

    Improvement solution for issue 311

    I've wrote a better solution replacing the references '$ref' with the recursive method __replace_ref

commit 3cb03f4
Author: Isaac Hernandez <isaacfi@gmail.com>
Date:   Mon Jun 24 08:52:34 2019 -0500

    Fix index

commit bdcfd33
Author: Isaac Hernandez <isaacfi@gmail.com>
Date:   Mon Jun 24 08:51:30 2019 -0500

    Validate if the referenced schema has divider

commit bf9c17e
Author: Isaac Hernandez <isaacfi@gmail.com>
Date:   Sun Jun 23 23:31:04 2019 -0500

    Remove the spaces in 361 line

commit bf262df
Author: Isaac Hernandez <isaacfi@gmail.com>
Date:   Sun Jun 23 23:16:13 2019 -0500

    Solution for issue #311

    Sorry for all changes, but it pretend to solve the issue #311 I loaded the main_def from file
  • Loading branch information
billyrrr committed Aug 8, 2019
1 parent 86cb827 commit 5ee9586
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions flasgger/utils.py
Expand Up @@ -6,6 +6,7 @@
import inspect
import os
import re
import sys
import jsonschema
import yaml
from six import string_types, text_type
Expand Down Expand Up @@ -251,6 +252,40 @@ def wrapper(*args, **kwargs):
return decorator


def __replace_ref(schema: dict, relative_path: str):
""" TODO: add dev docs
:param schema:
:param relative_path:
:return:
"""
absolute_path = os.path.dirname(sys.argv[0])
new_value = {}
for key, value in schema.items():
if isinstance(value, dict):
new_value[key] = __replace_ref(value, relative_path)
elif key == '$ref':
if len(value) > 0 and value[0] == '/':
file_ref_path = absolute_path + value
else:
file_ref_path = relative_path + '/' + value
relative_path = os.path.dirname(file_ref_path)
with open(file_ref_path) as file:
file_content = file.read()
comment_index = file_content.rfind('---')
if comment_index > 0:
comment_index = comment_index + 3
else:
comment_index = 0
content = yaml.safe_load((file_content[comment_index:]))
new_value = content
if isinstance(content, dict):
new_value = __replace_ref(content, relative_path)
else:
new_value[key] = value
return new_value


def validate(
data=None, schema_id=None, filepath=None, root=None, definition=None,
specs=None, validation_function=None, validation_error_handler=None):
Expand Down Expand Up @@ -359,6 +394,13 @@ def validate(
if validation_function is None:
validation_function = jsonschema.validate

absolute_path = os.path.dirname(sys.argv[0])
if filepath is None:
relative_path = absolute_path
else:
relative_path = os.path.dirname(filepath)
main_def = __replace_ref(main_def, relative_path)

try:
validation_function(data, main_def)
except Exception as err:
Expand Down Expand Up @@ -808,6 +850,7 @@ class LazyString(StringLike):
A lazy string *without* caching. The resulting string is regenerated for
every request.
"""

def __init__(self, func):
"""
Creates a `LazyString` object using `func` as the delayed closure.
Expand All @@ -826,6 +869,7 @@ class CachedLazyString(LazyString):
"""
A lazy string with caching.
"""

def __init__(self, func):
"""
Uses `__init__()` from the parent and initializes a cache.
Expand Down

1 comment on commit 5ee9586

@billyrrr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit was authored by: Isaac Hernandez isaacfi@gmail.com @isaacfi

Author information was lost when squashing commit. Please see #312 for the original commit history. Sorry for any inconvenience.

Please sign in to comment.