Skip to content
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 @@ -539,12 +539,18 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
// are prefix with the classname of the containing class in the template.
// Here the datatypeWithEnum template variable gets updated to match that scheme.
// Also taking into account potential collection types e.g. List<JustSymbolEnum> -> List<EnumArraysJustSymbolEnum>
final String enumName = model.classname + property.enumName;
if (property.items != null) {
// basically inner items e.g. map of maps etc.
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.items.datatypeWithEnum, model.classname + property.items.datatypeWithEnum));
// inner items e.g. enums in collections, only works for one level
// but same is the case for DefaultCodegen
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.items.datatypeWithEnum, enumName));
property.items.setDatatypeWithEnum(enumName);
property.items.setEnumName(enumName);
} else {
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.enumName, model.classname + property.enumName));
// plain enum property
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.enumName, enumName));
}
property.setEnumName(enumName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builde
{{classname}}._();

static void _initializeBuilder({{{classname}}}Builder b) => b{{#vars}}{{#defaultValue}}
..{{{name}}} = {{#isEnum}}{{^isContainer}}const {{{classname}}}{{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vars}};
..{{{name}}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vars}};

factory {{classname}}([void updates({{classname}}Builder b)]) = _${{classname}};
static Serializer<{{classname}}> get serializer => _${{#lambda.camelcase}}{{{classname}}}{{/lambda.camelcase}}Serializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class {{{classname}}}{{{enumName}}} extends EnumClass {
class {{{enumName}}} extends EnumClass {

{{#allowableValues}}
{{#enumVars}}
{{#description}}
/// {{{description}}}
{{/description}}
@BuiltValueEnumConst({{#isInteger}}wireNumber: {{{value}}}{{/isInteger}}{{^isInteger}}wireName: r{{#lambda.escapeBuiltValueEnum}}{{{value}}}{{/lambda.escapeBuiltValueEnum}}{{/isInteger}})
static const {{{classname}}}{{{enumName}}} {{name}} = _${{#lambda.camelcase}}{{{classname}}}{{{enumName}}}{{/lambda.camelcase}}_{{name}};
static const {{{enumName}}} {{name}} = _${{#lambda.camelcase}}{{{enumName}}}{{/lambda.camelcase}}_{{name}};
{{/enumVars}}
{{/allowableValues}}

static Serializer<{{{classname}}}{{{enumName}}}> get serializer => _${{#lambda.camelcase}}{{{classname}}}{{{enumName}}}{{/lambda.camelcase}}Serializer;
static Serializer<{{{enumName}}}> get serializer => _${{#lambda.camelcase}}{{{enumName}}}{{/lambda.camelcase}}Serializer;

const {{{classname}}}{{{enumName}}}._(String name): super(name);
const {{{enumName}}}._(String name): super(name);

static BuiltSet<{{{classname}}}{{{enumName}}}> get values => _${{#lambda.camelcase}}{{{classname}}}{{{enumName}}}{{/lambda.camelcase}}Values;
static {{{classname}}}{{{enumName}}} valueOf(String name) => _${{#lambda.camelcase}}{{{classname}}}{{{enumName}}}{{/lambda.camelcase}}ValueOf(name);
static BuiltSet<{{{enumName}}}> get values => _${{#lambda.camelcase}}{{{enumName}}}{{/lambda.camelcase}}Values;
static {{{enumName}}} valueOf(String name) => _${{#lambda.camelcase}}{{{enumName}}}{{/lambda.camelcase}}ValueOf(name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class {{{classname}}} {
/// Returns a new [{{{classname}}}] instance.
{{{classname}}}({
{{#vars}}
{{#required}}{{^defaultValue}}@required {{/defaultValue}}{{/required}}this.{{{name}}}{{^isNullable}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{classname}}}{{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/isNullable}},
{{#required}}{{^defaultValue}}@required {{/defaultValue}}{{/required}}this.{{{name}}}{{^isNullable}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/isNullable}},
{{/vars}}
});

Expand Down Expand Up @@ -151,7 +151,7 @@ class {{{classname}}} {
{{^complexType}}
{{#isArray}}
{{#isEnum}}
{{{name}}}: {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']),
{{{name}}}: {{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']),
{{/isEnum}}
{{^isEnum}}
{{{name}}}: json[r'{{{baseName}}}'] == null
Expand All @@ -176,7 +176,7 @@ class {{{classname}}} {
{{{name}}}: json[r'{{{baseName}}}'],
{{/isEnum}}
{{#isEnum}}
{{{name}}}: {{{classname}}}{{{enumName}}}.fromJson(json[r'{{{baseName}}}']),
{{{name}}}: {{{enumName}}}.fromJson(json[r'{{{baseName}}}']),
{{/isEnum}}
{{/isNumber}}
{{/isMap}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#description}}/// {{{description}}}{{/description}}
class {{{classname}}}{{{enumName}}} {
class {{{enumName}}} {
/// Instantiate a new enum with the provided [value].
const {{{classname}}}{{{enumName}}}._(this.value);
const {{{enumName}}}._(this.value);

/// The underlying value of this enum member.
final {{{dataType}}} value;
Expand All @@ -13,52 +13,52 @@ class {{{classname}}}{{{enumName}}} {

{{#allowableValues}}
{{#enumVars}}
static const {{{name}}} = {{{classname}}}{{{enumName}}}._({{#isString}}r{{/isString}}{{{value}}});
static const {{{name}}} = {{{enumName}}}._({{#isString}}r{{/isString}}{{{value}}});
{{/enumVars}}
{{/allowableValues}}

/// List of all possible values in this [enum][{{{classname}}}{{{enumName}}}].
static const values = <{{{classname}}}{{{enumName}}}>[
/// List of all possible values in this [enum][{{{enumName}}}].
static const values = <{{{enumName}}}>[
{{#allowableValues}}
{{#enumVars}}
{{{name}}},
{{/enumVars}}
{{/allowableValues}}
];

static {{{classname}}}{{{enumName}}} fromJson(dynamic value) =>
{{{classname}}}{{{enumName}}}TypeTransformer().decode(value);
static {{{enumName}}} fromJson(dynamic value) =>
{{{enumName}}}TypeTransformer().decode(value);

static List<{{{classname}}}{{{enumName}}}> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
static List<{{{enumName}}}> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
json == null || json.isEmpty
? true == emptyIsNull ? null : <{{{classname}}}{{{enumName}}}>[]
? true == emptyIsNull ? null : <{{{enumName}}}>[]
: json
.map((value) => {{{classname}}}{{{enumName}}}.fromJson(value))
.map((value) => {{{enumName}}}.fromJson(value))
.toList(growable: true == growable);
}

/// Transformation class that can [encode] an instance of [{{{classname}}}{{{enumName}}}] to {{{dataType}}},
/// and [decode] dynamic data back to [{{{classname}}}{{{enumName}}}].
class {{{classname}}}{{{enumName}}}TypeTransformer {
const {{{classname}}}{{{enumName}}}TypeTransformer._();
/// Transformation class that can [encode] an instance of [{{{enumName}}}] to {{{dataType}}},
/// and [decode] dynamic data back to [{{{enumName}}}].
class {{{enumName}}}TypeTransformer {
const {{{enumName}}}TypeTransformer._();

factory {{{classname}}}{{{enumName}}}TypeTransformer() => _instance ??= {{{classname}}}{{{enumName}}}TypeTransformer._();
factory {{{enumName}}}TypeTransformer() => _instance ??= {{{enumName}}}TypeTransformer._();

{{{dataType}}} encode({{{classname}}}{{{enumName}}} data) => data.value;
{{{dataType}}} encode({{{enumName}}} data) => data.value;

/// Decodes a [dynamic value][data] to a {{{classname}}}{{{enumName}}}.
/// Decodes a [dynamic value][data] to a {{{enumName}}}.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
{{{classname}}}{{{enumName}}} decode(dynamic data, {bool allowNull}) {
{{{enumName}}} decode(dynamic data, {bool allowNull}) {
switch (data) {
{{#allowableValues}}
{{#enumVars}}
case {{#isString}}r{{/isString}}{{{value}}}: return {{{classname}}}{{{enumName}}}.{{{name}}};
case {{#isString}}r{{/isString}}{{{value}}}: return {{{enumName}}}.{{{name}}};
{{/enumVars}}
{{/allowableValues}}
default:
Expand All @@ -69,6 +69,6 @@ class {{{classname}}}{{{enumName}}}TypeTransformer {
return null;
}

/// Singleton [{{{classname}}}{{{enumName}}}TypeTransformer] instance.
static {{{classname}}}{{{enumName}}}TypeTransformer _instance;
/// Singleton [{{{enumName}}}TypeTransformer] instance.
static {{{enumName}}}TypeTransformer _instance;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ void main() {
final instance = ApiResponse();

group(ApiResponse, () {
// int code (default value: null)
// int code
test('to test the property `code`', () async {
// TODO
});

// String type (default value: null)
// String type
test('to test the property `type`', () async {
// TODO
});

// String message (default value: null)
// String message
test('to test the property `message`', () async {
// TODO
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ void main() {
final instance = Category();

group(Category, () {
// int id (default value: null)
// int id
test('to test the property `id`', () async {
// TODO
});

// String name (default value: null)
// String name
test('to test the property `name`', () async {
// TODO
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ void main() {
final instance = Order();

group(Order, () {
// int id (default value: null)
// int id
test('to test the property `id`', () async {
// TODO
});

// int petId (default value: null)
// int petId
test('to test the property `petId`', () async {
// TODO
});

// int quantity (default value: null)
// int quantity
test('to test the property `quantity`', () async {
// TODO
});

// DateTime shipDate (default value: null)
// DateTime shipDate
test('to test the property `shipDate`', () async {
// TODO
});

// Order Status
// String status (default value: null)
// String status
test('to test the property `status`', () async {
// TODO
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ void main() {
final instance = Pet();

group(Pet, () {
// int id (default value: null)
// int id
test('to test the property `id`', () async {
// TODO
});

// Category category (default value: null)
// Category category
test('to test the property `category`', () async {
// TODO
});

// String name (default value: null)
// String name
test('to test the property `name`', () async {
// TODO
});

// BuiltList<String> photoUrls (default value: const [])
// BuiltList<String> photoUrls
test('to test the property `photoUrls`', () async {
// TODO
});

// BuiltList<Tag> tags (default value: const [])
// BuiltList<Tag> tags
test('to test the property `tags`', () async {
// TODO
});

// pet status in the store
// String status (default value: null)
// String status
test('to test the property `status`', () async {
// TODO
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ void main() {
final instance = Tag();

group(Tag, () {
// int id (default value: null)
// int id
test('to test the property `id`', () async {
// TODO
});

// String name (default value: null)
// String name
test('to test the property `name`', () async {
// TODO
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@ void main() {
final instance = User();

group(User, () {
// int id (default value: null)
// int id
test('to test the property `id`', () async {
// TODO
});

// String username (default value: null)
// String username
test('to test the property `username`', () async {
// TODO
});

// String firstName (default value: null)
// String firstName
test('to test the property `firstName`', () async {
// TODO
});

// String lastName (default value: null)
// String lastName
test('to test the property `lastName`', () async {
// TODO
});

// String email (default value: null)
// String email
test('to test the property `email`', () async {
// TODO
});

// String password (default value: null)
// String password
test('to test the property `password`', () async {
// TODO
});

// String phone (default value: null)
// String phone
test('to test the property `phone`', () async {
// TODO
});

// User Status
// int userStatus (default value: null)
// int userStatus
test('to test the property `userStatus`', () async {
// TODO
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class MapTest implements Built<MapTest, MapTestBuilder> {

@nullable
@BuiltValueField(wireName: r'map_of_enum_string')
BuiltMap<String, MapTestInnerEnum> get mapOfEnumString;
BuiltMap<String, MapTestMapOfEnumStringEnum> get mapOfEnumString;
// enum mapOfEnumStringEnum { UPPER, lower, };

@nullable
Expand All @@ -39,18 +39,18 @@ abstract class MapTest implements Built<MapTest, MapTestBuilder> {
static Serializer<MapTest> get serializer => _$mapTestSerializer;
}

class MapTestInnerEnum extends EnumClass {
class MapTestMapOfEnumStringEnum extends EnumClass {

@BuiltValueEnumConst(wireName: r'UPPER')
static const MapTestInnerEnum UPPER = _$mapTestInnerEnum_UPPER;
static const MapTestMapOfEnumStringEnum UPPER = _$mapTestMapOfEnumStringEnum_UPPER;
@BuiltValueEnumConst(wireName: r'lower')
static const MapTestInnerEnum lower = _$mapTestInnerEnum_lower;
static const MapTestMapOfEnumStringEnum lower = _$mapTestMapOfEnumStringEnum_lower;

static Serializer<MapTestInnerEnum> get serializer => _$mapTestInnerEnumSerializer;
static Serializer<MapTestMapOfEnumStringEnum> get serializer => _$mapTestMapOfEnumStringEnumSerializer;

const MapTestInnerEnum._(String name): super(name);
const MapTestMapOfEnumStringEnum._(String name): super(name);

static BuiltSet<MapTestInnerEnum> get values => _$mapTestInnerEnumValues;
static MapTestInnerEnum valueOf(String name) => _$mapTestInnerEnumValueOf(name);
static BuiltSet<MapTestMapOfEnumStringEnum> get values => _$mapTestMapOfEnumStringEnumValues;
static MapTestMapOfEnumStringEnum valueOf(String name) => _$mapTestMapOfEnumStringEnumValueOf(name);
}

Loading