Skip to content

Commit e01fdee

Browse files
authored
add uuid pattern tests to python client (#23040)
1 parent a2b7776 commit e01fdee

114 files changed

Lines changed: 1197 additions & 80 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,3 +2919,10 @@ components:
29192919
type: string
29202920
enum: [JSON, CSV, XML]
29212921
default: JSON
2922+
UuidWithPattern:
2923+
type: object
2924+
properties:
2925+
id:
2926+
type: string
2927+
format: uuid
2928+
pattern: "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"

samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ docs/UnnamedDictWithAdditionalStringListProperties.md
122122
docs/UploadFileWithAdditionalPropertiesRequestObject.md
123123
docs/User.md
124124
docs/UserApi.md
125+
docs/UuidWithPattern.md
125126
docs/WithNestedOneOf.md
126127
git_push.sh
127128
petstore_api/__init__.py
@@ -250,6 +251,7 @@ petstore_api/models/unnamed_dict_with_additional_model_list_properties.py
250251
petstore_api/models/unnamed_dict_with_additional_string_list_properties.py
251252
petstore_api/models/upload_file_with_additional_properties_request_object.py
252253
petstore_api/models/user.py
254+
petstore_api/models/uuid_with_pattern.py
253255
petstore_api/models/with_nested_one_of.py
254256
petstore_api/py.typed
255257
petstore_api/rest.py

samples/openapi3/client/petstore/python-aiohttp/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Class | Method | HTTP request | Description
262262
- [UnnamedDictWithAdditionalStringListProperties](docs/UnnamedDictWithAdditionalStringListProperties.md)
263263
- [UploadFileWithAdditionalPropertiesRequestObject](docs/UploadFileWithAdditionalPropertiesRequestObject.md)
264264
- [User](docs/User.md)
265+
- [UuidWithPattern](docs/UuidWithPattern.md)
265266
- [WithNestedOneOf](docs/WithNestedOneOf.md)
266267

267268

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# UuidWithPattern
2+
3+
4+
## Properties
5+
6+
Name | Type | Description | Notes
7+
------------ | ------------- | ------------- | -------------
8+
**id** | **UUID** | | [optional]
9+
10+
## Example
11+
12+
```python
13+
from petstore_api.models.uuid_with_pattern import UuidWithPattern
14+
15+
# TODO update the JSON string below
16+
json = "{}"
17+
# create an instance of UuidWithPattern from a JSON string
18+
uuid_with_pattern_instance = UuidWithPattern.from_json(json)
19+
# print the JSON string representation of the object
20+
print(UuidWithPattern.to_json())
21+
22+
# convert the object into a dict
23+
uuid_with_pattern_dict = uuid_with_pattern_instance.to_dict()
24+
# create an instance of UuidWithPattern from a dict
25+
uuid_with_pattern_from_dict = UuidWithPattern.from_dict(uuid_with_pattern_dict)
26+
```
27+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
28+
29+

samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"UnnamedDictWithAdditionalStringListProperties",
148148
"UploadFileWithAdditionalPropertiesRequestObject",
149149
"User",
150+
"UuidWithPattern",
150151
"WithNestedOneOf",
151152
]
152153

