Skip to content

Commit

Permalink
CH-140 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Jul 29, 2024
1 parent 8f76ae2 commit aec6e66
Show file tree
Hide file tree
Showing 33 changed files with 783 additions and 494 deletions.
4 changes: 2 additions & 2 deletions applications/samples/api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.0
openapi: "3.0.3"
info:
title: CloudHarness Sample API
version: 0.1.0
Expand Down Expand Up @@ -27,7 +27,7 @@ paths:
operationId: error
summary: test sentry is working
x-openapi-router-controller: samples.controllers.test_controller

/ping:
get:
tags:
Expand Down
1 change: 0 additions & 1 deletion applications/samples/backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
connexion[swagger-ui]==2.14.2
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask<3.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def create_sample_resource(sample_resource=None): # noqa: E501
return "Payload is not of type SampleResource", 400

# Create a file inside the nfs
with open("/mnt/myvolume/myfile", "w") as f:
with open("/tmp/myvolume/myfile", "w") as f:
print("test", file=f)

return resource_service.create_sample_resource(sample_resource), 201


Expand Down
8 changes: 3 additions & 5 deletions applications/samples/backend/samples/encoder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from connexion.apps.flask_app import FlaskJSONEncoder

import six

from samples.models.base_model_ import Model
from flask.json import FlaskJSONEncoder
from samples.models.base_model import Model


class JSONEncoder(FlaskJSONEncoder):
Expand All @@ -11,7 +9,7 @@ class JSONEncoder(FlaskJSONEncoder):
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.openapi_types):
for attr in o.openapi_types:
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
Expand Down
3 changes: 0 additions & 3 deletions applications/samples/backend/samples/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# coding: utf-8

# flake8: noqa
from __future__ import absolute_import
# import models into model package
from samples.models.inline_response202 import InlineResponse202
from samples.models.inline_response202_task import InlineResponse202Task
Expand Down
68 changes: 68 additions & 0 deletions applications/samples/backend/samples/models/base_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pprint

import typing

from samples 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
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from samples.models.base_model_ import Model
from samples.models.base_model import Model
from samples.models.inline_response202_task import InlineResponse202Task
from samples import util

Expand Down Expand Up @@ -45,7 +42,7 @@ def from_dict(cls, dikt) -> 'InlineResponse202':
return util.deserialize_model(dikt, cls)

@property
def task(self):
def task(self) -> InlineResponse202Task:
"""Gets the task of this InlineResponse202.
Expand All @@ -55,7 +52,7 @@ def task(self):
return self._task

@task.setter
def task(self, task):
def task(self, task: InlineResponse202Task):
"""Sets the task of this InlineResponse202.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from samples.models.base_model_ import Model
from samples.models.base_model import Model
from samples import util


Expand Down Expand Up @@ -48,7 +45,7 @@ def from_dict(cls, dikt) -> 'InlineResponse202Task':
return util.deserialize_model(dikt, cls)

@property
def href(self):
def href(self) -> str:
"""Gets the href of this InlineResponse202Task.
the url where to check the operation status # noqa: E501
Expand All @@ -59,7 +56,7 @@ def href(self):
return self._href

@href.setter
def href(self, href):
def href(self, href: str):
"""Sets the href of this InlineResponse202Task.
the url where to check the operation status # noqa: E501
Expand All @@ -71,7 +68,7 @@ def href(self, href):
self._href = href

@property
def name(self):
def name(self) -> str:
"""Gets the name of this InlineResponse202Task.
Expand All @@ -81,7 +78,7 @@ def name(self):
return self._name

@name.setter
def name(self, name):
def name(self, name: str):
"""Sets the name of this InlineResponse202Task.
Expand Down
17 changes: 7 additions & 10 deletions applications/samples/backend/samples/models/sample_resource.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from samples.models.base_model_ import Model
from samples.models.base_model import Model
from samples import util


Expand Down Expand Up @@ -53,7 +50,7 @@ def from_dict(cls, dikt) -> 'SampleResource':
return util.deserialize_model(dikt, cls)

@property
def a(self):
def a(self) -> float:
"""Gets the a of this SampleResource.
# noqa: E501
Expand All @@ -64,7 +61,7 @@ def a(self):
return self._a

@a.setter
def a(self, a):
def a(self, a: float):
"""Sets the a of this SampleResource.
# noqa: E501
Expand All @@ -78,7 +75,7 @@ def a(self, a):
self._a = a

@property
def b(self):
def b(self) -> float:
"""Gets the b of this SampleResource.
# noqa: E501
Expand All @@ -89,7 +86,7 @@ def b(self):
return self._b

@b.setter
def b(self, b):
def b(self, b: float):
"""Sets the b of this SampleResource.
# noqa: E501
Expand All @@ -101,7 +98,7 @@ def b(self, b):
self._b = b

@property
def id(self):
def id(self) -> float:
"""Gets the id of this SampleResource.
# noqa: E501
Expand All @@ -112,7 +109,7 @@ def id(self):
return self._id

@id.setter
def id(self, id):
def id(self, id: float):
"""Sets the id of this SampleResource.
# noqa: E501
Expand Down
2 changes: 1 addition & 1 deletion applications/samples/backend/samples/openapi/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.0
openapi: 3.0.3
info:
contact:
email: [email protected]
Expand Down
2 changes: 0 additions & 2 deletions applications/samples/backend/samples/typing_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

import sys

if sys.version_info < (3, 7):
Expand Down
9 changes: 4 additions & 5 deletions applications/samples/backend/samples/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

import six
import typing
from samples import typing_utils

Expand All @@ -16,7 +15,7 @@ def _deserialize(data, klass):
if data is None:
return None

if klass in six.integer_types or klass in (float, str, bool, bytearray):
if klass in (int, float, str, bool, bytearray):
return _deserialize_primitive(data, klass)
elif klass == object:
return _deserialize_object(data)
Expand Down Expand Up @@ -45,7 +44,7 @@ def _deserialize_primitive(data, klass):
try:
value = klass(data)
except UnicodeEncodeError:
value = six.u(data)
value = data
except TypeError:
value = data
return value
Expand Down Expand Up @@ -110,7 +109,7 @@ def deserialize_model(data, klass):
if not instance.openapi_types:
return data

for attr, attr_type in six.iteritems(instance.openapi_types):
for attr, attr_type in instance.openapi_types.items():
if data is not None \
and instance.attribute_map[attr] in data \
and isinstance(data, (list, dict)):
Expand Down Expand Up @@ -145,4 +144,4 @@ def _deserialize_dict(data, boxed_type):
:rtype: dict
"""
return {k: _deserialize(v, boxed_type)
for k, v in six.iteritems(data)}
for k, v in data.items() }
1 change: 0 additions & 1 deletion applications/samples/backend/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

REQUIRES = [
"connexion>=2.0.2",
"swagger-ui-bundle>=0.0.2",
"python_dateutil>=2.6.0",
"pyjwt>=2.6.0",
"cloudharness"
Expand Down
2 changes: 1 addition & 1 deletion applications/samples/backend/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ skipsdist=True
[testenv]
deps=-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
{toxinidir}
{toxinidir}

commands=
pytest --cov=samples
1 change: 1 addition & 0 deletions applications/samples/backend/www/assets/index-Cyl2oP5E.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{text-align:center;background-color:"#eeeeee";font-family:Roboto,Helvetica,sans-serif}
Loading

0 comments on commit aec6e66

Please sign in to comment.