|  | @@ -3,10 +3,12 @@ import re
 | 
	
		
			
			| 3 | 3 |  import typing
 | 
	
		
			
			| 4 | 4 |  
 | 
	
		
			
			| 5 | 5 |  import bottle
 | 
	
		
			
			| 6 |  | -from apispec import APISpec, Path
 | 
	
		
			
			|  | 6 | +from apispec import APISpec
 | 
	
		
			
			|  | 7 | +from apispec import Path
 | 
	
		
			
			| 7 | 8 |  from apispec.ext.marshmallow.swagger import schema2jsonschema
 | 
	
		
			
			| 8 | 9 |  
 | 
	
		
			
			| 9 |  | -from hapic.decorator import DecoratedController, DECORATION_ATTRIBUTE_NAME
 | 
	
		
			
			|  | 10 | +from hapic.decorator import DecoratedController
 | 
	
		
			
			|  | 11 | +from hapic.decorator import DECORATION_ATTRIBUTE_NAME
 | 
	
		
			
			| 10 | 12 |  
 | 
	
		
			
			| 11 | 13 |  # Bottle regular expression to locate url parameters
 | 
	
		
			
			| 12 | 14 |  from hapic.description import ControllerDescription
 | 
	
	
		
			
			|  | @@ -14,17 +16,25 @@ from hapic.description import ControllerDescription
 | 
	
		
			
			| 14 | 16 |  BOTTLE_RE_PATH_URL = re.compile(r'<(?:[^:<>]+:)?([^<>]+)>')
 | 
	
		
			
			| 15 | 17 |  
 | 
	
		
			
			| 16 | 18 |  
 | 
	
		
			
			| 17 |  | -def bottle_route_for_view(token, app):
 | 
	
		
			
			|  | 19 | +def bottle_route_for_view(
 | 
	
		
			
			|  | 20 | +    decorated_controller: DecoratedController,
 | 
	
		
			
			|  | 21 | +    app: bottle.Bottle,
 | 
	
		
			
			|  | 22 | +):
 | 
	
		
			
			| 18 | 23 |      for route in app.routes:
 | 
	
		
			
			| 19 | 24 |          route_token = getattr(
 | 
	
		
			
			| 20 | 25 |              route.callback,
 | 
	
		
			
			| 21 | 26 |              DECORATION_ATTRIBUTE_NAME,
 | 
	
		
			
			| 22 | 27 |              None,
 | 
	
		
			
			| 23 | 28 |          )
 | 
	
		
			
			| 24 |  | -        if route_token == token:
 | 
	
		
			
			|  | 29 | +        if route_token == decorated_controller.token:
 | 
	
		
			
			| 25 | 30 |              return route
 | 
	
		
			
			| 26 |  | -    # TODO: specialize exception
 | 
	
		
			
			| 27 |  | -    raise Exception('Not found')
 | 
	
		
			
			|  | 31 | +    # TODO BS 20171010: specialize exception
 | 
	
		
			
			|  | 32 | +    # TODO BS 20171010: Raise exception or print error ?
 | 
	
		
			
			|  | 33 | +    raise Exception(
 | 
	
		
			
			|  | 34 | +        'Decorated route "{}" was not found in bottle routes'.format(
 | 
	
		
			
			|  | 35 | +            decorated_controller.name,
 | 
	
		
			
			|  | 36 | +        )
 | 
	
		
			
			|  | 37 | +    )
 | 
	
		
			
			| 28 | 38 |  
 | 
	
		
			
			| 29 | 39 |  
 | 
	
		
			
			| 30 | 40 |  def bottle_generate_operations(
 | 
	
	
		
			
			|  | @@ -143,7 +153,7 @@ class DocGenerator(object):
 | 
	
		
			
			| 143 | 153 |          # with app.test_request_context():
 | 
	
		
			
			| 144 | 154 |          paths = {}
 | 
	
		
			
			| 145 | 155 |          for controller in controllers:
 | 
	
		
			
			| 146 |  | -            bottle_route = bottle_route_for_view(controller.token, app)
 | 
	
		
			
			|  | 156 | +            bottle_route = bottle_route_for_view(controller, app)
 | 
	
		
			
			| 147 | 157 |              swagger_path = BOTTLE_RE_PATH_URL.sub(r'{\1}', bottle_route.rule)
 | 
	
		
			
			| 148 | 158 |  
 | 
	
		
			
			| 149 | 159 |              operations = bottle_generate_operations(
 |