@@ -284,5 +285,6 @@
284285
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties as UnnamedDictWithAdditionalStringListProperties
285286
from petstore_api.models.upload_file_with_additional_properties_request_object import UploadFileWithAdditionalPropertiesRequestObject as UploadFileWithAdditionalPropertiesRequestObject
286287
from petstore_api.models.user import User as User
288+
from petstore_api.models.uuid_with_pattern import UuidWithPattern as UuidWithPattern
287289
from petstore_api.models.with_nested_one_of import WithNestedOneOf as WithNestedOneOf
288290

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,6 @@
124124
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties
125125
from petstore_api.models.upload_file_with_additional_properties_request_object import UploadFileWithAdditionalPropertiesRequestObject
126126
from petstore_api.models.user import User
127+
from petstore_api.models.uuid_with_pattern import UuidWithPattern
127128
from petstore_api.models.with_nested_one_of import WithNestedOneOf
128129

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# coding: utf-8
2+
3+
"""
4+
OpenAPI Petstore
5+
6+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
7+
8+
The version of the OpenAPI document: 1.0.0
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
""" # noqa: E501
13+
14+
15+
from __future__ import annotations
16+
import pprint
17+
import re # noqa: F401
18+
import json
19+
20+
from pydantic import BaseModel, ConfigDict, field_validator
21+
from typing import Any, ClassVar, Dict, List, Optional
22+
from uuid import UUID
23+
from typing import Optional, Set
24+
from typing_extensions import Self
25+
26+
class UuidWithPattern(BaseModel):
27+
"""
28+
UuidWithPattern
29+
""" # noqa: E501
30+
id: Optional[UUID] = None
31+
__properties: ClassVar[List[str]] = ["id"]
32+
33+
@field_validator('id')
34+
def id_validate_regular_expression(cls, value):
35+
"""Validates the regular expression"""
36+
if value is None:
37+
return value
38+
39+
if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
40+
raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/")
41+
return value
42+
43+
model_config = ConfigDict(
44+
populate_by_name=True,
45+
validate_assignment=True,
46+
protected_namespaces=(),
47+
)
48+
49+
50+
def to_str(self) -> str:
51+
"""Returns the string representation of the model using alias"""
52+
return pprint.pformat(self.model_dump(by_alias=True))
53+
54+
def to_json(self) -> str:
55+
"""Returns the JSON representation of the model using alias"""
56+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
57+
return json.dumps(self.to_dict())
58+
59+
@classmethod
60+
def from_json(cls, json_str: str) -> Optional[Self]:
61+
"""Create an instance of UuidWithPattern from a JSON string"""
62+
return cls.from_dict(json.loads(json_str))
63+
64+
def to_dict(self) -> Dict[str, Any]:
65+
"""Return the dictionary representation of the model using alias.
66+
67+
This has the following differences from calling pydantic's
68+
`self.model_dump(by_alias=True)`:
69+
70+
* `None` is only added to the output dict for nullable fields that
71+
were set at model initialization. Other fields with value `None`
72+
are ignored.
73+
"""
74+
excluded_fields: Set[str] = set([
75+
])
76+
77+
_dict = self.model_dump(
78+
by_alias=True,
79+
exclude=excluded_fields,
80+
exclude_none=True,
81+
)
82+
return _dict
83+
84+
@classmethod
85+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
86+
"""Create an instance of UuidWithPattern from a dict"""
87+
if obj is None:
88+
return None
89+
90+
if not isinstance(obj, dict):
91+
return cls.model_validate(obj)
92+
93+
_obj = cls.model_validate({
94+
"id": obj.get("id")
95+
})
96+
return _obj
97+
98+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# coding: utf-8
2+
3+
"""
4+
OpenAPI Petstore
5+
6+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
7+
8+
The version of the OpenAPI document: 1.0.0
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
""" # noqa: E501
13+
14+
15+
import unittest
16+
17+
from petstore_api.models.uuid_with_pattern import UuidWithPattern
18+
19+
class TestUuidWithPattern(unittest.TestCase):
20+
"""UuidWithPattern unit test stubs"""
21+
22+
def setUp(self):
23+
pass
24+
25+
def tearDown(self):
26+
pass
27+
28+
def make_instance(self, include_optional) -> UuidWithPattern:
29+
"""Test UuidWithPattern
30+
include_optional is a boolean, when False only required
31+
params are included, when True both required and
32+
optional params are included """
33+
# uncomment below to create an instance of `UuidWithPattern`
34+
"""
35+
model = UuidWithPattern()
36+
if include_optional:
37+
return UuidWithPattern(
38+
id = '62ECB020-8429-430c-a01F-FCCfeEe150AC'
39+
)
40+
else:
41+
return UuidWithPattern(
42+
)
43+
"""
44+
45+
def testUuidWithPattern(self):
46+
"""Test UuidWithPattern"""
47+
# inst_req_only = self.make_instance(include_optional=False)
48+
# inst_req_and_optional = self.make_instance(include_optional=True)
49+
50+
if __name__ == '__main__':
51+
unittest.main()

samples/openapi3/client/petstore/python-httpx/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ docs/UnnamedDictWithAdditionalStringListProperties.md
122122
docs/UploadFileWithAdditionalPropertiesRequestObject.md
123123
docs/User.md
124124
docs/UserApi.md
125+
docs/UuidWithPattern.md
125126
docs/WithNestedOneOf.md
126127
git_push.sh
127128
petstore_api/__init__.py
@@ -250,6 +251,7 @@ petstore_api/models/unnamed_dict_with_additional_model_list_properties.py
250251
petstore_api/models/unnamed_dict_with_additional_string_list_properties.py
251252
petstore_api/models/upload_file_with_additional_properties_request_object.py
252253
petstore_api/models/user.py
254+
petstore_api/models/uuid_with_pattern.py
253255
petstore_api/models/with_nested_one_of.py
254256
petstore_api/py.typed
255257
petstore_api/rest.py

samples/openapi3/client/petstore/python-httpx/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Class | Method | HTTP request | Description
262262
- [UnnamedDictWithAdditionalStringListProperties](docs/UnnamedDictWithAdditionalStringListProperties.md)
263263
- [UploadFileWithAdditionalPropertiesRequestObject](docs/UploadFileWithAdditionalPropertiesRequestObject.md)
264264
- [User](docs/User.md)
265+
- [UuidWithPattern](docs/UuidWithPattern.md)
265266
- [WithNestedOneOf](docs/WithNestedOneOf.md)
266267

267268

0 commit comments

Comments
 (0)