openapi-generators / openapi-generators/openapi-python-client
feat: Add a enum_value_prefix similar to field_prefix and/or allow enum values that start with a bad chart to still be VALUE_$X
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 2k
- 派生
- 293
- 平均合并
- 34 分钟
- 30 天内合并 PR
- 1
描述
Describe the bug
INT enums
enum: [1,10,20]
map to VALUE_1, VALUE_10, VALUE_20 ....
but you can't have mixed str&int enums.
I have some enums in an openapi file that take both numbers and strings. ex: 1,20,noop
So the numbers need to be strings as well.
But since they start with an invalid char ([0-9]) they're renamed VALUE_1, VALUE_2, etc regardless of the int/string value
I think a similar thing happens to strings that start as _.
It's worse then passing in a string(especially since you can't pass in the string/value instead).
Its better to keep the string value after the prefix.
basically I'd like to be able to have
enum: ["200", "10", "_11", "_ABC", "noop"]
map to
class MyEnum(str, Enum):
VALUE_200 = "200"
VALUE_10 = "10"
VALUE_11 = "11"
VALUE_ABC= "ABC"
noop = "noop"
def __str__(self) -> str:
return str(self.value)
with
enum_value_prefix: V
class MyEnum(str, Enum):
V_200 = "200"
V_10 = "10"
V_11 = "11"
V_ABC= "ABC"
noop = "noop"
def __str__(self) -> str:
return str(self.value)
OpenAPI Spec File
Openapi doesn't have great support for custom enum naming.
I think this would work better in many cases anyway
https://stackoverflow.com/questions/66465888/how-to-define-enum-mapping-in-openapi
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用 issue 中混合的枚举值重现所请求的行为,并查看生成器当前如何命名无效的枚举成员。完成的定义是支持 enum_value_prefix 或等效的命名方式,同时保留原始值,并覆盖数值字符串和以下划线开头的字符串。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- openapi, python
- 领域
- backend-api-design
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100