コード例 #1
0
    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)
コード例 #2
0
 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)