Example #1
0
 def get_operation(self, rule, view, parent=None):
     annotation = resolve_annotations(view, 'docs', parent)
     docs = merge_recursive(annotation.options)
     operation = {
         'responses': self.get_responses(view, parent),
         'parameters': self.get_parameters(rule, view, docs, parent),
     }
     docs.pop('params', None)
     return merge_recursive([operation, docs])
Example #2
0
 def get_operation(self, rule, view, parent=None):
     annotation = resolve_annotations(view, 'docs', parent)
     docs = merge_recursive(annotation.options)
     operation = {
         'responses': self.get_responses(view, parent),
         'parameters': self.get_parameters(rule, view, docs, parent),
     }
     docs.pop('params', None)
     return merge_recursive([operation, docs])
Example #3
0
    def get_parameters(self, rule, view, docs, parent=None):
        annotation = resolve_annotations(view, 'args', parent)
        args = merge_recursive(annotation.options)
        schema = args.get('args', {})
        if is_instance_or_subclass(schema, Schema):
            converter = swagger.schema2parameters
        elif callable(schema):
            schema = schema(request=None)
            if is_instance_or_subclass(schema, Schema):
                converter = swagger.schema2parameters
            else:
                converter = swagger.fields2parameters
        else:
            converter = swagger.fields2parameters
        options = copy.copy(args.get('kwargs', {}))
        locations = options.pop('locations', None)
        if locations:
            options['default_in'] = locations[0]
        if parse_version(apispec.__version__) < parse_version('0.20.0'):
            options['dump'] = False

        options['spec'] = self.app.config.get('APISPEC_SPEC', None)

        rule_params = rule_to_params(rule, docs.get('params')) or []
        extra_params = converter(schema, **options) if args else []

        return extra_params + rule_params
Example #4
0
 def wrapped(*args, **kwargs):
     instance = args[0] if func.__apispec__.get('ismethod') else None
     annotation = utils.resolve_annotations(func, 'wrapper', instance)
     wrapper_cls = utils.merge_recursive(annotation.options).get(
         'wrapper', Wrapper)
     wrapper = wrapper_cls(func, instance)
     return wrapper(*args, **kwargs)
Example #5
0
 def get_parameters(self, rule, view, docs, parent=None):
     annotation = resolve_annotations(view, 'args', parent)
     args = merge_recursive(annotation.options)
     converter = (swagger.schema2parameters if is_instance_or_subclass(
         args.get('args', {}), Schema) else swagger.fields2parameters)
     options = copy.copy(args.get('kwargs', {}))
     locations = options.pop('locations', None)
     if locations:
         options['default_in'] = locations[0]
     return converter(args.get('args', {}), dump=False, **
                      options) + rule_to_params(rule, docs.get('params'))
Example #6
0
 def marshal_result(self, unpacked, status_code):
     config = flask.current_app.config
     format_response = config.get('APISPEC_FORMAT_RESPONSE', flask.jsonify) or identity
     annotation = utils.resolve_annotations(self.func, 'schemas', self.instance)
     schemas = utils.merge_recursive(annotation.options)
     schema = schemas.get(status_code, schemas.get('default'))
     if schema and annotation.apply is not False:
         schema = utils.resolve_instance(schema['schema'])
         output = schema.dump(unpacked[0]).data
     else:
         output = unpacked[0]
     return format_output((format_response(output), ) + unpacked[1:])
Example #7
0
 def marshal_result(self, unpacked, status_code):
     config = flask.current_app.config
     format_response = config.get('APISPEC_FORMAT_RESPONSE', flask.jsonify) or identity
     annotation = utils.resolve_annotations(self.func, 'schemas', self.instance)
     schemas = utils.merge_recursive(annotation.options)
     schema = schemas.get(status_code, schemas.get('default'))
     if schema and annotation.apply is not False:
         schema = utils.resolve_schema(schema['schema'], request=flask.request)
         dumped = schema.dump(unpacked[0])
         output = dumped.data if MARSHMALLOW_VERSION_INFO[0] < 3 else dumped
     else:
         output = unpacked[0]
     return format_output((format_response(output), ) + unpacked[1:])
