Ejemplo n.º 1
0
    def get_default_responses(self):
        """Get the default responses determined for this view from the request serializer and request method.

        :type: dict[str, openapi.Schema]
        """
        method = self.method.lower()

        default_status = guess_response_status(method)
        default_schema = ''
        if method in ('get', 'post', 'put', 'patch'):
            default_schema = self.get_default_response_serializer()

        default_schema = default_schema or ''
        if default_schema and not isinstance(default_schema, openapi.Schema):
            default_schema = self.serializer_to_schema(
                default_schema) or ''  # noqa

        if default_schema:
            if self.has_list_response():
                default_schema = openapi.Schema(type=openapi.TYPE_ARRAY,
                                                items=default_schema)
            if self.should_page():
                default_schema = self.get_paginated_response(
                    default_schema) or default_schema

        return OrderedDict({str(default_status): default_schema})
Ejemplo n.º 2
0
    def get_default_responses(self):
        """
        Get the default responses determined for this view from the request serializer and request method.

        :param drf_jsonapi.inspectors.SwaggerAutoSchema self: This object
        :type: dict[str, openapi.Schema]
        :return: A default OpenAPI response
        :rtype: collections.OrderedDict
        """

        method = self.method.lower()

        if self.relationship and method != "get":
            return OrderedDict({str(204): ""})

        default_status = guess_response_status(method)
        default_schema = ""
        if method in ("get", "post", "put", "patch"):
            default_schema = self.get_request_serializer(
            ) or self.get_view_serializer()

        default_schema = default_schema or ""
        if default_schema and not isinstance(default_schema, openapi.Schema):
            default_schema = self.serializer_to_schema(default_schema) or ""

        if default_schema and self.is_list():
            default_schema = openapi.Schema(type=openapi.TYPE_ARRAY,
                                            items=default_schema)

        return OrderedDict({str(default_status): default_schema})
Ejemplo n.º 3
0
    def get_default_responses(self):
        """Get the default responses determined for this view from the request serializer and
        request method.

        :type: dict[str, openapi.Schema]
        """
        method = self.method.lower()

        default_status = guess_response_status(method)
        default_schema = ''
        if method in ('get', 'post', 'put', 'patch'):
            default_schema = self.get_default_response_serializer()

        default_schema = default_schema or ''

        if default_schema and not isinstance(default_schema, openapi.Schema):
            default_schema = self.serializer_to_schema(default_schema) or ''

        if default_schema:
            if is_list_view(self.path, self.method, self.view) and self.method.lower() == 'get':
                default_schema = openapi.Schema(type=openapi.TYPE_ARRAY, items=default_schema)
            if self.should_page():
                default_schema = self.get_paginated_response(default_schema) or default_schema

        return OrderedDict({str(default_status): default_schema})
Ejemplo n.º 4
0
    def get_default_responses(self):
        """
        Get the default responses determined for this view from the request serializer and request method.

        :param drf_jsonapi.inspectors.SwaggerAutoSchema self: This object
        :type: dict[str, openapi.Schema]
        :return: A default OpenAPI response
        :rtype: collections.OrderedDict
        """

        method = self.method.lower()

        default_status = guess_response_status(method)
        default_schema = ''
        if method in ('get', 'post', 'put', 'patch'):
            default_schema = self.get_request_serializer(
            ) or self.get_view_serializer()

        default_schema = default_schema or ''
        if default_schema and not isinstance(default_schema, openapi.Schema):
            default_schema = self.serializer_to_schema(default_schema) or ''

        if default_schema:
            if self.is_list():
                default_schema = openapi.Schema(type=openapi.TYPE_ARRAY,
                                                items=default_schema)
            if self.should_page():
                default_schema = self.get_paginated_response(
                    default_schema) or default_schema

        return OrderedDict({str(default_status): default_schema})
Ejemplo n.º 5
0
    def _get_default_responses(self):
        """Get the default responses determined for this view from the request serializer and request method.

        :type: dict[str, openapi.Schema]
        """
        method = self.method.lower()

        default_status = guess_response_status(method)

        default_schema = self.get_default_response_serializer()

        default_schema = default_schema or ''
        if default_schema and not isinstance(default_schema, openapi.Schema):
            default_schema = self.serializer_to_schema(default_schema) or ''

        if default_schema and self.get_view_action() not in ('edit'):
            if self.has_list_response():
                default_schema = openapi.Schema(type=openapi.TYPE_ARRAY, items=default_schema)
            if self.should_page():
                query_schema = self.get_query_serializer() or serializers.DictField(help_text="查询条件", required=False)
                paged_schema = openapi.Schema(
                        type=openapi.TYPE_OBJECT,
                        properties=OrderedDict((
                                ('count', openapi.Schema(type=openapi.TYPE_INTEGER)),
                                ('page', openapi.Schema(type=openapi.TYPE_INTEGER)),
                                ('page_size', openapi.Schema(type=openapi.TYPE_INTEGER)),

                                ('next',
                                 openapi.Schema(type=openapi.TYPE_STRING, format=openapi.FORMAT_URI, x_nullable=True)),
                                ('previous',
                                 openapi.Schema(type=openapi.TYPE_STRING, format=openapi.FORMAT_URI, x_nullable=True)),
                                ('results', default_schema),
                                ('filter', self.serializer_to_schema(query_schema)),
                        )),
                        required=['results']
                )
                default_schema = paged_schema

        rsp_code_schema = self.serializer_to_schema(RspSerializer._declared_fields['code'])

        default_schema = openapi.Schema(
                type=openapi.TYPE_OBJECT,
                properties=OrderedDict((
                        ('code', rsp_code_schema),
                        ('msg', self.serializer_to_schema(RspSerializer._declared_fields['msg'])),
                        ('data', default_schema)
                )
                ),
                required=['code', 'msg']
        )

        return OrderedDict({str(default_status): default_schema})
Ejemplo n.º 6
0
    def get_default_responses(self):
        if not is_json_api_response(self.get_renderer_classes()):
            return super().get_default_responses()

        method = self.method.lower()

        default_status = guess_response_status(method)
        default_schema = ''
        if method in ('get', 'post', 'put', 'patch'):
            default_serializer = self.get_default_response_serializer()

            default_schema = openapi.Schema(
                type=openapi.TYPE_OBJECT,
                properties=OrderedDict({
                    'data': self.get_default_response_data(default_serializer),
                    'included': self.get_default_response_included(default_serializer)
                })
            )

        return filter_none(OrderedDict({str(default_status): default_schema}))