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

+ 13 - 6
hapic/hapic.py View File

75
     def context(self) -> ContextInterface:
75
     def context(self) -> ContextInterface:
76
         return self._context
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
     def with_api_doc(self):
85
     def with_api_doc(self):
79
         def decorator(func):
86
         def decorator(func):
80
             @functools.wraps(func)
87
             @functools.wraps(func)
103
 
110
 
104
         return decorator
111
         return decorator
105
 
112
 
106
-    def set_context(self, context: ContextInterface) -> None:
107
-        assert not self._context
108
-        self._context = context
109
-
110
     def output_body(
113
     def output_body(
111
         self,
114
         self,
112
         schema: typing.Any,
115
         schema: typing.Any,
338
             return decoration.get_wrapper(func)
341
             return decoration.get_wrapper(func)
339
         return decorator
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
     # TODO: marshmallow an extension too ? see #2
11
     # TODO: marshmallow an extension too ? see #2
12
     'bottle',
12
     'bottle',
13
     'marshmallow',
13
     'marshmallow',
14
-    'apispec==0.25.4-algoo',
14
+    'apispec==0.27.1-algoo',
15
     'multidict'
15
     'multidict'
16
 ]
16
 ]
17
 dependency_links = [
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
 tests_require = [
20
 tests_require = [
21
     'pytest',
21
     'pytest',
30
     # Versions should comply with PEP440.  For a discussion on single-sourcing
30
     # Versions should comply with PEP440.  For a discussion on single-sourcing
31
     # the version across setup.py and the project code, see
31
     # the version across setup.py and the project code, see
32
     # https://packaging.python.org/en/latest/single_source_version.html
32
     # https://packaging.python.org/en/latest/single_source_version.html
33
-    version='0.14',
33
+    version='0.20',
34
 
34
 
35
     description='HTTP api input/output manager',
35
     description='HTTP api input/output manager',
36
     # long_description=long_description,
36
     # long_description=long_description,