def add_resource(self, resource, *urls, **kwargs):
        path_item = {}
        definitions = {}

        for method in [m.lower() for m in resource.methods]:
            f = resource.__dict__.get(method, None)
            operation = f.__dict__.get('__swagger_operation_object', None)
            if operation:
                operation, definitions_ = self._extract_schemas(operation)
                path_item[method] = operation
                definitions.update(definitions_)
                summary = parse_method_doc(f, operation)
                if summary:
                    operation['summary'] = summary

        validate_definitions_object(definitions)
        self._swagger_object['definitions'].update(definitions)

        if path_item:
            validate_path_item_object(path_item)
            for url in urls:
                if not url.startswith('/'):
                    raise ValidationError('paths must start with a /')
                if self.blueprint and self.blueprint.url_prefix:
                    if not self.blueprint.url_prefix.startswith('/'):
                        raise ValidationError('url_prefix must start with a /')
                    if self.blueprint.url_prefix.endswith('/'):
                        raise ValidationError(
                            'url_prefix must not end with a /')
                    url = self.blueprint.url_prefix + url
                self._swagger_object['paths'][extract_swagger_path(
                    url)] = path_item

        super(Api, self).add_resource(resource, *urls, **kwargs)
    def test_should_parse_method_doc(self):
        def test_func(a):
            """
            Test function
            :param a: argument
            :return: Nothing
            """

        self.assertEqual(swagger.parse_method_doc(test_func, {}), 'Test function')
Example #3
0
    def test_should_parse_method_doc(self):
        def test_func(a):
            """
            Test function
            :param a: argument
            :return: Nothing
            """

        self.assertEqual(swagger.parse_method_doc(test_func, {}),
                         'Test function')
    def test_should_parse_method_doc_append_summary(self):
        def test_func(a):
            """
            Test function
            :param a: argument
            :return: Nothing
            """

        self.assertEqual(swagger.parse_method_doc(test_func, {'summary': 'Summary'}),
                         'Summary<br/>Test function')
Example #5
0
    def test_should_parse_method_doc_append_summary(self):
        def test_func(a):
            """
            Test function
            :param a: argument
            :return: Nothing
            """

        self.assertEqual(
            swagger.parse_method_doc(test_func, {'summary': 'Summary'}),
            'Summary<br/>Test function')
 def add_resource(self, resource, *urls, **kwargs):
     path_item = {}
     definitions = {}
     for method in [m.lower() for m in resource.methods]:
         f = resource.__dict__.get(method, None)
         operation = f.__dict__.get('__swagger_operation_object', None)
         if operation:
             operation, definitions_ = self._extract_schemas(operation)
             path_item[method] = operation
             definitions.update(definitions_)
             summary = parse_method_doc(f, operation)
             if summary:
                 operation['summary'] = summary
     validate_definitions_object(definitions)
     self._swagger_object['definitions'].update(definitions)
     if path_item:
         validate_path_item_object(path_item)
         for url in urls:
             if not url.startswith('/'):
                 raise ValidationError('paths must start with a /')
             self._swagger_object['paths'][extract_swagger_path(url)] = path_item
     super(Api, self).add_resource(resource, *urls, **kwargs)