-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dependency issue based on ssola/python-flask-microservice#3 and s…
- Loading branch information
1 parent
de8f5c1
commit fae2ea5
Showing
4 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
items = { | ||
0: {"name": "First item"} | ||
} | ||
from flask_injector import inject | ||
from services.provider import ItemsProvider | ||
|
||
|
||
def search() -> list: | ||
return items | ||
@inject | ||
def search(data_provider: ItemsProvider) -> list: | ||
return data_provider.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
from connexion.resolver import RestyResolver | ||
import connexion | ||
|
||
from injector import Binder | ||
from flask_injector import FlaskInjector | ||
from connexion.resolver import RestyResolver | ||
|
||
from services.provider import ItemsProvider | ||
|
||
|
||
def configure(binder: Binder) -> Binder: | ||
binder.bind( | ||
ItemsProvider, | ||
ItemsProvider([{"Name": "Test 1"}]) | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = connexion.App(__name__, specification_dir='swagger/') | ||
app.add_api('app.yaml', resolver=RestyResolver('api')) | ||
FlaskInjector(app=app.app, modules=[configure]) | ||
app.run(port=9090) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ItemsProvider(object): | ||
def __init__(self, items: list = []): | ||
self._items = items | ||
|
||
def get(self, number_of_items: int = 5) -> list: | ||
if not self._items: | ||
return [] | ||
|
||
if number_of_items > len(self._items): | ||
number_of_items = len(self._items) | ||
|
||
return self._items[0:number_of_items] |