Skip to content

Commit d8a0dfc

Browse files
dbantyestyrke
authored andcommitted
feat: Add UUID string format. Thanks @estyrke! (openapi-generators#1140)
Replaces openapi-generators#1131 with a few fixes --------- Co-authored-by: Emil Styrke <[email protected]> Co-authored-by: Dylan Anthony <[email protected]>
1 parent 45a22dd commit d8a0dfc

File tree

11 files changed

+325
-2
lines changed

11 files changed

+325
-2
lines changed

end_to_end_tests/__snapshots__/test_end_to_end.ambr

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
Circular $ref in request body
1010

1111

12+
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose
13+
14+
'''
15+
# ---
16+
# name: test_documents_with_errors[invalid-uuid-defaults]
17+
'''
18+
Generating /test-documents-with-errors
19+
Warning(s) encountered while generating. Client was generated, but some pieces may be missing
20+
21+
WARNING parsing PUT / within default. Endpoint will not be generated.
22+
23+
cannot parse parameter of endpoint put_: Invalid UUID value: 3
24+
25+
26+
WARNING parsing POST / within default. Endpoint will not be generated.
27+
28+
cannot parse parameter of endpoint post_: Invalid UUID value: notauuid
29+
30+
1231
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose
1332

1433
'''

end_to_end_tests/baseline_openapi_3.0.json

+19
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,8 @@
17651765
"aCamelDateTime",
17661766
"a_date",
17671767
"a_nullable_date",
1768+
"a_uuid",
1769+
"a_nullable_uuid",
17681770
"required_nullable",
17691771
"required_not_nullable",
17701772
"model",
@@ -1835,6 +1837,23 @@
18351837
"type": "string",
18361838
"format": "date"
18371839
},
1840+
"a_uuid": {
1841+
"title": "A Uuid",
1842+
"type": "string",
1843+
"format": "uuid"
1844+
},
1845+
"a_nullable_uuid": {
1846+
"title": "A Nullable Uuid",
1847+
"type": "string",
1848+
"format": "uuid",
1849+
"nullable": true,
1850+
"default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41"
1851+
},
1852+
"a_not_required_uuid": {
1853+
"title": "A Not Required Uuid",
1854+
"type": "string",
1855+
"format": "uuid"
1856+
},
18381857
"1_leading_digit": {
18391858
"title": "Leading Digit",
18401859
"type": "string"

end_to_end_tests/baseline_openapi_3.1.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,8 @@ info:
17501750
"aCamelDateTime",
17511751
"a_date",
17521752
"a_nullable_date",
1753+
"a_uuid",
1754+
"a_nullable_uuid",
17531755
"required_nullable",
17541756
"required_not_nullable",
17551757
"model",
@@ -1822,6 +1824,29 @@ info:
18221824
"type": "string",
18231825
"format": "date"
18241826
},
1827+
"a_uuid": {
1828+
"title": "A Uuid",
1829+
"type": "string",
1830+
"format": "uuid"
1831+
},
1832+
"a_nullable_uuid": {
1833+
"title": "A Nullable Uuid",
1834+
"anyOf": [
1835+
{
1836+
"type": "string",
1837+
"format": "uuid",
1838+
},
1839+
{
1840+
"type": "null"
1841+
}
1842+
],
1843+
"default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41"
1844+
},
1845+
"a_not_required_uuid": {
1846+
"title": "A Not Required Uuid",
1847+
"type": "string",
1848+
"format": "uuid"
1849+
},
18251850
"1_leading_digit": {
18261851
"title": "Leading Digit",
18271852
"type": "string"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: "Circular Body Ref"
4+
version: "0.1.0"
5+
paths:
6+
/:
7+
post:
8+
parameters:
9+
- name: id
10+
in: query
11+
required: false
12+
schema:
13+
type: string
14+
format: uuid
15+
default: "notauuid"
16+
responses:
17+
"200":
18+
description: "Successful Response"
19+
put:
20+
parameters:
21+
- name: another_id
22+
in: query
23+
required: false
24+
schema:
25+
type: string
26+
format: uuid
27+
default: 3
28+
responses:
29+
"200":
30+
description: "Successful Response"

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

+50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast
3+
from uuid import UUID
34

45
from attrs import define as _attrs_define
56
from dateutil.parser import isoparse
@@ -27,6 +28,8 @@ class AModel:
2728
a_camel_date_time (Union[datetime.date, datetime.datetime]):
2829
a_date (datetime.date):
2930
a_nullable_date (Union[None, datetime.date]):
31+
a_uuid (UUID):
32+
a_nullable_uuid (Union[None, UUID]): Default: UUID('07EF8B4D-AA09-4FFA-898D-C710796AFF41').
3033
required_nullable (Union[None, str]):
3134
required_not_nullable (str):
3235
one_of_models (Union['FreeFormModel', 'ModelWithUnionProperty', Any]):
@@ -37,6 +40,7 @@ class AModel:
3740
an_optional_allof_enum (Union[Unset, AnAllOfEnum]):
3841
nested_list_of_enums (Union[Unset, List[List[DifferentEnum]]]):
3942
a_not_required_date (Union[Unset, datetime.date]):
43+
a_not_required_uuid (Union[Unset, UUID]):
4044
attr_1_leading_digit (Union[Unset, str]):
4145
attr_leading_underscore (Union[Unset, str]):
4246
not_required_nullable (Union[None, Unset, str]):
@@ -51,17 +55,20 @@ class AModel:
5155
a_camel_date_time: Union[datetime.date, datetime.datetime]
5256
a_date: datetime.date
5357
a_nullable_date: Union[None, datetime.date]
58+
a_uuid: UUID
5459
required_nullable: Union[None, str]
5560
required_not_nullable: str
5661
one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", Any]
5762
nullable_one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", None]
5863
model: "ModelWithUnionProperty"
5964
nullable_model: Union["ModelWithUnionProperty", None]
6065
an_allof_enum_with_overridden_default: AnAllOfEnum = AnAllOfEnum.OVERRIDDEN_DEFAULT
66+
a_nullable_uuid: Union[None, UUID] = UUID("07EF8B4D-AA09-4FFA-898D-C710796AFF41")
6167
any_value: Union[Unset, Any] = "default"
6268
an_optional_allof_enum: Union[Unset, AnAllOfEnum] = UNSET
6369
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
6470
a_not_required_date: Union[Unset, datetime.date] = UNSET
71+
a_not_required_uuid: Union[Unset, UUID] = UNSET
6572
attr_1_leading_digit: Union[Unset, str] = UNSET
6673
attr_leading_underscore: Union[Unset, str] = UNSET
6774
not_required_nullable: Union[None, Unset, str] = UNSET
@@ -93,6 +100,14 @@ def to_dict(self) -> Dict[str, Any]:
93100
else:
94101
a_nullable_date = self.a_nullable_date
95102

103+
a_uuid = str(self.a_uuid)
104+
105+
a_nullable_uuid: Union[None, str]
106+
if isinstance(self.a_nullable_uuid, UUID):
107+
a_nullable_uuid = str(self.a_nullable_uuid)
108+
else:
109+
a_nullable_uuid = self.a_nullable_uuid
110+
96111
required_nullable: Union[None, str]
97112
required_nullable = self.required_nullable
98113

@@ -143,6 +158,10 @@ def to_dict(self) -> Dict[str, Any]:
143158
if not isinstance(self.a_not_required_date, Unset):
144159
a_not_required_date = self.a_not_required_date.isoformat()
145160

161+
a_not_required_uuid: Union[Unset, str] = UNSET
162+
if not isinstance(self.a_not_required_uuid, Unset):
163+
a_not_required_uuid = str(self.a_not_required_uuid)
164+
146165
attr_1_leading_digit = self.attr_1_leading_digit
147166

148167
attr_leading_underscore = self.attr_leading_underscore
@@ -194,6 +213,8 @@ def to_dict(self) -> Dict[str, Any]:
194213
"aCamelDateTime": a_camel_date_time,
195214
"a_date": a_date,
196215
"a_nullable_date": a_nullable_date,
216+
"a_uuid": a_uuid,
217+
"a_nullable_uuid": a_nullable_uuid,
197218
"required_nullable": required_nullable,
198219
"required_not_nullable": required_not_nullable,
199220
"one_of_models": one_of_models,
@@ -210,6 +231,8 @@ def to_dict(self) -> Dict[str, Any]:
210231
field_dict["nested_list_of_enums"] = nested_list_of_enums
211232
if a_not_required_date is not UNSET:
212233
field_dict["a_not_required_date"] = a_not_required_date
234+
if a_not_required_uuid is not UNSET:
235+
field_dict["a_not_required_uuid"] = a_not_required_uuid
213236
if attr_1_leading_digit is not UNSET:
214237
field_dict["1_leading_digit"] = attr_1_leading_digit
215238
if attr_leading_underscore is not UNSET:
@@ -273,6 +296,23 @@ def _parse_a_nullable_date(data: object) -> Union[None, datetime.date]:
273296

274297
a_nullable_date = _parse_a_nullable_date(d.pop("a_nullable_date"))
275298

299+
a_uuid = UUID(d.pop("a_uuid"))
300+
301+
def _parse_a_nullable_uuid(data: object) -> Union[None, UUID]:
302+
if data is None:
303+
return data
304+
try:
305+
if not isinstance(data, str):
306+
raise TypeError()
307+
a_nullable_uuid_type_0 = UUID(data)
308+
309+
return a_nullable_uuid_type_0
310+
except: # noqa: E722
311+
pass
312+
return cast(Union[None, UUID], data)
313+
314+
a_nullable_uuid = _parse_a_nullable_uuid(d.pop("a_nullable_uuid"))
315+
276316
def _parse_required_nullable(data: object) -> Union[None, str]:
277317
if data is None:
278318
return data
@@ -371,6 +411,13 @@ def _parse_nullable_model(data: object) -> Union["ModelWithUnionProperty", None]
371411
else:
372412
a_not_required_date = isoparse(_a_not_required_date).date()
373413

414+
_a_not_required_uuid = d.pop("a_not_required_uuid", UNSET)
415+
a_not_required_uuid: Union[Unset, UUID]
416+
if isinstance(_a_not_required_uuid, Unset):
417+
a_not_required_uuid = UNSET
418+
else:
419+
a_not_required_uuid = UUID(_a_not_required_uuid)
420+
374421
attr_1_leading_digit = d.pop("1_leading_digit", UNSET)
375422

376423
attr_leading_underscore = d.pop("_leading_underscore", UNSET)
@@ -464,6 +511,8 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro
464511
a_camel_date_time=a_camel_date_time,
465512
a_date=a_date,
466513
a_nullable_date=a_nullable_date,
514+
a_uuid=a_uuid,
515+
a_nullable_uuid=a_nullable_uuid,
467516
required_nullable=required_nullable,
468517
required_not_nullable=required_not_nullable,
469518
one_of_models=one_of_models,
@@ -474,6 +523,7 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro
474523
an_optional_allof_enum=an_optional_allof_enum,
475524
nested_list_of_enums=nested_list_of_enums,
476525
a_not_required_date=a_not_required_date,
526+
a_not_required_uuid=a_not_required_uuid,
477527
attr_1_leading_digit=attr_1_leading_digit,
478528
attr_leading_underscore=attr_leading_underscore,
479529
not_required_nullable=not_required_nullable,

0 commit comments

Comments
 (0)