Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage enum properly on Dart Jaguar generator #3654

Merged
merged 2 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CodecRepo> defaultConverters = {
MimeTypes.json: _jsonJaguarRepo,
Expand Down Expand Up @@ -97,4 +97,4 @@ class {{clientName}} {
}

{{/apis}}{{/apiInfo}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
part '{{classFilename}}.jser.dart';

@Entity()
{{#jsonFormat}}
class {{classname}} {
/// The underlying value of this enum member.
final {{dataType}} value;
Expand All @@ -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;
}
{{classname}} deserialize({{dataType}} data) {
switch (data) {
{{#allowableValues}}
{{#enumVars}}
case {{{value}}}: return {{classname}}.{{{name}}};
{{/enumVars}}
{{/allowableValues}}
default: throw('Unknown enum value to decode: $data');
}
}

@override
{{classname}} decode(dynamic 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}}
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> photoUrls;

@Alias('tags', isNullable: false)
@Alias('tags', isNullable: false, )
final List<Tag> 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, };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.2-SNAPSHOT
4.1.2-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
14 changes: 8 additions & 6 deletions samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
14 changes: 8 additions & 6 deletions samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> photoUrls;

@Alias('tags', isNullable: false)
@Alias('tags', isNullable: false, )
final List<Tag> tags;
/* pet status in the store */
@Alias('status', isNullable: false)
@Alias('status', isNullable: false,

)
final String status;
//enum statusEnum { available, pending, sold, };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down