generated from HIRO-MicroDataCenters-BV/template-web-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piao
committed
Jul 1, 2024
1 parent
cb019db
commit adf0b64
Showing
16 changed files
with
808 additions
and
0 deletions.
There are no files selected for viewing
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,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import connexion | ||
|
||
from openapi_server import encoder | ||
|
||
|
||
def main(): | ||
app = connexion.App(__name__, specification_dir='./openapi/') | ||
app.app.json_encoder = encoder.JSONEncoder | ||
app.add_api('openapi.yaml', | ||
arguments={'title': 'Prediction Microservice'}, | ||
pythonic_params=True) | ||
|
||
app.run(port=8080) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
21 changes: 21 additions & 0 deletions
21
client/template_web_client/openapi_server/controllers/default_controller.py
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,21 @@ | ||
import connexion | ||
from typing import Dict | ||
from typing import Tuple | ||
from typing import Union | ||
|
||
from openapi_server.models.metric import Metric # noqa: E501 | ||
from openapi_server import util | ||
from openapi_server.prediction_service import utils | ||
|
||
|
||
def get_metric_by_id(metric_id): # noqa: E501 | ||
"""Retrieve historical and predicted time series by ID | ||
Returns a time series metric # noqa: E501 | ||
:param metric_id: Id of the metric to return | ||
:type metric_id: str | ||
:rtype: Union[Metric, Tuple[Metric, int], Tuple[Metric, int, Dict[str, str]] | ||
""" | ||
return utils.query(metric_id) |
2 changes: 2 additions & 0 deletions
2
client/template_web_client/openapi_server/controllers/security_controller.py
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,2 @@ | ||
from typing import List | ||
|
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,19 @@ | ||
from json import JSONEncoder | ||
|
||
from openapi_server.models.base_model import Model | ||
|
||
|
||
class JSONEncoder(JSONEncoder): | ||
include_nulls = False | ||
|
||
def default(self, o): | ||
if isinstance(o, Model): | ||
dikt = {} | ||
for attr in o.openapi_types: | ||
value = getattr(o, attr) | ||
if value is None and not self.include_nulls: | ||
continue | ||
attr = o.attribute_map[attr] | ||
dikt[attr] = value | ||
return dikt | ||
return JSONEncoder.default(self, o) |
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,3 @@ | ||
# flake8: noqa | ||
# import models into model package | ||
from openapi_server.models.metric import Metric |
68 changes: 68 additions & 0 deletions
68
client/template_web_client/openapi_server/models/base_model.py
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,68 @@ | ||
import pprint | ||
|
||
import typing | ||
|
||
from openapi_server import util | ||
|
||
T = typing.TypeVar('T') | ||
|
||
|
||
class Model: | ||
# openapiTypes: The key is attribute name and the | ||
# value is attribute type. | ||
openapi_types: typing.Dict[str, type] = {} | ||
|
||
# attributeMap: The key is attribute name and the | ||
# value is json key in definition. | ||
attribute_map: typing.Dict[str, str] = {} | ||
|
||
@classmethod | ||
def from_dict(cls: typing.Type[T], dikt) -> T: | ||
"""Returns the dict as a model""" | ||
return util.deserialize_model(dikt, cls) | ||
|
||
def to_dict(self): | ||
"""Returns the model properties as a dict | ||
:rtype: dict | ||
""" | ||
result = {} | ||
|
||
for attr in self.openapi_types: | ||
value = getattr(self, attr) | ||
if isinstance(value, list): | ||
result[attr] = list(map( | ||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x, | ||
value | ||
)) | ||
elif hasattr(value, "to_dict"): | ||
result[attr] = value.to_dict() | ||
elif isinstance(value, dict): | ||
result[attr] = dict(map( | ||
lambda item: (item[0], item[1].to_dict()) | ||
if hasattr(item[1], "to_dict") else item, | ||
value.items() | ||
)) | ||
else: | ||
result[attr] = value | ||
|
||
return result | ||
|
||
def to_str(self): | ||
"""Returns the string representation of the model | ||
:rtype: str | ||
""" | ||
return pprint.pformat(self.to_dict()) | ||
|
||
def __repr__(self): | ||
"""For `print` and `pprint`""" | ||
return self.to_str() | ||
|
||
def __eq__(self, other): | ||
"""Returns true if both objects are equal""" | ||
return self.__dict__ == other.__dict__ | ||
|
||
def __ne__(self, other): | ||
"""Returns true if both objects are not equal""" | ||
return not self == other |
Oops, something went wrong.