dart-dio.class.mustache Maven / Gradle / Ivy
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part '{{classFilename}}.g.dart';
abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builder> {
{{#vars}}
{{#description}}
/// {{{.}}}
{{/description}}
{{!
A field is @nullable in built_value when it is
nullable || (!required && !defaultValue) in OAS
}}
{{#isNullable}}
@nullable
{{/isNullable}}
{{^isNullable}}
{{^required}}
{{^defaultValue}}
@nullable
{{/defaultValue}}
{{/required}}
{{/isNullable}}
@BuiltValueField(wireName: r'{{baseName}}')
{{{datatypeWithEnum}}} get {{name}};
{{#allowableValues}}
// {{#min}}range from {{{min}}} to {{{max}}}{{/min}}{{^min}}enum {{name}}Enum { {{#values}} {{{.}}}, {{/values}} };{{/min}}
{{/allowableValues}}
{{/vars}}
{{classname}}._();
static void _initializeBuilder({{{classname}}}Builder b) => b{{#vars}}{{#defaultValue}}
..{{{name}}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vars}};
factory {{classname}}([void updates({{classname}}Builder b)]) = _${{classname}};
@BuiltValueSerializer(custom: true)
static Serializer<{{classname}}> get serializer => _${{classname}}Serializer();
}
{{!
Generate a custom serializer in order to support combinations of required and nullable.
By default built_value does not serialize null fields.
}}
class _${{classname}}Serializer implements StructuredSerializer<{{classname}}> {
@override
final Iterable types = const [{{classname}}, _${{classname}}];
@override
final String wireName = r'{{classname}}';
@override
Iterable