Browse Source

Merge branch 'master' of github.com:algoo/hapic into generic_hapic

Guénaël Muller 6 years ago
parent
commit
a4571bc29b
3 changed files with 22 additions and 13 deletions
  1. 6 4
      hapic/doc.py
  2. 13 6
      hapic/hapic.py
  3. 3 3
      setup.py

+ 6 - 4
hapic/doc.py View File

@@ -105,14 +105,16 @@ class DocGenerator(object):
105 105
         self,
106 106
         controllers: typing.List[DecoratedController],
107 107
         context: ContextInterface,
108
+        title: str='',
109
+        description: str='',
108 110
     ) -> dict:
109 111
         spec = APISpec(
110
-            title='Swagger Petstore',
112
+            title=title,
113
+            info=dict(description=description),
111 114
             version='1.0.0',
112
-            plugins=[
113
-                # 'apispec.ext.bottle',
115
+            plugins=(
114 116
                 'apispec.ext.marshmallow',
115
-            ],
117
+            ),
116 118
             schema_name_resolver=generate_schema_name,
117 119
         )
118 120
 

+ 13 - 6
hapic/hapic.py View File

@@ -75,6 +75,13 @@ class Hapic(object):
75 75
     def context(self) -> ContextInterface:
76 76
         return self._context
77 77
 
78
+    def set_context(self, context: ContextInterface) -> None:
79
+        assert not self._context
80
+        self._context = context
81
+
82
+    def reset_context(self) -> None:
83
+        self._context = None
84
+
78 85
     def with_api_doc(self):
79 86
         def decorator(func):
80 87
             @functools.wraps(func)
@@ -103,10 +110,6 @@ class Hapic(object):
103 110
 
104 111
         return decorator
105 112
 
106
-    def set_context(self, context: ContextInterface) -> None:
107
-        assert not self._context
108
-        self._context = context
109
-
110 113
     def output_body(
111 114
         self,
112 115
         schema: typing.Any,
@@ -338,5 +341,9 @@ class Hapic(object):
338 341
             return decoration.get_wrapper(func)
339 342
         return decorator
340 343
 
341
-    def generate_doc(self):
342
-        return self.doc_generator.get_doc(self._controllers, self.context)
344
+    def generate_doc(self, title: str='', description: str=''):
345
+        return self.doc_generator.get_doc(
346
+            self._controllers,
347
+            self.context,
348
+            title=title,
349
+            description=description)

+ 3 - 3
setup.py View File

@@ -11,11 +11,11 @@ install_requires = [
11 11
     # TODO: marshmallow an extension too ? see #2
12 12
     'bottle',
13 13
     'marshmallow',
14
-    'apispec==0.25.4-algoo',
14
+    'apispec==0.27.1-algoo',
15 15
     'multidict'
16 16
 ]
17 17
 dependency_links = [
18
-    'git+https://github.com/algoo/apispec.git@dev-algoo#egg=apispec-0.25.4-algoo'  # nopep8
18
+    'git+https://github.com/algoo/apispec.git@dev-fork#egg=apispec-0.27.1-algoo'  # nopep8
19 19
 ]
20 20
 tests_require = [
21 21
     'pytest',
@@ -30,7 +30,7 @@ setup(
30 30
     # Versions should comply with PEP440.  For a discussion on single-sourcing
31 31
     # the version across setup.py and the project code, see
32 32
     # https://packaging.python.org/en/latest/single_source_version.html
33
-    version='0.14',
33
+    version='0.20',
34 34
 
35 35
     description='HTTP api input/output manager',
36 36
     # long_description=long_description,