Example #8
0
    def get_parameters(self, rule, view, docs, parent=None):
        annotation = resolve_annotations(view, 'args', parent)
        args = merge_recursive(annotation.options)
        converter = (swagger.schema2parameters if is_instance_or_subclass(
            args.get('args', {}), Schema) else swagger.fields2parameters)
        options = copy.copy(args.get('kwargs', {}))
        locations = options.pop('locations', None)
        if locations:
            options['default_in'] = locations[0]
        if parse_version(apispec.__version__) < parse_version('0.20.0'):
            options['dump'] = False
        rule_params = rule_to_params(rule, docs.get('params')) or []
        extra_params = converter(args.get('args', {}), **
                                 options) if args else []

        return rule_params + extra_params
Example #9
0
 def get_parameters(self, rule, view, docs, parent=None):
     annotation = resolve_annotations(view, 'args', parent)
     args = merge_recursive(annotation.options)
     converter = (
         swagger.schema2parameters
         if is_instance_or_subclass(args.get('args', {}), Schema)
         else swagger.fields2parameters
     )
     options = copy.copy(args.get('kwargs', {}))
     locations = options.pop('locations', None)
     if locations:
         options['default_in'] = locations[0]
     return converter(
         args.get('args', {}),
         dump=False,
         **options
     ) + rule_to_params(rule, docs.get('params'))
Example #10
0
 def get_responses(self, view, parent=None):
     annotation = resolve_annotations(view, 'schemas', parent)
     options = []
     for option in annotation.options:
         exploded = {}
         for status_code, meta in option.items():
             if self.spec.openapi_version.major < 3:
                 meta.pop('content_type', None)
                 exploded[status_code] = meta
             else:
                 content_type = meta['content_type'] or 'application/json'
                 exploded[status_code] = {
                     'content': {
                         content_type: {
                             'schema': meta['schema']
                         }
                     }
                 }
                 if meta['description']:
                     exploded[status_code]['description'] = meta['description']
         options.append(exploded)
     return merge_recursive(options)
Example #11
0
    def get_parameters(self, rule, view, docs, parent=None):
        openapi = self.marshmallow_plugin.openapi
        annotation = resolve_annotations(view, 'args', parent)
        args = merge_recursive(annotation.options)
        schema = args.get('args', {})
        if is_instance_or_subclass(schema, Schema):
            converter = openapi.schema2parameters
        elif callable(schema):
            schema = schema(request=None)
            if is_instance_or_subclass(schema, Schema):
                converter = openapi.schema2parameters
            else:
                converter = openapi.fields2parameters
        else:
            converter = openapi.fields2parameters
        options = copy.copy(args.get('kwargs', {}))
        locations = options.pop('locations', None)
        if locations:
            options['default_in'] = locations[0]

        rule_params = rule_to_params(rule, docs.get('params')) or []
        extra_params = converter(schema, **options) if args else []

        return extra_params + rule_params
Example #12
0
 def get_responses(self, view, parent=None):
     annotation = resolve_annotations(view, 'schemas', parent)
     return merge_recursive(annotation.options)
Example #13
0
 def get_responses(self, view, parent=None):
     annotation = resolve_annotations(view, 'schemas', parent)
     return merge_recursive(annotation.options)
Example #14
0
 def wrapped(*args, **kwargs):
     instance = args[0] if func.__apispec__.get('ismethod') else None
     annotation = utils.resolve_annotations(func, 'wrapper', instance)
     wrapper_cls = utils.merge_recursive(annotation.options).get('wrapper', Wrapper)
     wrapper = wrapper_cls(func, instance)
     return wrapper(*args, **kwargs)