示例#1
0
    def get_parameters(self, rule, view, docs, parent=None):
        if APISPEC_VERSION_INFO[0] < 3:
            openapi = self.marshmallow_plugin.openapi
        else:
            openapi = self.marshmallow_plugin.converter
        annotation = resolve_annotations(view, 'args', parent)
        extra_params = []
        for args in 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]
            elif 'default_in' not in options:
                options['default_in'] = 'body'
            extra_params += converter(schema, **options) if args else []

        rule_params = rule_to_params(rule, docs.get('params')) or []

        return extra_params + rule_params
示例#2
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
示例#3
0
 def test_params(self, app, path, openapi):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['band'][0]
     expected = (
         [{'in': 'query', 'name': 'name', 'required': False, 'type': 'string'}] +
         rule_to_params(rule)
     )
     assert params == expected
示例#4
0
 def test_params(self, app, path):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['get_band'][0]
     expected = (
         swagger.fields2parameters({'name': fields.Str()}, default_in='query') +
         rule_to_params(rule)
     )
     assert params == expected
示例#5
0
 def test_params_override(self, app):
     rule = make_rule(app, '/<band_id>/')
     overrides = {'band_id': {'description': 'the band id'}}
     params = rule_to_params(rule, overrides=overrides)
     expected = make_param(type='string',
                           name='band_id',
                           description='the band id')
     assert params[0] == expected
示例#6
0
 def test_params(self, app, path, openapi):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['band'][0]
     expected = (
         openapi.fields2parameters(
             {'name': fields.Str()}, default_in='query') +
         rule_to_params(rule)
     )
     assert params == expected
示例#7
0
 def test_params(self, app, path, openapi):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['get_band'][0]
     expected = (
         openapi.schema2parameters(
             Schema.from_dict({'name': fields.Str()}), location='query') +
         rule_to_params(rule)
     )
     assert params == expected
示例#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]
     return converter(args.get('args', {}), dump=False, **
                      options) + rule_to_params(rule, docs.get('params'))
示例#9
0
 def test_params(self, app, path):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['get_band'][0]
     expected = ([{
         'in': 'body',
         'name': 'body',
         'required': False,
         'schema': {
             '$ref': '#/definitions/Body'
         }
     }] + rule_to_params(rule))
     assert params == expected
示例#10
0
 def test_params(self, app, path):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['get_band'][0]
     expected = (
         [{
             'in': 'query',
             'name': 'name',
             'type': 'string',
             'required': False,
             'default': 'queen',
         }] + rule_to_params(rule)
     )
     assert params == expected
示例#11
0
 def test_params(self, app, path):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['get_band'][0]
     expected = (
             [{
                 'in': 'query',
                 'name': 'name',
                 'required': False,
                 'schema': {
                     'type': 'string',
                     'default': 'queen',
                 }
             }] + rule_to_params(rule)
     )
     assert params == expected
示例#12
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
示例#13
0
 def test_params_override_header(self, app):
     rule = make_rule(app, '/some_path/')
     overrides = {
         'Authorization': {
             'type': 'string',
             'description': 'The authorization token',
             'in': 'header',
             'required': True
         }
     }
     params = rule_to_params(rule, overrides=overrides)
     expected = make_param(type='string',
                           name='Authorization',
                           in_location='header',
                           description='The authorization token',
                           required=True)
     assert params[0] == expected
示例#14
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'))
示例#15
0
 def test_params(self, app, path):
     params = path['get']['parameters']
     rule = app.url_map._rules_by_endpoint['get_band'][0]
     expected = ([{
         'in': 'body',
         'name': 'body',
         'required': False,
         'schema': {
             'properties': {
                 'address': {
                     'type': 'string'
                 },
                 'name': {
                     'type': 'string'
                 }
             },
             'type': 'object'
         },
     }] + rule_to_params(rule))
     assert params == expected
示例#16
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
示例#17
0
    def get_parameters(self, rule, view, docs, parent=None):
        openapi = self.marshmallow_plugin.converter
        annotation = resolve_annotations(view, 'args', parent)
        extra_params = []
        for args in annotation.options:
            schema = args.get('args', {})
            openapi_converter = openapi.schema2parameters
            if not is_instance_or_subclass(schema, Schema):
                if callable(schema):
                    schema = schema(request=None)
                else:
                    schema = Schema.from_dict(schema)
                    openapi_converter = functools.partial(
                        self._convert_dict_schema, openapi_converter)

            options = copy.copy(args.get('kwargs', {}))
            if not options.get('location'):
                options['location'] = 'body'
            extra_params += openapi_converter(schema, **
                                              options) if args else []

        rule_params = rule_to_params(rule, docs.get('params')) or []

        return extra_params + rule_params
示例#18
0
 def test_params(self, app):
     rule = make_rule(app, '/<band_id>/')
     params = rule_to_params(rule)
     assert len(params) == 1
     expected = make_param(type='string', name='band_id')
     assert params[0] == expected
示例#19
0
 def test_params_float(self, app):
     rule = make_rule(app, '/<float:band_id>/')
     params = rule_to_params(rule)
     expected = make_param(type='number', format='float', name='band_id')
     assert params[0] == expected
示例#20
0
 def test_params_int(self, app):
     rule = make_rule(app, '/<int:band_id>/')
     params = rule_to_params(rule)
     expected = make_param(type='integer', format='int32', name='band_id')
     assert params[0] == expected
示例#21
0
 def test_params_default(self, app):
     rule = make_rule(app, '/<band_id>/', defaults={'band_id': 'queen'})
     params = rule_to_params(rule)
     expected = make_param(type='string', name='band_id', default='queen')
     assert params[0] == expected
示例#22
0
 def test_params(self, app):
     rule = make_rule(app, '/<band_id>/')
     params = rule_to_params(rule)
     assert len(params) == 1
     expected = make_param(type='string', name='band_id')
     assert params[0] == expected
示例#23
0
 def test_params_default(self, app):
     rule = make_rule(app, '/<band_id>/', defaults={'band_id': 'queen'})
     params = rule_to_params(rule)
     expected = make_param(type='string', name='band_id', default='queen')
     assert params[0] == expected
示例#24
0
 def test_params_int(self, app):
     rule = make_rule(app, '/<int:band_id>/')
     params = rule_to_params(rule)
     expected = make_param(type='integer', format='int32', name='band_id')
     assert params[0] == expected
示例#25
0
 def test_params_float(self, app):
     rule = make_rule(app, '/<float:band_id>/')
     params = rule_to_params(rule)
     expected = make_param(type='number', format='float', name='band_id')
     assert params[0] == expected
示例#26
0
 def test_params_override(self, app):
     rule = make_rule(app, '/<band_id>/')
     overrides = {'band_id': {'description': 'the band id'}}
     params = rule_to_params(rule, overrides=overrides)
     expected = make_param(type='string', name='band_id', description='the band id')
     assert params[0] == expected