Browse Source

Own hapic object for each api example

Guénaël Muller 6 years ago
parent
commit
9f331a613b
3 changed files with 14 additions and 15 deletions
  1. 4 5
      example/fake_api/bottle_api.py
  2. 5 5
      example/fake_api/flask_api.py
  3. 5 5
      example/fake_api/pyramid_api.py

+ 4 - 5
example/fake_api/bottle_api.py View File

@@ -5,13 +5,12 @@ from http import HTTPStatus
5 5
 import bottle
6 6
 import time
7 7
 from datetime import datetime
8
-import hapic
8
+from hapic import Hapic
9 9
 from example.fake_api.schema import *
10 10
 from hapic.data import HapicData
11
+from hapic.ext.bottle import BottleContext
11 12
 
12
-
13
-class NoContentException(Exception):
14
-    pass
13
+hapic = Hapic()
15 14
 
16 15
 
17 16
 class BottleController(object):
@@ -111,7 +110,7 @@ if __name__ == "__main__":
111 110
     app = bottle.Bottle()
112 111
     controllers = BottleController()
113 112
     controllers.bind(app)
114
-    hapic.set_context(hapic.ext.bottle.BottleContext(app))
113
+    hapic.set_context(BottleContext(app))
115 114
     time.sleep(1)
116 115
     s = json.dumps(hapic.generate_doc())
117 116
     time.sleep(1)

+ 5 - 5
example/fake_api/flask_api.py View File

@@ -5,13 +5,13 @@ from http import HTTPStatus
5 5
 import flask
6 6
 import time
7 7
 from datetime import datetime
8
-import hapic
8
+from hapic import Hapic
9
+
9 10
 from example.fake_api.schema import *
11
+from hapic.ext.flask import FlaskContext
10 12
 from hapic.data import HapicData
11 13
 
12
-
13
-class NoContentException(Exception):
14
-    pass
14
+hapic = Hapic()
15 15
 
16 16
 
17 17
 class FlaskController(object):
@@ -118,7 +118,7 @@ if __name__ == "__main__":
118 118
     app = flask.Flask(__name__)
119 119
     controllers = FlaskController()
120 120
     controllers.bind(app)
121
-    hapic.set_context(hapic.ext.flask.FlaskContext(app))
121
+    hapic.set_context(FlaskContext(app))
122 122
     time.sleep(1)
123 123
     s = json.dumps(hapic.generate_doc())
124 124
     time.sleep(1)

+ 5 - 5
example/fake_api/pyramid_api.py View File

@@ -6,13 +6,13 @@ from pyramid.config import Configurator
6 6
 from wsgiref.simple_server import make_server
7 7
 import time
8 8
 from datetime import datetime
9
-import hapic
9
+from hapic import Hapic
10 10
 from example.fake_api.schema import *
11
-from hapic.data import HapicData
12 11
 
12
+from hapic.data import HapicData
13
+from hapic.ext.pyramid import PyramidContext
13 14
 
14
-class NoContentException(Exception):
15
-    pass
15
+hapic = Hapic()
16 16
 
17 17
 
18 18
 class PyramidController(object):
@@ -121,7 +121,7 @@ if __name__ == "__main__":
121 121
     configurator = Configurator(autocommit=True)
122 122
     controllers = PyramidController()
123 123
     controllers.bind(configurator)
124
-    hapic.set_context(hapic.ext.pyramid.PyramidContext(configurator))
124
+    hapic.set_context(PyramidContext(configurator))
125 125
     time.sleep(1)
126 126
     s = json.dumps(hapic.generate_doc())
127 127
     time.sleep(1)