def test_from_router(self):
        patterns = [
            url(r'from-router', include(naming_collisions_router.urls)),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)

        with pytest.raises(ValueError):
            generator.get_schema()
    def test_manually_routing_nested_routes(self):
        patterns = [
            url(r'^test', simple_fbv),
            url(r'^test/list/', simple_fbv),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)

        with pytest.raises(ValueError):
            generator.get_schema()
Esempio n. 3
0
    def get(self, request):
        generator = SchemaGenerator(title='后端API文档',
                                    urlconf='chess_user.urls')
        schema = generator.get_schema(request=request)
        document = self.load_swagger_json(schema)

        return Response(document)
Esempio n. 4
0
 def get(self, request):
     # Define also the URL prefix for the current API version. Not very nice,
     # but did not find another way.
     generator = SchemaGenerator(
         title='QCAT API v2', url='/api/v2/', urlconf='api.urls.v2')
     schema = generator.get_schema(request=request, public=True)
     return Response(schema)
Esempio n. 5
0
    def get(self, request):
        generator = SchemaGenerator(title='ToDo',
                                    urlconf='apps.api.v1.urls',
                                    url="/api/v1/")
        schema = generator.get_schema(request=request)

        return Response(schema)
Esempio n. 6
0
    def get(self, request):
        generator = SchemaGenerator(title='AR_tree的API',
                                    urlconf='AR_tree.urls')
        schema = generator.get_schema(request=request)
        document = self.load_swagger_json(schema)

        return Response(document)
Esempio n. 7
0
 def get(self, request):
     generator = SchemaGenerator(title=title,
                                 url=url,
                                 patterns=patterns,
                                 urlconf=urlconf)
     schema = generator.get_schema(request=request, public=True)
     return Response(schema)
    def test_manually_routing_nested_routes(self):
        patterns = [
            url(r'^test', simple_fbv),
            url(r'^test/list/', simple_fbv),
        ]

        generator = SchemaGenerator(title='Naming Colisions',
                                    patterns=patterns)
        schema = generator.get_schema()

        expected = coreapi.Document(url='',
                                    title='Naming Colisions',
                                    content={
                                        'test': {
                                            'list': {
                                                'list':
                                                coreapi.Link(url='/test/list/',
                                                             action='get')
                                            },
                                            'list_0':
                                            coreapi.Link(url='/test',
                                                         action='get')
                                        }
                                    })

        assert expected == schema
Esempio n. 9
0
    def test_schema_for_regular_views(self):
        """
        Ensure that AutoField foreign keys are output as Integer.
        """
        generator = SchemaGenerator(title='Example API', patterns=self.patterns)
        schema = generator.get_schema()

        expected = coreapi.Document(
            url='',
            title='Example API',
            content={
                'example': {
                    'create': coreapi.Link(
                        url='/example/',
                        action='post',
                        encoding='application/json',
                        fields=[
                            coreapi.Field('name', required=True, location='form', schema=coreschema.String(title='Name')),
                            coreapi.Field('target', required=True, location='form', schema=coreschema.Integer(description='Target', title='Target')),
                        ]
                    )
                }
            }
        )
        assert schema == expected
    def test_manually_routing_generic_view(self):
        patterns = [
            url(r'^test', NamingCollisionView.as_view()),
            url(r'^test/retrieve/', NamingCollisionView.as_view()),
            url(r'^test/update/', NamingCollisionView.as_view()),

            # Fails with method names:
            url(r'^test/get/', NamingCollisionView.as_view()),
            url(r'^test/put/', NamingCollisionView.as_view()),
            url(r'^test/delete/', NamingCollisionView.as_view()),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)

        with pytest.raises(ValueError):
            generator.get_schema()
Esempio n. 11
0
 def get(self, request):
     generator = SchemaGenerator(
         title="CMDB-API",
         description='CMDB-接口平台',
     )
     schema = generator.get_schema(request=request)
     return Response(schema)
Esempio n. 12
0
 def get(self, request):
     # Define also the URL prefix for the current API version. Not very nice,
     # but did not find another way.
     generator = SchemaGenerator(
         title='QCAT API v2', url='/api/v2/', urlconf='api.urls.v2')
     schema = generator.get_schema(request=request, public=True)
     return Response(schema)
