Skip to content

feat: Add UUID string format. Thanks @estyrke! #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 20, 2024
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
19 changes: 19 additions & 0 deletions end_to_end_tests/__snapshots__/test_end_to_end.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
Circular $ref in request body


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

'''
# ---
# name: test_documents_with_errors[invalid-uuid-defaults]
'''
Generating /test-documents-with-errors
Warning(s) encountered while generating. Client was generated, but some pieces may be missing

WARNING parsing PUT / within default. Endpoint will not be generated.

cannot parse parameter of endpoint put_: Invalid UUID value: 3


WARNING parsing POST / within default. Endpoint will not be generated.

cannot parse parameter of endpoint post_: Invalid UUID value: notauuid


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

'''
Expand Down
19 changes: 19 additions & 0 deletions end_to_end_tests/baseline_openapi_3.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,8 @@
"aCamelDateTime",
"a_date",
"a_nullable_date",
"a_uuid",
"a_nullable_uuid",
"required_nullable",
"required_not_nullable",
"model",
Expand Down Expand Up @@ -1784,6 +1786,23 @@
"type": "string",
"format": "date"
},
"a_uuid": {
"title": "A Uuid",
"type": "string",
"format": "uuid"
},
"a_nullable_uuid": {
"title": "A Nullable Uuid",
"type": "string",
"format": "uuid",
"nullable": true,
"default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41"
},
"a_not_required_uuid": {
"title": "A Not Required Uuid",
"type": "string",
"format": "uuid"
},
"1_leading_digit": {
"title": "Leading Digit",
"type": "string"
Expand Down
25 changes: 25 additions & 0 deletions end_to_end_tests/baseline_openapi_3.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,8 @@ info:
"aCamelDateTime",
"a_date",
"a_nullable_date",
"a_uuid",
"a_nullable_uuid",
"required_nullable",
"required_not_nullable",
"model",
Expand Down Expand Up @@ -1771,6 +1773,29 @@ info:
"type": "string",
"format": "date"
},
"a_uuid": {
"title": "A Uuid",
"type": "string",
"format": "uuid"
},
"a_nullable_uuid": {
"title": "A Nullable Uuid",
"anyOf": [
{
"type": "string",
"format": "uuid",
},
{
"type": "null"
}
],
"default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41"
},
"a_not_required_uuid": {
"title": "A Not Required Uuid",
"type": "string",
"format": "uuid"
},
"1_leading_digit": {
"title": "Leading Digit",
"type": "string"
Expand Down
30 changes: 30 additions & 0 deletions end_to_end_tests/documents_with_errors/invalid-uuid-defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: "3.1.0"
info:
title: "Circular Body Ref"
version: "0.1.0"
paths:
/:
post:
parameters:
- name: id
in: query
required: false
schema:
type: string
format: uuid
default: "notauuid"
responses:
"200":
description: "Successful Response"
put:
parameters:
- name: another_id
in: query
required: false
schema:
type: string
format: uuid
default: 3
responses:
"200":
description: "Successful Response"
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast
from uuid import UUID

from attrs import define as _attrs_define
from dateutil.parser import isoparse
Expand Down Expand Up @@ -27,6 +28,8 @@ class AModel:
a_camel_date_time (Union[datetime.date, datetime.datetime]):
a_date (datetime.date):
a_nullable_date (Union[None, datetime.date]):
a_uuid (UUID):
a_nullable_uuid (Union[None, UUID]): Default: UUID('07EF8B4D-AA09-4FFA-898D-C710796AFF41').
required_nullable (Union[None, str]):
required_not_nullable (str):
one_of_models (Union['FreeFormModel', 'ModelWithUnionProperty', Any]):
Expand All @@ -37,6 +40,7 @@ class AModel:
an_optional_allof_enum (Union[Unset, AnAllOfEnum]):
nested_list_of_enums (Union[Unset, List[List[DifferentEnum]]]):
a_not_required_date (Union[Unset, datetime.date]):
a_not_required_uuid (Union[Unset, UUID]):
attr_1_leading_digit (Union[Unset, str]):
attr_leading_underscore (Union[Unset, str]):
not_required_nullable (Union[None, Unset, str]):
Expand All @@ -51,17 +55,20 @@ class AModel:
a_camel_date_time: Union[datetime.date, datetime.datetime]
a_date: datetime.date
a_nullable_date: Union[None, datetime.date]
a_uuid: UUID
required_nullable: Union[None, str]
required_not_nullable: str
one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", Any]
nullable_one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", None]
model: "ModelWithUnionProperty"
nullable_model: Union["ModelWithUnionProperty", None]
an_allof_enum_with_overridden_default: AnAllOfEnum = AnAllOfEnum.OVERRIDDEN_DEFAULT
a_nullable_uuid: Union[None, UUID] = UUID("07EF8B4D-AA09-4FFA-898D-C710796AFF41")
any_value: Union[Unset, Any] = "default"
an_optional_allof_enum: Union[Unset, AnAllOfEnum] = UNSET
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
a_not_required_date: Union[Unset, datetime.date] = UNSET
a_not_required_uuid: Union[Unset, UUID] = UNSET
attr_1_leading_digit: Union[Unset, str] = UNSET
attr_leading_underscore: Union[Unset, str] = UNSET
not_required_nullable: Union[None, Unset, str] = UNSET
Expand Down Expand Up @@ -93,6 +100,14 @@ def to_dict(self) -> Dict[str, Any]:
else:
a_nullable_date = self.a_nullable_date

a_uuid = str(self.a_uuid)

a_nullable_uuid: Union[None, str]
if isinstance(self.a_nullable_uuid, UUID):
a_nullable_uuid = str(self.a_nullable_uuid)
else:
a_nullable_uuid = self.a_nullable_uuid

required_nullable: Union[None, str]
required_nullable = self.required_nullable

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

a_not_required_uuid: Union[Unset, str] = UNSET
if not isinstance(self.a_not_required_uuid, Unset):
a_not_required_uuid = str(self.a_not_required_uuid)

attr_1_leading_digit = self.attr_1_leading_digit

attr_leading_underscore = self.attr_leading_underscore
Expand Down Expand Up @@ -193,6 +212,8 @@ def to_dict(self) -> Dict[str, Any]:
"aCamelDateTime": a_camel_date_time,
"a_date": a_date,
"a_nullable_date": a_nullable_date,
"a_uuid": a_uuid,
"a_nullable_uuid": a_nullable_uuid,
"required_nullable": required_nullable,
"required_not_nullable": required_not_nullable,
"one_of_models": one_of_models,
Expand All @@ -209,6 +230,8 @@ def to_dict(self) -> Dict[str, Any]:
field_dict["nested_list_of_enums"] = nested_list_of_enums
if a_not_required_date is not UNSET:
field_dict["a_not_required_date"] = a_not_required_date
if a_not_required_uuid is not UNSET:
field_dict["a_not_required_uuid"] = a_not_required_uuid
if attr_1_leading_digit is not UNSET:
field_dict["1_leading_digit"] = attr_1_leading_digit
if attr_leading_underscore is not UNSET:
Expand Down Expand Up @@ -272,6 +295,23 @@ def _parse_a_nullable_date(data: object) -> Union[None, datetime.date]:

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

a_uuid = UUID(d.pop("a_uuid"))

def _parse_a_nullable_uuid(data: object) -> Union[None, UUID]:
if data is None:
return data
try:
if not isinstance(data, str):
raise TypeError()
a_nullable_uuid_type_0 = UUID(data)

return a_nullable_uuid_type_0
except: # noqa: E722
pass
return cast(Union[None, UUID], data)

a_nullable_uuid = _parse_a_nullable_uuid(d.pop("a_nullable_uuid"))

def _parse_required_nullable(data: object) -> Union[None, str]:
if data is None:
return data
Expand Down Expand Up @@ -370,6 +410,13 @@ def _parse_nullable_model(data: object) -> Union["ModelWithUnionProperty", None]
else:
a_not_required_date = isoparse(_a_not_required_date).date()

_a_not_required_uuid = d.pop("a_not_required_uuid", UNSET)
a_not_required_uuid: Union[Unset, UUID]
if isinstance(_a_not_required_uuid, Unset):
a_not_required_uuid = UNSET
else:
a_not_required_uuid = UUID(_a_not_required_uuid)

attr_1_leading_digit = d.pop("1_leading_digit", UNSET)

attr_leading_underscore = d.pop("_leading_underscore", UNSET)
Expand Down Expand Up @@ -463,6 +510,8 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro
a_camel_date_time=a_camel_date_time,
a_date=a_date,
a_nullable_date=a_nullable_date,
a_uuid=a_uuid,
a_nullable_uuid=a_nullable_uuid,
required_nullable=required_nullable,
required_not_nullable=required_not_nullable,
one_of_models=one_of_models,
Expand All @@ -473,6 +522,7 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro
an_optional_allof_enum=an_optional_allof_enum,
nested_list_of_enums=nested_list_of_enums,
a_not_required_date=a_not_required_date,
a_not_required_uuid=a_not_required_uuid,
attr_1_leading_digit=attr_1_leading_digit,
attr_leading_underscore=attr_leading_underscore,
not_required_nullable=not_required_nullable,
Expand Down
Loading
Loading