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 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
2k
フォーク
293
平均マージ
34分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、issue にある混在した enum 値で要求された動作を再現し、現在ジェネレーターが無効な enum メンバーにどのような名前を付けているかを確認します。元の値を保持したまま enum_value_prefix または同等の命名をサポートし、数値文字列とアンダースコアで始まる文字列をカバーできれば完了とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
openapi, python
領域
backend-api-design
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。