File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ type Config struct {
7
7
Package string `json:"package"`
8
8
Out string `json:"out"`
9
9
EmitPydanticModels bool `json:"emit_pydantic_models"`
10
+ EmitStrEnum bool `json:"emit_str_enum"`
10
11
QueryParameterLimit * int32 `json:"query_parameter_limit"`
11
12
InflectionExcludeTableNames []string `json:"inflection_exclude_table_names"`
12
13
}
Original file line number Diff line number Diff line change @@ -681,12 +681,19 @@ func buildModelsTree(ctx *pyTmplCtx, i *importer) *pyast.Node {
681
681
mod .Body = append (mod .Body , buildImportGroup (std ), buildImportGroup (pkg ))
682
682
683
683
for _ , e := range ctx .Enums {
684
+ bases := []* pyast.Node {
685
+ poet .Name ("str" ),
686
+ poet .Attribute (poet .Name ("enum" ), "Enum" ),
687
+ }
688
+ if i .C .EmitStrEnum {
689
+ // override the bases to emit enum.StrEnum (only support in Python >=3.11)
690
+ bases = []* pyast.Node {
691
+ poet .Attribute (poet .Name ("enum" ), "StrEnum" ),
692
+ }
693
+ }
684
694
def := & pyast.ClassDef {
685
- Name : e .Name ,
686
- Bases : []* pyast.Node {
687
- poet .Name ("str" ),
688
- poet .Attribute (poet .Name ("enum" ), "Enum" ),
689
- },
695
+ Name : e .Name ,
696
+ Bases : bases ,
690
697
}
691
698
if e .Comment != "" {
692
699
def .Body = append (def .Body , & pyast.Node {
You can’t perform that action at this time.
0 commit comments