Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions activitysmith_openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

# import models into sdk package
from activitysmith_openapi.models.activity_metric import ActivityMetric
from activitysmith_openapi.models.activity_metric_value import ActivityMetricValue
from activitysmith_openapi.models.alert_payload import AlertPayload
from activitysmith_openapi.models.bad_request_error import BadRequestError
from activitysmith_openapi.models.channel_target import ChannelTarget
Expand Down
3 changes: 2 additions & 1 deletion activitysmith_openapi/docs/ActivityMetric.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**label** | **str** | |
**value** | **float** | |
**value** | [**ActivityMetricValue**](ActivityMetricValue.md) | |
**unit** | **str** | | [optional]
**color** | **str** | Optional per-metric accent color for metrics and stats activities. | [optional]

## Example

Expand Down
28 changes: 28 additions & 0 deletions activitysmith_openapi/docs/ActivityMetricValue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ActivityMetricValue


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

## Example

```python
from activitysmith_openapi.models.activity_metric_value import ActivityMetricValue

# TODO update the JSON string below
json = "{}"
# create an instance of ActivityMetricValue from a JSON string
activity_metric_value_instance = ActivityMetricValue.from_json(json)
# print the JSON string representation of the object
print(ActivityMetricValue.to_json())

# convert the object into a dict
activity_metric_value_dict = activity_metric_value_instance.to_dict()
# create an instance of ActivityMetricValue from a dict
activity_metric_value_from_dict = ActivityMetricValue.from_dict(activity_metric_value_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


1 change: 1 addition & 0 deletions activitysmith_openapi/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# import models into model package
from activitysmith_openapi.models.activity_metric import ActivityMetric
from activitysmith_openapi.models.activity_metric_value import ActivityMetricValue
from activitysmith_openapi.models.alert_payload import AlertPayload
from activitysmith_openapi.models.bad_request_error import BadRequestError
from activitysmith_openapi.models.channel_target import ChannelTarget
Expand Down
28 changes: 22 additions & 6 deletions activitysmith_openapi/models/activity_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import re # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from activitysmith_openapi.models.activity_metric_value import ActivityMetricValue
from typing import Optional, Set
from typing_extensions import Self

Expand All @@ -28,10 +29,21 @@ class ActivityMetric(BaseModel):
ActivityMetric
""" # noqa: E501
label: Annotated[str, Field(min_length=1, strict=True)]
value: Union[Annotated[float, Field(le=100, strict=True, ge=0)], Annotated[int, Field(le=100, strict=True, ge=0)]]
value: ActivityMetricValue
unit: Optional[StrictStr] = None
color: Optional[StrictStr] = Field(default=None, description="Optional per-metric accent color for metrics and stats activities.")
additional_properties: Dict[str, Any] = {}
__properties: ClassVar[List[str]] = ["label", "value", "unit"]
__properties: ClassVar[List[str]] = ["label", "value", "unit", "color"]

@field_validator('color')
def color_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value

if value not in set(['lime', 'green', 'cyan', 'blue', 'purple', 'magenta', 'red', 'orange', 'yellow']):
raise ValueError("must be one of enum values ('lime', 'green', 'cyan', 'blue', 'purple', 'magenta', 'red', 'orange', 'yellow')")
return value

model_config = ConfigDict(
populate_by_name=True,
Expand Down Expand Up @@ -74,6 +86,9 @@ def to_dict(self) -> Dict[str, Any]:
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of value
if self.value:
_dict['value'] = self.value.to_dict()
# puts key-value pairs in additional_properties in the top level
if self.additional_properties is not None:
for _key, _value in self.additional_properties.items():
Expand All @@ -92,8 +107,9 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:

_obj = cls.model_validate({
"label": obj.get("label"),
"value": obj.get("value"),
"unit": obj.get("unit")
"value": ActivityMetricValue.from_dict(obj["value"]) if obj.get("value") is not None else None,
"unit": obj.get("unit"),
"color": obj.get("color")
})
# store additional fields in additional_properties
for _key in obj.keys():
Expand Down
144 changes: 144 additions & 0 deletions activitysmith_openapi/models/activity_metric_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# coding: utf-8

"""
ActivitySmith API

Send push notifications and Live Activities to your own devices via a single API key.

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501


from __future__ import annotations
import json
import pprint
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, List, Optional, Union
from typing_extensions import Annotated
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ACTIVITYMETRICVALUE_ONE_OF_SCHEMAS = ["float", "str"]

class ActivityMetricValue(BaseModel):
"""
ActivityMetricValue
"""
# data type: float
oneof_schema_1_validator: Optional[Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]]] = None
# data type: str
oneof_schema_2_validator: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=64)]] = None
actual_instance: Optional[Union[float, str]] = None
one_of_schemas: Set[str] = { "float", "str" }

model_config = ConfigDict(
validate_assignment=True,
protected_namespaces=(),
)


def __init__(self, *args, **kwargs) -> None:
if args:
if len(args) > 1:
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
if kwargs:
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
super().__init__(actual_instance=args[0])
else:
super().__init__(**kwargs)

@field_validator('actual_instance')
def actual_instance_must_validate_oneof(cls, v):
instance = ActivityMetricValue.model_construct()
error_messages = []
match = 0
# validate data type: float
try:
instance.oneof_schema_1_validator = v
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
# validate data type: str
try:
instance.oneof_schema_2_validator = v
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
if match > 1:
# more than 1 match
raise ValueError("Multiple matches found when setting `actual_instance` in ActivityMetricValue with oneOf schemas: float, str. Details: " + ", ".join(error_messages))
elif match == 0:
# no match
raise ValueError("No match found when setting `actual_instance` in ActivityMetricValue with oneOf schemas: float, str. Details: " + ", ".join(error_messages))
else:
return v

@classmethod
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
return cls.from_json(json.dumps(obj))

@classmethod
def from_json(cls, json_str: str) -> Self:
"""Returns the object represented by the json string"""
instance = cls.model_construct()
error_messages = []
match = 0

# deserialize data into float
try:
# validation
instance.oneof_schema_1_validator = json.loads(json_str)
# assign value to actual_instance
instance.actual_instance = instance.oneof_schema_1_validator
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
# deserialize data into str
try:
# validation
instance.oneof_schema_2_validator = json.loads(json_str)
# assign value to actual_instance
instance.actual_instance = instance.oneof_schema_2_validator
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

if match > 1:
# more than 1 match
raise ValueError("Multiple matches found when deserializing the JSON string into ActivityMetricValue with oneOf schemas: float, str. Details: " + ", ".join(error_messages))
elif match == 0:
# no match
raise ValueError("No match found when deserializing the JSON string into ActivityMetricValue with oneOf schemas: float, str. Details: " + ", ".join(error_messages))
else:
return instance

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
if self.actual_instance is None:
return "null"

if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
return self.actual_instance.to_json()
else:
return json.dumps(self.actual_instance)

def to_dict(self) -> Optional[Union[Dict[str, Any], float, str]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
return self.actual_instance.to_dict()
else:
# primitive type
return self.actual_instance

def to_str(self) -> str:
"""Returns the string representation of the actual instance"""
return pprint.pformat(self.model_dump())


7 changes: 4 additions & 3 deletions activitysmith_openapi/test/test_activity_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def make_instance(self, include_optional) -> ActivityMetric:
if include_optional:
return ActivityMetric(
label = '0',
value = 0,
unit = ''
value = None,
unit = '',
color = 'lime'
)
else:
return ActivityMetric(
label = '0',
value = 0,
value = None,
)
"""

Expand Down
50 changes: 50 additions & 0 deletions activitysmith_openapi/test/test_activity_metric_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# coding: utf-8

"""
ActivitySmith API

Send push notifications and Live Activities to your own devices via a single API key.

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501


import unittest

from activitysmith_openapi.models.activity_metric_value import ActivityMetricValue

class TestActivityMetricValue(unittest.TestCase):
"""ActivityMetricValue unit test stubs"""

def setUp(self):
pass

def tearDown(self):
pass

def make_instance(self, include_optional) -> ActivityMetricValue:
"""Test ActivityMetricValue
include_optional is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `ActivityMetricValue`
"""
model = ActivityMetricValue()
if include_optional:
return ActivityMetricValue(
)
else:
return ActivityMetricValue(
)
"""

def testActivityMetricValue(self):
"""Test ActivityMetricValue"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)

if __name__ == '__main__':
unittest.main()