Esempio n. 13
0
 def get(self, request):
     generator = SchemaGenerator(
         title="RDMO API",
         patterns=urlpatterns,
     )
     schema = generator.get_schema(request=request)
     return Response(schema)
    def test_from_router(self):
        patterns = [
            url(r'from-router', include(naming_collisions_router.urls)),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
        schema = generator.get_schema()
        desc = schema['detail_0'].description  # not important here

        expected = coreapi.Document(
            url='',
            title='Naming Colisions',
            content={
                'detail': {
                    'detail_export': coreapi.Link(
                        url='/from-routercollision/detail/export/',
                        action='get',
                        description=desc)
                },
                'detail_0': coreapi.Link(
                    url='/from-routercollision/detail/',
                    action='get',
                    description=desc
                )
            }
        )

        assert schema == expected
Esempio n. 15
0
    def test_manually_routing_generic_view(self):
        patterns = [
            url(r'^test', NamingCollisionView.as_view()),
            url(r'^test/retrieve/', NamingCollisionView.as_view()),
            url(r'^test/update/', NamingCollisionView.as_view()),

            # Fails with method names:
            url(r'^test/get/', NamingCollisionView.as_view()),
            url(r'^test/put/', NamingCollisionView.as_view()),
            url(r'^test/delete/', NamingCollisionView.as_view()),
        ]

        generator = SchemaGenerator(title='Naming Colisions',
                                    patterns=patterns)

        schema = generator.get_schema()

        self._verify_cbv_links(schema['test']['delete'], '/test/delete/')
        self._verify_cbv_links(schema['test']['put'], '/test/put/')
        self._verify_cbv_links(schema['test']['get'], '/test/get/')
        self._verify_cbv_links(schema['test']['update'], '/test/update/')
        self._verify_cbv_links(schema['test']['retrieve'], '/test/retrieve/')
        self._verify_cbv_links(schema['test'],
                               '/test',
                               suffixes=(None, '0', None, '0'))
Esempio n. 16
0
    def test_from_router(self):
        patterns = [
            url(r'from-router', include(naming_collisions_router.urls)),
        ]

        generator = SchemaGenerator(title='Naming Colisions',
                                    patterns=patterns)
        schema = generator.get_schema()

        # not important here
        desc_0 = schema['detail']['detail_export'].description
        desc_1 = schema['detail_0'].description

        expected = coreapi.Document(
            url='',
            title='Naming Colisions',
            content={
                'detail': {
                    'detail_export':
                    coreapi.Link(url='/from-routercollision/detail/export/',
                                 action='get',
                                 description=desc_0)
                },
                'detail_0':
                coreapi.Link(url='/from-routercollision/detail/',
                             action='get',
                             description=desc_1)
            })

        assert schema == expected
Esempio n. 17
0
    def get(self, request):
        from burl.core.urls import api_v1
        api_url_patterns = [path('api/v1/', include(api_v1))]
        generator = SchemaGenerator(title='burl api',
                                    patterns=api_url_patterns)
        schema = generator.get_schema(request=request)

        return Response(schema)
Esempio n. 18
0
def schema_view(request):
    """
    Swagger test API
    """
    generator = SchemaGenerator(title='Rest Swagger')
    schema = generator.get_schema(request=request)

    return Response(schema)
Esempio n. 19
0
 def get(self, request):
     """."""
     generator = SchemaGenerator()
     schema = generator.get_schema(request=request)
     if not schema:
         raise exceptions.ValidationError(
             'The schema generator did not return a schema Document')
     return Response(schema)
Esempio n. 20
0
    def get(self, request):
        generator = SchemaGenerator(title='Geotrek API mobile',
                                    urlconf='geotrek.api.mobile.urls',
                                    url='/api/mobile',
                                    description="Mobile Geotrek API.")
        schema = generator.get_schema(request=request)

        return response.Response(schema)
Esempio n. 21
0
def get_context(request):
    generator = SchemaGenerator(title='ArenaData Cluster Manager API',
                                description=intro())
    data = generator.get_schema(request, True)
    context = {
        'document': data,
        'request': request,
    }
    return context
Esempio n. 22
0
    def get(self, request):
        generator = SchemaGenerator(
            title='Geotrek API v2 beta 1',
            urlconf='geotrek.api.v2.urls',
            url='/api/v2',
            description="New Geotrek OpenAPI. Please Authorize first.")
        schema = generator.get_schema(request=request)

        return response.Response(schema)
Esempio n. 23
0
        def get(self, request):
            generator = SchemaGenerator(title=title, url=url)
            schema = generator.get_schema(request=request)

            if not schema:
                raise exceptions.ValidationError(
                    'The schema generator did not return a schema Document'
                )

            return Response(schema)
Esempio n. 24
0
    def test_url_under_same_key_not_replaced(self):
        patterns = [
            url(r'example/(?P<pk>\d+)/$', BasicNamingCollisionView.as_view()),
            url(r'example/(?P<slug>\w+)/$', BasicNamingCollisionView.as_view()),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
        schema = generator.get_schema()

        assert schema['example']['read'].url == '/example/{id}/'
        assert schema['example']['read_0'].url == '/example/{slug}/'
Esempio n. 25
0
    def get(self, request):
        generator = SchemaGenerator(title='Base API')
        try:
            user = User.objects.get(username='******')
        except User.DoesNotExist:
            user = User.objects.create(username='******')
        request.user = user
        request.auth = (user, None)
        schema = generator.get_schema(request)

        return Response(schema)
    def test_url_under_same_key_not_replaced(self):
        patterns = [
            url(r'example/(?P<pk>\d+)/$', BasicNamingCollisionView.as_view()),
            url(r'example/(?P<slug>\w+)/$', BasicNamingCollisionView.as_view()),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
        schema = generator.get_schema()

        assert schema['example']['read'].url == '/example/{id}/'
        assert schema['example']['read_0'].url == '/example/{slug}/'
    def test_url_under_same_key_not_replaced_another(self):

        patterns = [
            url(r'^test/list/', simple_fbv),
            url(r'^test/(?P<pk>\d+)/list/', simple_fbv),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
        schema = generator.get_schema()

        assert schema['test']['list']['list'].url == '/test/list/'
        assert schema['test']['list']['list_0'].url == '/test/{id}/list/'
    def test_schema_for_regular_views(self):
        """
        Ensure that schema generation works for ViewSet classes
        with method limitation by Django CBV's http_method_names attribute
        """
        generator = SchemaGenerator(title='Example API', patterns=self.patterns)
        request = factory.get('/example1/')
        schema = generator.get_schema(Request(request))

        expected = coreapi.Document(
            url='http://testserver/example1/',
            title='Example API',
            content={
                'example1': {
                    'list': coreapi.Link(
                        url='/example1/',
                        action='get',
                        fields=[
                            coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')),
                            coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')),
                            coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
                        ]
                    ),
                    'custom_list_action': coreapi.Link(
                        url='/example1/custom_list_action/',
                        action='get'
                    ),
                    'custom_list_action_multiple_methods': {
                        'read': coreapi.Link(
                            url='/example1/custom_list_action_multiple_methods/',
                            action='get',
                            description='Custom description.',
                        )
                    },
                    'documented_custom_action': {
                        'read': coreapi.Link(
                            url='/example1/documented_custom_action/',
                            action='get',
                            description='A description of the get method on the custom action.',
                        ),
                    },
                    'read': coreapi.Link(
                        url='/example1/{id}/',
                        action='get',
                        fields=[
                            coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
                            coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
                        ]
                    )
                }
            }
        )
        assert schema == expected
Esempio n. 29
0
        def get(self, request):
            generator = SchemaGenerator(title=title,
                                        url=url,
                                        patterns=patterns,
                                        urlconf=urlconf)
            schema = generator.get_schema(request=request, public=True)

            if not schema:
                raise exceptions.ValidationError(
                    "The schema generator did not return a schema Document")

            return Response(schema)
Esempio n. 30
0
    def test_url_under_same_key_not_replaced_another(self):

        patterns = [
            url(r'^test/list/', simple_fbv),
            url(r'^test/(?P<pk>\d+)/list/', simple_fbv),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
        schema = generator.get_schema()

        assert schema['test']['list']['list'].url == '/test/list/'
        assert schema['test']['list']['list_0'].url == '/test/{id}/list/'
Esempio n. 31
0
        def get(self, request):
            # bubble modify (SchemaGenerator->CustomerSchemaGenerator)
            generator = SchemaGenerator(title=title, url=url)
            # bubble modify end
            schema = generator.get_schema(request=request)

            if not schema:
                raise exceptions.ValidationError(
                    'The schema generator did not return a schema Document'
                )

            return Response(schema)
Esempio n. 32
0
    def get(self, request):
        generator = SchemaGenerator(title='Discovery API')
        schema = generator.get_schema(request=request)

        if not schema:
            # get_schema() uses the same permissions check as the API endpoints.
            # If we don't get a schema document back, it means the user is not
            # authenticated or doesn't have permission to access the API.
            # api_docs_permission_denied_handler() handles both of these cases.
            return api_docs_permission_denied_handler(request)

        return Response(schema)
    def test_schema_for_regular_views(self):
        """
        Ensure that schema generation works for ViewSet classes
        with method limitation by Django CBV's http_method_names attribute
        """
        generator = SchemaGenerator(title='Example API', patterns=self.patterns)
        request = factory.get('/example1/')
        schema = generator.get_schema(Request(request))

        expected = coreapi.Document(
            url='http://testserver/example1/',
            title='Example API',
            content={
                'example1': {
                    'list': coreapi.Link(
                        url='/example1/',
                        action='get',
                        fields=[
                            coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')),
                            coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')),
                            coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
                        ]
                    ),
                    'custom_list_action': coreapi.Link(
                        url='/example1/custom_list_action/',
                        action='get'
                    ),
                    'custom_list_action_multiple_methods': {
                        'read': coreapi.Link(
                            url='/example1/custom_list_action_multiple_methods/',
                            action='get',
                            description='Custom description.',
                        )
                    },
                    'documented_custom_action': {
                        'read': coreapi.Link(
                            url='/example1/documented_custom_action/',
                            action='get',
                            description='A description of the get method on the custom action.',
                        ),
                    },
                    'read': coreapi.Link(
                        url='/example1/{id}/',
                        action='get',
                        fields=[
                            coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
                            coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
                        ]
                    )
                }
            }
        )
        assert schema == expected
Esempio n. 34
0
 def get(self, request):
     params = {"urlconf": "api_v2.urls"}
     if "HTTP_X_FORWARDED_HOST" in request.META:
         # forwarding via tob-web
         # params["url"] = "{}://{}/api".format(
         #    request.META.get("HTTP_X_FORWARDED_PROTO", "http"),
         #    request.META["HTTP_X_FORWARDED_HOST"])
         params["url"] = "/api"
     else:
         params["url"] = "/api/v2"
     generator = SchemaGenerator(**params)
     schema = generator.get_schema(request=request)
     return Response(schema)
Esempio n. 35
0
        def get(self, request):
            generator = SchemaGenerator(title=title,
                                        url=url,
                                        patterns=patterns,
                                        urlconf=urlconf)
            schema = generator.get_schema(request=request)

            if settings.SWAGGER_HTTPS:
                schema._url = schema._url.replace('http', 'https')

            if not schema:
                raise exceptions.ValidationError(
                    'The schema generator did not return a schema Document')

            return Response(schema)
Esempio n. 36
0
        def get(self, request):
            generator = SchemaGenerator(title=title,
                                        url=url,
                                        patterns=patterns,
                                        urlconf=urlconf)

            # Showing all the endpoints, no mather the user permissions
            # schema = generator.get_schema(request=request)
            schema = generator.get_schema()

            if not schema:
                raise exceptions.ValidationError(
                    'The schema generator did not return a schema Document')

            return Response(schema)
    def test_schema_generator_excludes_correctly(self):
        """Schema should not include excluded views"""
        generator = SchemaGenerator(title='Exclusions', patterns=self.patterns)
        schema = generator.get_schema()
        expected = coreapi.Document(
            url='',
            title='Exclusions',
            content={
                'included-fbv': {
                    'list': coreapi.Link(url='/included-fbv/', action='get')
                }
            }
        )

        assert len(schema.data) == 1
        assert 'included-fbv' in schema.data
        assert schema == expected
 def test_schema_for_regular_views(self):
     """
     Ensure that schema generation with an API that is not at the URL
     root continues to use correct structure for link keys.
     """
     generator = SchemaGenerator(title='Example API', patterns=self.patterns)
     schema = generator.get_schema()
     expected = coreapi.Document(
         url='',
         title='Example API',
         content={
             'example': {
                 'create': coreapi.Link(
                     url='/api/v1/example/',
                     action='post',
                     fields=[]
                 ),
                 'list': coreapi.Link(
                     url='/api/v1/example/',
                     action='get',
                     fields=[]
                 ),
                 'read': coreapi.Link(
                     url='/api/v1/example/{id}/',
                     action='get',
                     fields=[
                         coreapi.Field('id', required=True, location='path')
                     ]
                 ),
                 'sub': {
                     'list': coreapi.Link(
                         url='/api/v1/example/{id}/sub/',
                         action='get',
                         fields=[
                             coreapi.Field('id', required=True, location='path')
                         ]
                     )
                 }
             }
         }
     )
     assert schema == expected
 def test_schema_for_regular_views(self):
     """
     Ensure that schema generation works for APIView classes.
     """
     generator = SchemaGenerator(title='Example API', patterns=self.patterns)
     schema = generator.get_schema()
     expected = coreapi.Document(
         url='',
         title='Example API',
         content={
             'example': {
                 'create': coreapi.Link(
                     url='/example/',
                     action='post',
                     fields=[]
                 ),
                 'list': coreapi.Link(
                     url='/example/',
                     action='get',
                     fields=[]
                 ),
                 'read': coreapi.Link(
                     url='/example/{id}/',
                     action='get',
                     fields=[
                         coreapi.Field('id', required=True, location='path')
                     ]
                 ),
                 'sub': {
                     'list': coreapi.Link(
                         url='/example/{id}/sub/',
                         action='get',
                         fields=[
                             coreapi.Field('id', required=True, location='path')
                         ]
                     )
                 }
             }
         }
     )
     assert schema == expected
    def test_manually_routing_generic_view(self):
        patterns = [
            url(r'^test', NamingCollisionView.as_view()),
            url(r'^test/retrieve/', NamingCollisionView.as_view()),
            url(r'^test/update/', NamingCollisionView.as_view()),

            # Fails with method names:
            url(r'^test/get/', NamingCollisionView.as_view()),
            url(r'^test/put/', NamingCollisionView.as_view()),
            url(r'^test/delete/', NamingCollisionView.as_view()),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)

        schema = generator.get_schema()

        self._verify_cbv_links(schema['test']['delete'], '/test/delete/')
        self._verify_cbv_links(schema['test']['put'], '/test/put/')
        self._verify_cbv_links(schema['test']['get'], '/test/get/')
        self._verify_cbv_links(schema['test']['update'], '/test/update/')
        self._verify_cbv_links(schema['test']['retrieve'], '/test/retrieve/')
        self._verify_cbv_links(schema['test'], '/test', suffixes=(None, '0', None, '0'))
 def test_view(self):
     schema_generator = SchemaGenerator(title='Test View', patterns=urlpatterns2)
     schema = schema_generator.get_schema()
     expected = coreapi.Document(
         url='',
         title='Test View',
         content={
             'example-view': {
                 'create': coreapi.Link(
                     url='/example-view/',
                     action='post',
                     fields=[]
                 ),
                 'read': coreapi.Link(
                     url='/example-view/',
                     action='get',
                     fields=[]
                 )
             }
         }
     )
     self.assertEquals(schema, expected)
 def test_schema_for_regular_views(self):
     """
     Ensure that schema generation works for ViewSet classes
     with permission classes raising exceptions.
     """
     generator = SchemaGenerator(title='Example API', patterns=self.patterns)
     request = factory.get('/')
     schema = generator.get_schema(Request(request))
     expected = coreapi.Document(
         url='',
         title='Example API',
         content={
             'example': {
                 'list': coreapi.Link(
                     url='/example/',
                     action='get',
                     fields=[]
                 ),
             },
         }
     )
     assert schema == expected
    def test_manually_routing_nested_routes(self):
        patterns = [
            url(r'^test', simple_fbv),
            url(r'^test/list/', simple_fbv),
        ]

        generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
        schema = generator.get_schema()

        expected = coreapi.Document(
            url='',
            title='Naming Colisions',
            content={
                'test': {
                    'list': {
                        'list': coreapi.Link(url='/test/list/', action='get')
                    },
                    'list_0': coreapi.Link(url='/test', action='get')
                }
            }
        )

        assert expected == schema
Esempio n. 44
0
def schema_view(request):
    generator = SchemaGenerator()
    return Response(generator.get_schema(request=request))
Esempio n. 45
0
def schema_view(request):
    generator = SchemaGenerator(title='Koldunov API')
    return Response(generator.get_schema())