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

未關閉
#1,043 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先使用 issue 中混合的列舉值重現所要求的行為,並檢視產生器目前如何命名無效的列舉成員。完成的定義是支援 enum_value_prefix 或等效的命名方式,同時保留原始值,並涵蓋數值字串及以下底線開頭的字串。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
openapi, python
領域
backend-api-design
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。