Esempio n. 1
0
    def _operation(introspector):
        operation = OrderedDict(
            tags=introspector.tags,
            summary=introspector.parser.get_summary(),
            description=introspector.parser.get_description(),
            parameters=introspector.parameters,
            responses=introspector.responses,
            security=introspector.security)

        # Remove empty keys
        for key, value in list(operation.items()):
            if not value:
                operation.pop(key)

        return operation
Esempio n. 2
0
    def responses(self):
        """
        Collects method responses

        :return: swagger responses object
        :rtype: OrderedDict
        """
        responses = OrderedDict()
        responses.update(self.introspector.responses)
        responses.update(super(BaseMethodIntrospector, self).responses)

        serializer = self._get_serializer()

        if serializer and not responses.get(200, None):
            si = SerializerIntrospector(serializer)
            if 'list' in self.method.lower():
                pagination_introspector = get_pagination_introspector(
                    self.view, si=si)
                responses.update(pagination_introspector.responses)
            else:
                response = OrderedDict([
                    ('description', 'Default response'),
                    ('schema', si.build_response_object()['schema']),
                ])
                responses[200] = response

        status_code = self.STATUS_CODES.get(self.method,
                                            self.DEFAULT_STATUS_CODE)
        response = responses.pop(200, None)
        # TODO this code wants to be rewritten
        if response:
            if status_code == status.HTTP_204_NO_CONTENT:
                response.pop('schema', None)
            if not responses.get(status_code, None):
                responses[status_code] = response

        if status_code not in responses:
            response = OrderedDict([
                ('description', 'Empty response'),
            ])
            responses[status_code] = response

        return responses
Esempio n. 3
0
    def get_operation(self):
        """
        Get full swagger operation object

        :return: swagger operation object
        :rtype: OrderedDict
        """

        operation = OrderedDict(tags=self.parser.get_tags(),
                                summary=self.parser.get_summary(),
                                description=self.parser.get_description(),
                                parameters=self.parameters,
                                produces=None,
                                consumes=None,
                                responses=self.responses,
                                security=self.security)

        for key, value in list(operation.items()):
            # Remove empty keys
            if not value:
                operation.pop(key)

        return operation
Esempio n. 4
0
    def get_operation(self):
        """
        Get full swagger operation object

        :return: swagger operation object
        :rtype: OrderedDict
        """

        operation = OrderedDict(tags=self._get_tags(),
                                summary=self._get_summary(),
                                description=self._get_description(),
                                parameters=self._get_parameters(),
                                produces=self._get_produces(),
                                consumes=self._get_consumes(),
                                responses=self.responses,
                                security=self._get_security())

        # TODO: SECURITY OBJECT SECURITY DEFINITIONS
        for key, value in list(operation.items()):
            # Remove empty keys
            if not value:
                operation.pop(key)

        return operation