FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add support for x-enum-varnames to string enums by mbbush · Pull Request #1358 · openapi-generators/openapi-python-client · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
default: minor
---

# Add support for x-enum-varnames to string enums

#1358 by @mbbush

You can now customize the variable names of the generated string enumerations using the x-enum-varnames openapi extension. Previously, this was only possible for integer enumerations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,35 @@ def test_invalid_values(self, MyModel):
MyModel.from_dict({"enumProp": 2})


@with_generated_client_fixture(
"""
components:
schemas:
MyStrEnum:
type: string
enum: ["a", "b", "c"]
x-enum-varnames: [
"One",
"More than OnE",
"not_quite_four"
]
""")
@with_generated_code_imports(
".models.MyStrEnum",
)
class TestStrEnumVarNameExtensions:
@pytest.mark.parametrize(
"expected_name,expected_value",
[
("ONE", "a"),
("MORE_THAN_ON_E", "b"),
("NOT_QUITE_FOUR", "c"),
],
)
def test_enum_values(self, MyStrEnum, expected_name, expected_value):
assert getattr(MyStrEnum, expected_name) == MyStrEnum(expected_value)


@with_generated_client_fixture(
"""
components:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def values_from_list(
else:
output[f"VALUE_{value}"] = value
continue
if value and value[0].isalpha():
if use_var_names:
key = var_names[i]
elif value and value[0].isalpha():
key = value.upper()
else:
key = f"VALUE_{i}"
Expand Down

Back | FazBrowse Home | New Git URL