diff --git a/modules/openapi-generator/src/main/resources/dart2/enum.mustache b/modules/openapi-generator/src/main/resources/dart2/enum.mustache index bdd82a161437..cfda923660f9 100644 --- a/modules/openapi-generator/src/main/resources/dart2/enum.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/enum.mustache @@ -12,7 +12,15 @@ class {{classname}} { static const {{classname}} {{{name}}} = {{classname}}._internal({{value}}); {{/enumVars}} {{/allowableValues}} - + + static List<{{classname}}> get values => const [ + {{#allowableValues}} + {{#enumVars}} + {{{name}}}, + {{/enumVars}} + {{/allowableValues}} + ]; + {{dataType}} toJson () { return value; } @@ -25,7 +33,7 @@ class {{classname}} { static {{classname}} fromJson({{dataType}} value) { return {{classname}}TypeTransformer().decode(value); } - + static List<{{classname}}> listFromJson(List json) { return json == null ? List<{{classname}}>() diff --git a/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache b/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache index 5ecc2b1a6ac5..dc334dface51 100644 --- a/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache @@ -13,6 +13,14 @@ class {{classname}}{{enumName}} { {{/enumVars}} {{/allowableValues}} + static List<{{classname}}{{enumName}}> get values => const [ + {{#allowableValues}} + {{#enumVars}} + {{{name}}}, + {{/enumVars}} + {{/allowableValues}} + ]; + {{{dataType}}} toJson () { return value; } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart index 821b59586aa1..a5edbe07bc39 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart @@ -93,6 +93,12 @@ class OrderStatusEnum { /// Order Status static const OrderStatusEnum delivered_ = OrderStatusEnum._internal("delivered"); + static List get values => const [ + placed_, + approved_, + delivered_, + ]; + String toJson () { return value; } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart index 0999f9f638ec..b6ba84763567 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart @@ -97,6 +97,12 @@ class PetStatusEnum { /// pet status in the store static const PetStatusEnum sold_ = PetStatusEnum._internal("sold"); + static List get values => const [ + available_, + pending_, + sold_, + ]; + String toJson () { return value; }