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 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)
def decorator(*args, **kwargs): if not auth(request.args.get('api_key'), extract_swagger_path(request.url_rule.rule), request.method): abort(401) return f(*args, **kwargs)
def test_should_extract_swagger_path_extended(self): self.assertEqual( swagger.extract_swagger_path( '/<string(length=2):lang_code>/<string:id>/<float:probability>' ), '/{lang_code}/{id}/{probability}')
def test_should_extract_swagger_path(self): self.assertEqual(swagger.extract_swagger_path('/path/<parameter>'), '/path/{parameter}')
def test_should_extract_swagger_path_extended(self): self.assertEqual(swagger.extract_swagger_path('/<string(length=2):lang_code>/<string:id>/<float:probability>'), '/{lang_code}/{id}/{probability}')