• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python schemas.SchemaGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rest_framework.schemas.SchemaGenerator的典型用法代码示例。如果您正苦于以下问题:Python SchemaGenerator类的具体用法?Python SchemaGenerator怎么用?Python SchemaGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SchemaGenerator类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_from_router

    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
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:28,代码来源:test_schemas.py


示例2: test_4605_regression

 def test_4605_regression(self):
     generator = SchemaGenerator()
     prefix = generator.determine_path_prefix([
         '/api/v1/items/',
         '/auth/convert-token/'
     ])
     assert prefix == '/'
开发者ID:ArtikUA,项目名称:django-rest-framework,代码行数:7,代码来源:test_schemas.py


示例3: test_schema_for_regular_views

    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
开发者ID:YanyanZeng,项目名称:django-rest-framework,代码行数:25,代码来源:test_schemas.py


示例4: get

 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)
开发者ID:CDE-UNIBE,项目名称:qcat,代码行数:7,代码来源:views.py


示例5: get

        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)
开发者ID:interTouch,项目名称:django-rest-swagger,代码行数:10,代码来源:views.py


示例6: test_url_under_same_key_not_replaced

    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}/'
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:11,代码来源:test_schemas.py


示例7: test_url_under_same_key_not_replaced_another

    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/'
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:12,代码来源:test_schemas.py


示例8: test_viewset_action_with_null_schema

    def test_viewset_action_with_null_schema(self):
        class CustomViewSet(GenericViewSet):
            @action(detail=True, schema=None)
            def extra_action(self, pk, **kwargs):
                pass

        router = SimpleRouter()
        router.register(r'detail', CustomViewSet, basename='detail')

        generator = SchemaGenerator()
        view = generator.create_view(router.urls[0].callback, 'GET')
        assert view.schema is None
开发者ID:robinhoodmarkets,项目名称:django-rest-framework,代码行数:12,代码来源:test_schemas.py


示例9: test_schema_for_regular_views

    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
开发者ID:robinhoodmarkets,项目名称:django-rest-framework,代码行数:53,代码来源:test_schemas.py


示例10: test_schema_generator_excludes_correctly

    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
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:17,代码来源:test_schemas.py


示例11: test_schema_for_regular_views

 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
开发者ID:ArtikUA,项目名称:django-rest-framework,代码行数:42,代码来源:test_schemas.py


示例12: test_manually_routing_generic_view

    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'))
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:22,代码来源:test_schemas.py


示例13: test_view

 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)
开发者ID:CoffeeBeanSoftware,项目名称:django-rest-framework,代码行数:22,代码来源:test_schemas.py


示例14: test_viewset_action_with_schema

    def test_viewset_action_with_schema(self):
        class CustomViewSet(GenericViewSet):
            @action(detail=True, schema=AutoSchema(manual_fields=[
                coreapi.Field(
                    "my_extra_field",
                    required=True,
                    location="path",
                    schema=coreschema.String()
                ),
            ]))
            def extra_action(self, pk, **kwargs):
                pass

        router = SimpleRouter()
        router.register(r'detail', CustomViewSet, basename='detail')

        generator = SchemaGenerator()
        view = generator.create_view(router.urls[0].callback, 'GET')
        link = view.schema.get_link('/a/url/{id}/', 'GET', '')
        fields = link.fields

        assert len(fields) == 2
        assert "my_extra_field" in [f.name for f in fields]
开发者ID:robinhoodmarkets,项目名称:django-rest-framework,代码行数:23,代码来源:test_schemas.py


示例15: test_manually_routing_nested_routes

    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
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:23,代码来源:test_schemas.py


示例16: schema_view

def schema_view(request):
    generator = SchemaGenerator()
    return Response(generator.get_schema(request=request))
开发者ID:sipwise,项目名称:repoapi,代码行数:3,代码来源:views.py


示例17: schema_view

def schema_view(request):
    generator = SchemaGenerator(title='Koldunov API')
    return Response(generator.get_schema())
开发者ID:volgoweb,项目名称:rest_example,代码行数:3,代码来源:schema.py



注:本文中的rest_framework.schemas.SchemaGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python serializers.Serializer类代码示例发布时间:2022-05-26
下一篇:
Python routers.SimpleRouter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap