Skip to content
This repository was archived by the owner on Jan 11, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: marcgibbons/django-rest-swagger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: StepicOrg/django-rest-swagger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 7 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 12, 2014

  1. Copy the full SHA
    12cabd9 View commit details

Commits on Apr 30, 2014

  1. Copy the full SHA
    664ed39 View commit details
  2. python 3 compatibility

    andrvb committed Apr 30, 2014
    Copy the full SHA
    0b2b144 View commit details
  3. use enabled_methods option

    andrvb committed Apr 30, 2014
    Copy the full SHA
    ac6d649 View commit details
  4. Copy the full SHA
    c821044 View commit details
  5. Copy the full SHA
    4ea703e View commit details

Commits on May 19, 2015

  1. Copy the full SHA
    d2a8dee View commit details
2 changes: 1 addition & 1 deletion rest_framework_swagger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = '0.1.14'
VERSION = '0.1.14.3'

DEFAULT_SWAGGER_SETTINGS = {
'exclude_namespaces': [],
24 changes: 19 additions & 5 deletions rest_framework_swagger/docgenerator.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
from .introspectors import APIViewIntrospector, \
ViewSetIntrospector, BaseMethodIntrospector, IntrospectorHelper, \
get_resolved_value, YAMLDocstringParser
from . import SWAGGER_SETTINGS


class DocumentationGenerator(object):
@@ -50,7 +51,8 @@ def get_operations(self, api):

for method_introspector in introspector:
if not isinstance(method_introspector, BaseMethodIntrospector) or \
method_introspector.get_http_method() == "OPTIONS":
method_introspector.get_http_method() == "OPTIONS" or \
method_introspector.get_http_method().lower() not in SWAGGER_SETTINGS['enabled_methods']:
continue # No one cares. I impose JSON.

doc_parser = YAMLDocstringParser(
@@ -70,10 +72,6 @@ def get_operations(self, api):
'type': response_type,
}

if doc_parser.yaml_error is not None:
operation['notes'] += "<pre>YAMLError:\n {err}</pre>".format(
err=doc_parser.yaml_error)

response_messages = doc_parser.get_response_messages()
parameters = doc_parser.discover_parameters(
inspector=method_introspector)
@@ -84,6 +82,22 @@ def get_operations(self, api):
if response_messages:
operation['responseMessages'] = response_messages

# override operation from callback's docstring
callback_doc_parser = YAMLDocstringParser(docstring=callback.__doc__)
method = method_introspector.method.lower()
if method in callback_doc_parser.object:
overrides = callback_doc_parser.object[method]
allowed_keys = {'method', 'summary', 'nickname', 'notes', 'type', 'parameters', 'responseMessages'}
if isinstance(overrides, dict):
for key, value in overrides.items():
if key in allowed_keys:
operation[key] = value

for parser in [doc_parser, callback_doc_parser]:
if parser.yaml_error is not None:
operation['notes'] += "<pre>YAMLError:\n {err}</pre>".format(
err=parser.yaml_error)

operations.append(operation)

return operations
17 changes: 9 additions & 8 deletions rest_framework_swagger/introspectors.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import inspect
import re
import itertools
import yaml
import importlib

@@ -304,14 +305,14 @@ def __iter__(self):
yield ViewSetMethodIntrospector(self, methods[method], method)

def _resolve_methods(self):
if not hasattr(self.pattern.callback, 'func_code') or \
not hasattr(self.pattern.callback, 'func_closure') or \
not hasattr(self.pattern.callback.func_code, 'co_freevars') or \
'actions' not in self.pattern.callback.func_code.co_freevars:
if not hasattr(self.pattern.callback, '__code__') or \
not hasattr(self.pattern.callback, '__closure__') or \
not hasattr(self.pattern.callback.__code__, 'co_freevars') or \
'actions' not in self.pattern.callback.__code__.co_freevars:
raise RuntimeError('Unable to use callback invalid closure/function specified.')

idx = self.pattern.callback.func_code.co_freevars.index('actions')
return self.pattern.callback.func_closure[idx].cell_contents
idx = self.pattern.callback.__code__.co_freevars.index('actions')
return self.pattern.callback.__closure__[idx].cell_contents


class ViewSetMethodIntrospector(BaseMethodIntrospector):
@@ -520,7 +521,7 @@ def load_obj_from_docstring(self, docstring):
yaml_string = formatting.dedent(yaml_string)
try:
return yaml.load(yaml_string)
except yaml.YAMLError, e:
except yaml.YAMLError as e:
self.yaml_error = e
return None

@@ -754,7 +755,7 @@ def _merge_params(params1, params2, key):
Merges parameters lists by key
"""
merged = OrderedDict()
for item in params1 + params2:
for item in itertools.chain(params1, params2):
merged[item[key]] = item

return [val for (_, val) in merged.items()]
2 changes: 1 addition & 1 deletion rest_framework_swagger/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from importlib import import_module

from django.core.urlresolvers import RegexURLResolver
from django.conf import settings
@@ -7,7 +8,6 @@
from django.contrib.admindocs.utils import trim_docstring
from django.http import HttpRequest
from django.test import TestCase
from django.utils.importlib import import_module
from django.views.generic import View

from rest_framework.views import APIView
2 changes: 1 addition & 1 deletion rest_framework_swagger/urlparser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from importlib import import_module

from django.conf import settings
from django.utils.importlib import import_module
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
from django.contrib.admindocs.views import simplify_regex