Swagger router

Classes

SwaggerRouter

New in version 0.1.

class aiohttp_apiset.swagger.router.SwaggerRouter(path: str = None, *, search_dirs=None, swagger_ui='/apidoc/', version_ui=2, route_factory=<function route_factory>, encoding=None, default_validate=True, file_loader=None, spec_url=None)[source]

SwaggerRouter is designed to load swagger specifications

Parameters:
  • path – path to specification
  • search_dirs – directory for search files of specification
  • swagger_ui – if True then swagger-ui will be available at the url basePath/apidoc/index.html
  • encoding – default encoding of specification, if None apply UTF-8
  • route_factory – factory for select route class and create route
  • default_validate – if True and not specify in method then standart route_factory selected SwaggerValidationRoute
add_route(method, path, handler, *, name=None, expect_handler=None, swagger_data=None, validate=None)[source]

Returns route

Parameters:
  • method – as well as in aiohttp
  • path – as well as in aiohttp
  • handler – as well as in aiohttp and also must be str mymodule.handler
  • name – as well as in aiohttp
  • expect_handler – as well as in aiohttp
  • swagger_data – data http://swagger.io/specification/#operationObject
  • validate – bool param for validate in SwaggerValidationRoute
  • build – bool param for build extractor and validator
Returns:

route for handler

add_search_dir(path)[source]

Add directory for search specification files

freeze()[source]

Freeze router.

include(spec, *, basePath=None, operationId_mapping=None, name=None)[source]

Adds a new specification to a router

Parameters:
  • spec – path to specification
  • basePath – override base path specify in specification
  • operationId_mapping – mapping for handlers
  • name – name to access original spec
setup(app: aiohttp.web_app.Application)[source]

Installation routes to app.router

Parameters:app – instance of aiohttp.web.Application

SwaggerRoute

class aiohttp_apiset.swagger.route.SwaggerRoute(method, handler, resource, *, expect_handler=None, location=None, swagger_data=None)[source]
Parameters:
  • method – as well as in aiohttp
  • handler – as well as in aiohttp
  • resource – as well as in aiohttp
  • expect_handler – as well as in aiohttp
  • location – SubLocation instance
  • swagger_data – data
build_swagger_data(loader)[source]

Prepare data when schema loaded

Parameters:swagger_schema – loaded schema
errors_factory

alias of aiohttp_apiset.exceptions.ValidationError

validate(request: aiohttp.web_request.Request)[source]

Returns parameters extract from request and multidict errors

Parameters:request – Request
Returns:tuple of parameters and errors

SwaggerValidationRoute

class aiohttp_apiset.swagger.route.SwaggerValidationRoute(method, handler, resource, *, expect_handler=None, location=None, swagger_data=None)[source]
build_swagger_data(loader)[source]

Prepare data when schema loaded

Parameters:swagger_schema – loaded schema