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

Aperta
#1,043 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
2k
Fork
293
Merge medio
34m
PR unite (30g)
1

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il comportamento richiesto con i valori di enum misti dell’issue e verifica come il generatore denomina attualmente i membri di enum non validi. Considera il lavoro completato quando viene supportato enum_value_prefix o una denominazione equivalente, preservando i valori originali e includendo la copertura per le stringhe numeriche e quelle precedute da un underscore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
openapi, python
Ambito
backend-api-design
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.