mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 03:20:12 +03:00
Drop unused 'OpenAPISchemaGenerator'
This commit is contained in:
parent
4ec0fd6d2d
commit
9590e11101
|
@ -480,43 +480,3 @@ class SchemaGenerator(BaseSchemaGenerator):
|
|||
|
||||
# Default action, eg "/users/", "/users/{pk}/"
|
||||
return named_path_components + [action]
|
||||
|
||||
|
||||
class OpenAPISchemaGenerator(BaseSchemaGenerator):
|
||||
|
||||
def get_paths(self, request=None):
|
||||
result = OrderedDict()
|
||||
|
||||
paths, view_endpoints = self._get_paths_and_endpoints(request)
|
||||
|
||||
# Only generate the path prefix for paths that will be included
|
||||
if not paths:
|
||||
return None
|
||||
prefix = self.determine_path_prefix(paths)
|
||||
|
||||
for path, method, view in view_endpoints:
|
||||
if not self.has_view_permissions(path, method, view):
|
||||
continue
|
||||
operation = view.schema.get_operation(path, method)
|
||||
subpath = path[len(prefix):]
|
||||
result.setdefault(subpath, {})
|
||||
result[subpath][method.lower()] = operation
|
||||
|
||||
return result
|
||||
|
||||
def get_schema(self, request=None, public=False):
|
||||
"""
|
||||
Generate a `coreapi.Document` representing the API schema.
|
||||
"""
|
||||
self._initialise_endpoints()
|
||||
|
||||
paths = self.get_paths(None if public else request)
|
||||
if not paths:
|
||||
return None
|
||||
|
||||
schema = {
|
||||
'basePath': self.url,
|
||||
'paths': paths,
|
||||
}
|
||||
|
||||
return schema
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
import unittest
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.test import RequestFactory, TestCase, override_settings
|
||||
|
||||
from rest_framework.compat import uritemplate
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.schemas.generators import OpenAPISchemaGenerator
|
||||
from rest_framework.schemas.inspectors import OpenAPIAutoSchema
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
def create_request(path):
|
||||
factory = RequestFactory()
|
||||
request = Request(factory.get(path))
|
||||
return request
|
||||
|
||||
|
||||
def create_view(view_cls, method, request):
|
||||
generator = OpenAPISchemaGenerator()
|
||||
view = generator.create_view(view_cls.as_view(), method, request)
|
||||
return view
|
||||
|
||||
|
||||
@unittest.skipUnless(uritemplate, 'uritemplate is not installed')
|
||||
class TestOperationIntrospection(TestCase):
|
||||
|
||||
def test_path_without_parameters(self):
|
||||
path = '/example/'
|
||||
method = 'GET'
|
||||
|
||||
view = create_view(
|
||||
views.ExampleListView,
|
||||
method,
|
||||
create_request(path)
|
||||
)
|
||||
inspector = OpenAPIAutoSchema()
|
||||
inspector.view = view
|
||||
|
||||
operation = inspector.get_operation(path, method)
|
||||
assert operation == {
|
||||
'parameters': []
|
||||
}
|
||||
|
||||
def test_path_with_id_parameter(self):
|
||||
path = '/example/{id}/'
|
||||
method = 'GET'
|
||||
|
||||
view = create_view(
|
||||
views.ExampleDetailView,
|
||||
method,
|
||||
create_request(path)
|
||||
)
|
||||
inspector = OpenAPIAutoSchema()
|
||||
inspector.view = view
|
||||
operation = inspector.get_operation(path, method)
|
||||
assert operation == {
|
||||
'parameters': [{
|
||||
'description': '',
|
||||
'in': 'path',
|
||||
'name': 'id',
|
||||
'required': True,
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
@unittest.skipUnless(uritemplate, 'uritemplate is not installed')
|
||||
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.inspectors.OpenAPIAutoSchema'})
|
||||
class TestGenerator(TestCase):
|
||||
|
||||
def test_paths_construction(self):
|
||||
"""Construction of the `paths` key."""
|
||||
patterns = [
|
||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
||||
]
|
||||
generator = OpenAPISchemaGenerator(patterns=patterns)
|
||||
generator._initialise_endpoints()
|
||||
|
||||
paths = generator.get_paths()
|
||||
|
||||
assert 'example/' in paths
|
||||
example_operations = paths['example/']
|
||||
assert len(example_operations) == 2
|
||||
assert 'get' in example_operations
|
||||
assert 'post' in example_operations
|
||||
|
||||
def test_schema_construction(self):
|
||||
"""Construction of the top level dictionary."""
|
||||
patterns = [
|
||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
||||
]
|
||||
generator = OpenAPISchemaGenerator(patterns=patterns)
|
||||
|
||||
request = create_request('/')
|
||||
schema = generator.get_schema(request=request)
|
||||
|
||||
assert 'basePath' in schema
|
||||
assert 'paths' in schema
|
Loading…
Reference in New Issue
Block a user