Skip to content

Commit ebea6ce

Browse files
committed
[python] sync HTTPX wire-name sample
Commit 3a307ab changes escaped wire names in the shared Python petstore fixture. Its generated output predates the HTTPX sync sample added by 5165243, leaving that newer sample's models and tests on sanitized names. Regenerate the five affected models and update the oneOf and anyOf tests to send and assert the actual wire names.
1 parent 6622b5e commit ebea6ce

6 files changed

Lines changed: 41 additions & 25 deletions

File tree

‎samples/openapi3/client/petstore/python-httpx-sync/petstore_api/models/basque_pig.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class BasquePig(BaseModel):
2727
"""
2828
BasquePig
2929
""" # noqa: E501
30-
class_name: StrictStr = Field(alias="className")
30+
class_name: StrictStr = Field(alias="class'\"\\Name")
3131
color: StrictStr
32-
__properties: ClassVar[List[str]] = ["className", "color"]
32+
__properties: ClassVar[List[str]] = ["class'\"\\Name", "color"]
3333

3434
model_config = ConfigDict(
3535
validate_by_name=True,
@@ -82,7 +82,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8282
return cls.model_validate(obj)
8383

8484
_obj = cls.model_validate({
85-
"className": obj.get("className"),
85+
"class'\"\\Name": obj.get("class'\"\\Name"),
8686
"color": obj.get("color")
8787
})
8888
return _obj

‎samples/openapi3/client/petstore/python-httpx-sync/petstore_api/models/danish_pig.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class DanishPig(BaseModel):
2727
"""
2828
DanishPig
2929
""" # noqa: E501
30-
class_name: StrictStr = Field(alias="className")
30+
class_name: StrictStr = Field(alias="class'\"\\Name")
3131
size: StrictInt
32-
__properties: ClassVar[List[str]] = ["className", "size"]
32+
__properties: ClassVar[List[str]] = ["class'\"\\Name", "size"]
3333

3434
model_config = ConfigDict(
3535
validate_by_name=True,
@@ -82,7 +82,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8282
return cls.model_validate(obj)
8383

8484
_obj = cls.model_validate({
85-
"className": obj.get("className"),
85+
"class'\"\\Name": obj.get("class'\"\\Name"),
8686
"size": obj.get("size")
8787
})
8888
return _obj

‎samples/openapi3/client/petstore/python-httpx-sync/petstore_api/models/discriminator_all_of_sub.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DiscriminatorAllOfSub(DiscriminatorAllOfSuper):
2828
"""
2929
DiscriminatorAllOfSub
3030
""" # noqa: E501
31-
__properties: ClassVar[List[str]] = ["elementType"]
31+
__properties: ClassVar[List[str]] = ["element'\"\\Type"]
3232

3333
model_config = ConfigDict(
3434
validate_by_name=True,
@@ -81,7 +81,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8181
return cls.model_validate(obj)
8282

8383
_obj = cls.model_validate({
84-
"elementType": obj.get("elementType")
84+
"element'\"\\Type": obj.get("element'\"\\Type")
8585
})
8686
return _obj
8787

‎samples/openapi3/client/petstore/python-httpx-sync/petstore_api/models/discriminator_all_of_super.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class DiscriminatorAllOfSuper(BaseModel):
3232
"""
3333
DiscriminatorAllOfSuper
3434
""" # noqa: E501
35-
element_type: StrictStr = Field(alias="elementType")
36-
__properties: ClassVar[List[str]] = ["elementType"]
35+
element_type: StrictStr = Field(alias="element'\"\\Type")
36+
__properties: ClassVar[List[str]] = ["element'\"\\Type"]
3737

3838
model_config = ConfigDict(
3939
validate_by_name=True,
@@ -44,11 +44,11 @@ class DiscriminatorAllOfSuper(BaseModel):
4444

4545

4646
# JSON field name that stores the object type
47-
__discriminator_property_name: ClassVar[str] = 'elementType'
47+
__discriminator_property_name: ClassVar[str] = 'element\'"\\Type'
4848

4949
# discriminator mappings
5050
__discriminator_value_class_map: ClassVar[Dict[str, str]] = {
51-
'DiscriminatorAllOfSub': 'DiscriminatorAllOfSub'
51+
'sub\'"\\kind\nvalue': 'DiscriminatorAllOfSub'
5252
}
5353

5454
@classmethod

‎samples/openapi3/client/petstore/python-httpx-sync/petstore_api/models/with_nested_one_of.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import re # noqa: F401
1818
import json
1919

20-
from pydantic import BaseModel, ConfigDict, StrictInt
20+
from pydantic import BaseModel, ConfigDict, Field, StrictInt
2121
from typing import Any, ClassVar, Dict, List, Optional
2222
from petstore_api.models.one_of_enum_string import OneOfEnumString
2323
from petstore_api.models.pig import Pig
@@ -30,9 +30,9 @@ class WithNestedOneOf(BaseModel):
3030
WithNestedOneOf
3131
""" # noqa: E501
3232
size: Optional[StrictInt] = None
33-
nested_pig: Optional[Pig] = None
33+
nested_pig: Optional[Pig] = Field(default=None, alias="nested_\npig")
3434
nested_oneof_enum_string: Optional[OneOfEnumString] = None
35-
__properties: ClassVar[List[str]] = ["size", "nested_pig", "nested_oneof_enum_string"]
35+
__properties: ClassVar[List[str]] = ["size", "nested_\npig", "nested_oneof_enum_string"]
3636

3737
model_config = ConfigDict(
3838
validate_by_name=True,
@@ -75,7 +75,7 @@ def to_dict(self) -> Dict[str, Any]:
7575
)
7676
# override the default output from pydantic by calling `to_dict()` of nested_pig
7777
if self.nested_pig:
78-
_dict['nested_pig'] = self.nested_pig.to_dict()
78+
_dict['nested_\npig'] = self.nested_pig.to_dict()
7979
return _dict
8080

8181
@classmethod
@@ -89,7 +89,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8989

9090
_obj = cls.model_validate({
9191
"size": obj.get("size"),
92-
"nested_pig": Pig.from_dict(obj["nested_pig"]) if obj.get("nested_pig") is not None else None,
92+
"nested_\npig": Pig.from_dict(obj["nested_\npig"]) if obj.get("nested_\npig") is not None else None,
9393
"nested_oneof_enum_string": obj.get("nested_oneof_enum_string")
9494
})
9595
return _obj

‎samples/openapi3/client/petstore/python-httpx-sync/tests/test_model.py‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,18 @@ def test_equal(self):
7575
self.assertFalse(self.pet1 == self.pet2)
7676

7777
def test_oneOf(self):
78+
mapping_value = """basque'"\\pig\nkind"""
79+
wire_name = """class'"\\Name"""
80+
wire_value = {wire_name: mapping_value, "color": "red"}
81+
wire_json = json.dumps(wire_value)
82+
7883
# test new Pig
7984
new_pig = petstore_api.Pig()
8085
self.assertEqual("null", new_pig.to_json())
8186
self.assertEqual(None, new_pig.actual_instance)
8287

8388
# test from_json
84-
json_str = '{"className": "BasquePig", "color": "red"}'
85-
p = petstore_api.Pig.from_json(json_str)
89+
p = petstore_api.Pig.from_json(wire_json)
8690
self.assertIsInstance(p.actual_instance, petstore_api.BasquePig)
8791

8892
# test init
@@ -113,26 +117,38 @@ def test_oneOf(self):
113117
self.assertIn("Input should be a valid dictionary or instance of DanishPig", str(e))
114118

115119
# test to_json
116-
self.assertEqual(p.to_json(), '{"className": "BasquePig", "color": "red"}')
120+
self.assertEqual(p.to_json(), wire_json)
117121

118122
# test nested property
119-
nested = petstore_api.WithNestedOneOf(size = 1, nested_pig = p)
120-
self.assertEqual(nested.to_json(), '{"size": 1, "nested_pig": {"className": "BasquePig", "color": "red"}}')
123+
nested_wire_name = "nested_\npig"
124+
nested = petstore_api.WithNestedOneOf.from_dict({
125+
"size": 1,
126+
nested_wire_name: wire_value,
127+
})
128+
assert nested is not None
129+
self.assertEqual(
130+
nested.to_json(),
131+
json.dumps({"size": 1, nested_wire_name: wire_value}),
132+
)
121133

122134
nested_json = nested.to_json()
123135
nested2 = petstore_api.WithNestedOneOf.from_json(nested_json)
124136
assert nested2 is not None
125137
self.assertEqual(nested2.to_json(), nested_json)
126138

127139
def test_anyOf(self):
140+
mapping_value = """basque'"\\pig\nkind"""
141+
wire_name = """class'"\\Name"""
142+
wire_value = {wire_name: mapping_value, "color": "red"}
143+
wire_json = json.dumps(wire_value)
144+
128145
# test new AnyOfPig
129146
new_anypig = petstore_api.AnyOfPig()
130147
self.assertEqual("null", new_anypig.to_json())
131148
self.assertEqual(None, new_anypig.actual_instance)
132149

133150
# test from_json
134-
json_str = '{"className": "BasquePig", "color": "red"}'
135-
p = petstore_api.AnyOfPig.from_json(json_str)
151+
p = petstore_api.AnyOfPig.from_json(wire_json)
136152
self.assertIsInstance(p.actual_instance, petstore_api.BasquePig)
137153

138154
# test init
@@ -168,7 +184,7 @@ def test_anyOf(self):
168184
self.assertIn("Input should be a valid dictionary or instance of DanishPig", str(e))
169185

170186
# test to_json
171-
self.assertEqual(p.to_json(), '{"className": "BasquePig", "color": "red"}')
187+
self.assertEqual(p.to_json(), wire_json)
172188

173189
def test_inheritance(self):
174190
dog = petstore_api.Dog(breed="bulldog", className="dog", color="white")

0 commit comments

Comments
 (0)