Skip to content

Add tests for enum names with dots in python cilents #21374

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 4 commits into from
Jun 4, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,8 @@ public void setMapNumberTo(String mapNumberTo) {
}

public String toEnumVariableName(String name, String datatype) {
name = name.replace(".", "_DOT_");

if ("int".equals(datatype)) {
return "NUMBER_" + name.replace("-", "MINUS_");
}
Expand Down
33 changes: 0 additions & 33 deletions modules/openapi-generator/src/test/resources/3_0/enum_float.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2898,3 +2898,15 @@ components:
- B
- C
default: B
PonySizes:
type: object
properties:
type:
$ref: '#/components/schemas/Type'
Type:
type: float
enum:
- 2.0
- 1.0
- 0.5
- 0.25
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ docs/ParentWithOptionalDict.md
docs/Pet.md
docs/PetApi.md
docs/Pig.md
docs/PonySizes.md
docs/PoopCleaning.md
docs/PrimitiveString.md
docs/PropertyMap.md
Expand All @@ -113,6 +114,7 @@ docs/TestInlineFreeformAdditionalPropertiesRequest.md
docs/TestModelWithEnumDefault.md
docs/TestObjectForMultipartRequestsRequestMarker.md
docs/Tiger.md
docs/Type.md
docs/UnnamedDictWithAdditionalModelListProperties.md
docs/UnnamedDictWithAdditionalStringListProperties.md
docs/UploadFileWithAdditionalPropertiesRequestObject.md
Expand Down Expand Up @@ -215,6 +217,7 @@ petstore_api/models/parent.py
petstore_api/models/parent_with_optional_dict.py
petstore_api/models/pet.py
petstore_api/models/pig.py
petstore_api/models/pony_sizes.py
petstore_api/models/poop_cleaning.py
petstore_api/models/primitive_string.py
petstore_api/models/property_map.py
Expand All @@ -238,6 +241,7 @@ petstore_api/models/test_inline_freeform_additional_properties_request.py
petstore_api/models/test_model_with_enum_default.py
petstore_api/models/test_object_for_multipart_requests_request_marker.py
petstore_api/models/tiger.py
petstore_api/models/type.py
petstore_api/models/unnamed_dict_with_additional_model_list_properties.py
petstore_api/models/unnamed_dict_with_additional_string_list_properties.py
petstore_api/models/upload_file_with_additional_properties_request_object.py
Expand Down
2 changes: 2 additions & 0 deletions samples/openapi3/client/petstore/python-aiohttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ Class | Method | HTTP request | Description
- [ParentWithOptionalDict](docs/ParentWithOptionalDict.md)
- [Pet](docs/Pet.md)
- [Pig](docs/Pig.md)
- [PonySizes](docs/PonySizes.md)
- [PoopCleaning](docs/PoopCleaning.md)
- [PrimitiveString](docs/PrimitiveString.md)
- [PropertyMap](docs/PropertyMap.md)
Expand All @@ -254,6 +255,7 @@ Class | Method | HTTP request | Description
- [TestModelWithEnumDefault](docs/TestModelWithEnumDefault.md)
- [TestObjectForMultipartRequestsRequestMarker](docs/TestObjectForMultipartRequestsRequestMarker.md)
- [Tiger](docs/Tiger.md)
- [Type](docs/Type.md)
- [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md)
- [UnnamedDictWithAdditionalStringListProperties](docs/UnnamedDictWithAdditionalStringListProperties.md)
- [UploadFileWithAdditionalPropertiesRequestObject](docs/UploadFileWithAdditionalPropertiesRequestObject.md)
Expand Down
29 changes: 29 additions & 0 deletions samples/openapi3/client/petstore/python-aiohttp/docs/PonySizes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# PonySizes


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**type** | [**Type**](Type.md) | | [optional]

## Example

```python
from petstore_api.models.pony_sizes import PonySizes

# TODO update the JSON string below
json = "{}"
# create an instance of PonySizes from a JSON string
pony_sizes_instance = PonySizes.from_json(json)
# print the JSON string representation of the object
print(PonySizes.to_json())

# convert the object into a dict
pony_sizes_dict = pony_sizes_instance.to_dict()
# create an instance of PonySizes from a dict
pony_sizes_from_dict = PonySizes.from_dict(pony_sizes_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


16 changes: 16 additions & 0 deletions samples/openapi3/client/petstore/python-aiohttp/docs/Type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Type


## Enum

* `NUMBER_2_DOT_0` (value: `2.0`)

* `NUMBER_1_DOT_0` (value: `1.0`)

* `NUMBER_0_DOT_5` (value: `0.5`)

* `NUMBER_0_DOT_25` (value: `0.25`)

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"ParentWithOptionalDict",
"Pet",
"Pig",
"PonySizes",
"PoopCleaning",
"PrimitiveString",
"PropertyMap",
Expand All @@ -139,6 +140,7 @@
"TestModelWithEnumDefault",
"TestObjectForMultipartRequestsRequestMarker",
"Tiger",
"Type",
"UnnamedDictWithAdditionalModelListProperties",
"UnnamedDictWithAdditionalStringListProperties",
"UploadFileWithAdditionalPropertiesRequestObject",
Expand Down Expand Up @@ -249,6 +251,7 @@
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict as ParentWithOptionalDict
from petstore_api.models.pet import Pet as Pet
from petstore_api.models.pig import Pig as Pig
from petstore_api.models.pony_sizes import PonySizes as PonySizes
from petstore_api.models.poop_cleaning import PoopCleaning as PoopCleaning
from petstore_api.models.primitive_string import PrimitiveString as PrimitiveString
from petstore_api.models.property_map import PropertyMap as PropertyMap
Expand All @@ -272,6 +275,7 @@
from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDefault as TestModelWithEnumDefault
from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker as TestObjectForMultipartRequestsRequestMarker
from petstore_api.models.tiger import Tiger as Tiger
from petstore_api.models.type import Type as Type
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties as UnnamedDictWithAdditionalModelListProperties
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties as UnnamedDictWithAdditionalStringListProperties
from petstore_api.models.upload_file_with_additional_properties_request_object import UploadFileWithAdditionalPropertiesRequestObject as UploadFileWithAdditionalPropertiesRequestObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
from petstore_api.models.pet import Pet
from petstore_api.models.pig import Pig
from petstore_api.models.pony_sizes import PonySizes
from petstore_api.models.poop_cleaning import PoopCleaning
from petstore_api.models.primitive_string import PrimitiveString
from petstore_api.models.property_map import PropertyMap
Expand All @@ -117,6 +118,7 @@
from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDefault
from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker
from petstore_api.models.tiger import Tiger
from petstore_api.models.type import Type
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties
from petstore_api.models.upload_file_with_additional_properties_request_object import UploadFileWithAdditionalPropertiesRequestObject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# coding: utf-8

"""
OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501


from __future__ import annotations
import pprint
import re # noqa: F401
import json

from pydantic import BaseModel, ConfigDict
from typing import Any, ClassVar, Dict, List, Optional
from petstore_api.models.type import Type
from typing import Optional, Set
from typing_extensions import Self

class PonySizes(BaseModel):
"""
PonySizes
""" # noqa: E501
type: Optional[Type] = None
__properties: ClassVar[List[str]] = ["type"]

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)


def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of PonySizes from a JSON string"""
return cls.from_dict(json.loads(json_str))

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.

This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:

* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])

_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of PonySizes from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate({
"type": obj.get("type")
})
return _obj


Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding: utf-8

"""
OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501


from __future__ import annotations
import json
from enum import Enum
from typing_extensions import Self


class Type(int, Enum):
"""
Type
"""

"""
allowed enum values
"""
NUMBER_2_DOT_0 = 2.0
NUMBER_1_DOT_0 = 1.0
NUMBER_0_DOT_5 = 0.5
NUMBER_0_DOT_25 = 0.25

@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Type from a JSON string"""
return cls(json.loads(json_str))


Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# coding: utf-8

"""
OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501


import unittest

from petstore_api.models.pony_sizes import PonySizes

class TestPonySizes(unittest.TestCase):
"""PonySizes unit test stubs"""

def setUp(self):
pass

def tearDown(self):
pass

def make_instance(self, include_optional) -> PonySizes:
"""Test PonySizes
include_optional is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `PonySizes`
"""
model = PonySizes()
if include_optional:
return PonySizes(
type = 2.0
)
else:
return PonySizes(
)
"""

def testPonySizes(self):
"""Test PonySizes"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)

if __name__ == '__main__':
unittest.main()
Loading
Loading