|
@@ -409,16 +409,11 @@ class Hapic(object):
|
409
|
409
|
if not route.endswith('/'):
|
410
|
410
|
route = '{}/'.format(route)
|
411
|
411
|
|
412
|
|
- # Add swagger directory as served static dir
|
413
|
412
|
swaggerui_path = os.path.join(
|
414
|
413
|
os.path.dirname(os.path.abspath(__file__)),
|
415
|
414
|
'static',
|
416
|
415
|
'swaggerui',
|
417
|
416
|
)
|
418
|
|
- self.context.serve_directory(
|
419
|
|
- route,
|
420
|
|
- swaggerui_path,
|
421
|
|
- )
|
422
|
417
|
|
423
|
418
|
# Documentation file view
|
424
|
419
|
doc_yaml = self.doc_generator.get_doc_yaml(
|
|
@@ -428,7 +423,15 @@ class Hapic(object):
|
428
|
423
|
description=description,
|
429
|
424
|
)
|
430
|
425
|
|
431
|
|
- def spec_yaml_view():
|
|
426
|
+ def spec_yaml_view(*args, **kwargs):
|
|
427
|
+ """
|
|
428
|
+ Method to return swagger generated yaml spec file.
|
|
429
|
+
|
|
430
|
+ This method will be call as a framework view, like those,
|
|
431
|
+ it need to handle the default arguments of a framework view.
|
|
432
|
+ As frameworks have different arguments patterns, we should
|
|
433
|
+ allow any arguments patterns (args, kwargs).
|
|
434
|
+ """
|
432
|
435
|
return self.context.get_response(
|
433
|
436
|
doc_yaml,
|
434
|
437
|
mimetype='text/x-yaml',
|
|
@@ -445,14 +448,22 @@ class Hapic(object):
|
445
|
448
|
)
|
446
|
449
|
|
447
|
450
|
# Declare the swaggerui view
|
448
|
|
- def api_doc_view():
|
|
451
|
+ def api_doc_view(*args, **kwargs):
|
|
452
|
+ """
|
|
453
|
+ Method to return html index view of swagger ui.
|
|
454
|
+
|
|
455
|
+ This method will be call as a framework view, like those,
|
|
456
|
+ it need to handle the default arguments of a framework view.
|
|
457
|
+ As frameworks have different arguments patterns, we should
|
|
458
|
+ allow any arguments patterns (args, kwargs).
|
|
459
|
+ """
|
449
|
460
|
return self.context.get_response(
|
450
|
461
|
doc_page_content,
|
451
|
462
|
http_code=HTTPStatus.OK,
|
452
|
463
|
mimetype='text/html',
|
453
|
464
|
)
|
454
|
465
|
|
455
|
|
- # Add a view to generate the html index page of swaggerui
|
|
466
|
+ # Add a view to generate the html index page of swagger-ui
|
456
|
467
|
self.context.add_view(
|
457
|
468
|
route=route,
|
458
|
469
|
http_method='GET',
|
|
@@ -465,3 +476,9 @@ class Hapic(object):
|
465
|
476
|
http_method='GET',
|
466
|
477
|
view_func=spec_yaml_view,
|
467
|
478
|
)
|
|
479
|
+
|
|
480
|
+ # Add swagger directory as served static dir
|
|
481
|
+ self.context.serve_directory(
|
|
482
|
+ route,
|
|
483
|
+ swaggerui_path,
|
|
484
|
+ )
|