Skip to content

Commit 9970392

Browse files
committed
test: check against strings using period as delimiter
An actual live example of this is when using `protoc` and producing OpenApi2 with fully qualified names on. See [here](grpc-ecosystem/grpc-gateway#2191 (comment)). The names generated will be of the form `protoname.v1.ServiceName`.
1 parent 5fa736a commit 9970392

File tree

4 files changed

+99
-126
lines changed

4 files changed

+99
-126
lines changed

end_to_end_tests/golden-record/my_test_api_client/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .import_ import Import
2424
from .model_from_all_of import ModelFromAllOf
2525
from .model_name import ModelName
26+
from .model_reference_with_periods import ModelReferenceWithPeriods
2627
from .model_with_additional_properties_inlined import ModelWithAdditionalPropertiesInlined
2728
from .model_with_additional_properties_inlined_additional_property import (
2829
ModelWithAdditionalPropertiesInlinedAdditionalProperty,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
import attr
4+
5+
T = TypeVar("T", bound="ModelReferenceWithPeriods")
6+
7+
8+
@attr.s(auto_attribs=True)
9+
class ModelReferenceWithPeriods:
10+
"""A Model with periods in its reference"""
11+
12+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
13+
14+
def to_dict(self) -> Dict[str, Any]:
15+
16+
field_dict: Dict[str, Any] = {}
17+
field_dict.update(self.additional_properties)
18+
field_dict.update({})
19+
20+
return field_dict
21+
22+
@classmethod
23+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
24+
d = src_dict.copy()
25+
model_reference_with_periods = cls()
26+
27+
model_reference_with_periods.additional_properties = d
28+
return model_reference_with_periods
29+
30+
@property
31+
def additional_keys(self) -> List[str]:
32+
return list(self.additional_properties.keys())
33+
34+
def __getitem__(self, key: str) -> Any:
35+
return self.additional_properties[key]
36+
37+
def __setitem__(self, key: str, value: Any) -> None:
38+
self.additional_properties[key] = value
39+
40+
def __delitem__(self, key: str) -> None:
41+
del self.additional_properties[key]
42+
43+
def __contains__(self, key: str) -> bool:
44+
return key in self.additional_properties

0 commit comments

Comments
 (0)