diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache index 1fd657ea1df..3e8055b608f 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache @@ -19,7 +19,7 @@ import 'package:jaguar_mimetype/jaguar_mimetype.dart'; {{#jsonFormat}} final _jsonJaguarRepo = JsonRepo() -{{#models}}{{#model}}..add({{classname}}Serializer()) +{{#models}}{{#model}}{{^isEnum}}..add({{classname}}Serializer()){{/isEnum}} {{/model}}{{/models}}; final Map defaultConverters = { MimeTypes.json: _jsonJaguarRepo, @@ -97,4 +97,4 @@ class {{clientName}} { } {{/apis}}{{/apiInfo}} -} \ No newline at end of file +} diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache index de899850177..0ee26193bba 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache @@ -10,7 +10,12 @@ part '{{classFilename}}.jser.dart'; class {{classname}} { {{#vars}}{{#description}} /* {{{description}}} */{{/description}} - @Alias('{{{baseName}}}', isNullable:{{#isNullable}} true{{/isNullable}}{{^isNullable}} false{{/isNullable}}) + @Alias('{{{baseName}}}', isNullable:{{#isNullable}} true{{/isNullable}}{{^isNullable}} false{{/isNullable}},{{#allowableValues}} + {{^enumVars.empty}}{{^isString}}{{! isString because inline enums are not handled for now }} + processor: const {{{datatype}}}FieldProcessor(), + {{/isString}}{{/enumVars.empty}} + {{/allowableValues}} + ) final {{{datatype}}} {{name}}; {{#allowableValues}}{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{{/allowableValues}}{{/vars}} diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/enum.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/enum.mustache index 0698e149412..ef2c35e2c2a 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/enum.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/enum.mustache @@ -1,6 +1,5 @@ -part '{{classFilename}}.jser.dart'; -@Entity() +{{#jsonFormat}} class {{classname}} { /// The underlying value of this enum member. final {{dataType}} value; @@ -12,27 +11,27 @@ class {{classname}} { {{#description}} /// {{description}} {{/description}} - static const {{classname}} {{{name}}}} = const {{classname}}._internal({{{value}}}); + static const {{classname}} {{{name}}} = const {{classname}}._internal({{{value}}}); {{/enumVars}} {{/allowableValues}} } -class {{classname}}TypeTransformer extends TypeTransformer<{{classname}}> { +class {{classname}}FieldProcessor implements FieldProcessor<{{classname}}, {{dataType}}> { + const {{classname}}FieldProcessor(); - @override - dynamic encode({{classname}} data) { - return data.value; - } - - @override - {{classname}} decode(dynamic data) { - switch (data) { - {{#allowableValues}} - {{#enumVars}} - case {{{value}}}: return {{classname}}.{{{name}}}}; - {{/enumVars}} - {{/allowableValues}} - default: throw('Unknown enum value to decode: $data'); + {{classname}} deserialize({{dataType}} data) { + switch (data) { + {{#allowableValues}} + {{#enumVars}} + case {{{value}}}: return {{classname}}.{{{name}}}; + {{/enumVars}} + {{/allowableValues}} + default: throw('Unknown enum value to decode: $data'); + } + } + + {{dataType}} serialize({{classname}} item) { + return item.value; } - } } +{{/jsonFormat}} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart index 9c95a72bc65..7282e058587 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart @@ -5,13 +5,13 @@ part 'api_response.jser.dart'; class ApiResponse { - @Alias('code', isNullable: false) + @Alias('code', isNullable: false, ) final int code; - @Alias('type', isNullable: false) + @Alias('type', isNullable: false, ) final String type; - @Alias('message', isNullable: false) + @Alias('message', isNullable: false, ) final String message; diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart index 2b4b2d27308..8a48730d0d2 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart @@ -5,10 +5,10 @@ part 'category.jser.dart'; class Category { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('name', isNullable: false) + @Alias('name', isNullable: false, ) final String name; diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart index c4fc5175f70..1d10a3e896d 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart @@ -5,22 +5,24 @@ part 'order.jser.dart'; class Order { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('petId', isNullable: false) + @Alias('petId', isNullable: false, ) final int petId; - @Alias('quantity', isNullable: false) + @Alias('quantity', isNullable: false, ) final int quantity; - @Alias('shipDate', isNullable: false) + @Alias('shipDate', isNullable: false, ) final DateTime shipDate; /* Order Status */ - @Alias('status', isNullable: false) + @Alias('status', isNullable: false, + processor: const StringFieldProcessor(), + ) final String status; //enum statusEnum { placed, approved, delivered, }; - @Alias('complete', isNullable: false) + @Alias('complete', isNullable: false, ) final bool complete; diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart index a9eb6c6b332..2ec8ba6aab3 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart @@ -9,22 +9,24 @@ part 'pet.jser.dart'; class Pet { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('category', isNullable: false) + @Alias('category', isNullable: false, ) final Category category; - @Alias('name', isNullable: false) + @Alias('name', isNullable: false, ) final String name; - @Alias('photoUrls', isNullable: false) + @Alias('photoUrls', isNullable: false, ) final List photoUrls; - @Alias('tags', isNullable: false) + @Alias('tags', isNullable: false, ) final List tags; /* pet status in the store */ - @Alias('status', isNullable: false) + @Alias('status', isNullable: false, + processor: const StringFieldProcessor(), + ) final String status; //enum statusEnum { available, pending, sold, }; diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart index 5fea9c025ec..15416bfca16 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart @@ -5,10 +5,10 @@ part 'tag.jser.dart'; class Tag { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('name', isNullable: false) + @Alias('name', isNullable: false, ) final String name; diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart index abfbd56c88f..4973bfafb2e 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart @@ -5,28 +5,28 @@ part 'user.jser.dart'; class User { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('username', isNullable: false) + @Alias('username', isNullable: false, ) final String username; - @Alias('firstName', isNullable: false) + @Alias('firstName', isNullable: false, ) final String firstName; - @Alias('lastName', isNullable: false) + @Alias('lastName', isNullable: false, ) final String lastName; - @Alias('email', isNullable: false) + @Alias('email', isNullable: false, ) final String email; - @Alias('password', isNullable: false) + @Alias('password', isNullable: false, ) final String password; - @Alias('phone', isNullable: false) + @Alias('phone', isNullable: false, ) final String phone; /* User Status */ - @Alias('userStatus', isNullable: false) + @Alias('userStatus', isNullable: false, ) final int userStatus; diff --git a/samples/client/petstore/dart-jaguar/openapi/.openapi-generator/VERSION b/samples/client/petstore/dart-jaguar/openapi/.openapi-generator/VERSION index d1a8f58b388..8acd11d8b92 100644 --- a/samples/client/petstore/dart-jaguar/openapi/.openapi-generator/VERSION +++ b/samples/client/petstore/dart-jaguar/openapi/.openapi-generator/VERSION @@ -1 +1 @@ -4.1.2-SNAPSHOT \ No newline at end of file +4.1.2-SNAPSHOT diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart index 9c95a72bc65..7282e058587 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart @@ -5,13 +5,13 @@ part 'api_response.jser.dart'; class ApiResponse { - @Alias('code', isNullable: false) + @Alias('code', isNullable: false, ) final int code; - @Alias('type', isNullable: false) + @Alias('type', isNullable: false, ) final String type; - @Alias('message', isNullable: false) + @Alias('message', isNullable: false, ) final String message; diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart index 2b4b2d27308..8a48730d0d2 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart @@ -5,10 +5,10 @@ part 'category.jser.dart'; class Category { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('name', isNullable: false) + @Alias('name', isNullable: false, ) final String name; diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart index c4fc5175f70..b0d18aea5f0 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart @@ -5,22 +5,24 @@ part 'order.jser.dart'; class Order { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('petId', isNullable: false) + @Alias('petId', isNullable: false, ) final int petId; - @Alias('quantity', isNullable: false) + @Alias('quantity', isNullable: false, ) final int quantity; - @Alias('shipDate', isNullable: false) + @Alias('shipDate', isNullable: false, ) final DateTime shipDate; /* Order Status */ - @Alias('status', isNullable: false) + @Alias('status', isNullable: false, + + ) final String status; //enum statusEnum { placed, approved, delivered, }; - @Alias('complete', isNullable: false) + @Alias('complete', isNullable: false, ) final bool complete; diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart index a9eb6c6b332..ea1be521e2d 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart @@ -9,22 +9,24 @@ part 'pet.jser.dart'; class Pet { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('category', isNullable: false) + @Alias('category', isNullable: false, ) final Category category; - @Alias('name', isNullable: false) + @Alias('name', isNullable: false, ) final String name; - @Alias('photoUrls', isNullable: false) + @Alias('photoUrls', isNullable: false, ) final List photoUrls; - @Alias('tags', isNullable: false) + @Alias('tags', isNullable: false, ) final List tags; /* pet status in the store */ - @Alias('status', isNullable: false) + @Alias('status', isNullable: false, + + ) final String status; //enum statusEnum { available, pending, sold, }; diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart index 5fea9c025ec..15416bfca16 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart @@ -5,10 +5,10 @@ part 'tag.jser.dart'; class Tag { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('name', isNullable: false) + @Alias('name', isNullable: false, ) final String name; diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart index abfbd56c88f..4973bfafb2e 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart @@ -5,28 +5,28 @@ part 'user.jser.dart'; class User { - @Alias('id', isNullable: false) + @Alias('id', isNullable: false, ) final int id; - @Alias('username', isNullable: false) + @Alias('username', isNullable: false, ) final String username; - @Alias('firstName', isNullable: false) + @Alias('firstName', isNullable: false, ) final String firstName; - @Alias('lastName', isNullable: false) + @Alias('lastName', isNullable: false, ) final String lastName; - @Alias('email', isNullable: false) + @Alias('email', isNullable: false, ) final String email; - @Alias('password', isNullable: false) + @Alias('password', isNullable: false, ) final String password; - @Alias('phone', isNullable: false) + @Alias('phone', isNullable: false, ) final String phone; /* User Status */ - @Alias('userStatus', isNullable: false) + @Alias('userStatus', isNullable: false, ) final int userStatus;