library {{ conf.inferred_package_name_snake_case() }}; import 'dart:convert'; import 'package:json_annotation/json_annotation.dart'; import 'package:decimal/decimal.dart'; import "{{ import_dots(namespace) }}_helper.dart"; {{ namespace_imports(namespace, outline, conf) }} {%- if !namespace.interfaces().is_empty() || !namespace.models().is_empty() %} {% if namespace.is_main() %} part '{{ conf.inferred_package_name_snake_case() }}.g.dart'; {% else %} part '{{ namespace.path().last().unwrap() }}.g.dart'; {% endif %} {% endif %} {% for e in outline.enums() %} {% if !e.members().is_empty() %} /// ## {{ e.title() }} /// /// {{ e.desc }} enum {{ e.name() }} { {%- for m in e.members() %} /// ### {{ m.title() }} /// /// {{ m.desc() }} @JsonValue("{{ m.name() }}") {{ m.name()|escape_dart|camelcase }}, {%- endfor %} } {%- endif %} {%- endfor %} {%- for path_argument in outline.path_arguments() %} class {{ path_argument.name() }} { {% for item in path_argument.items() %} String {{ item }}; {% endfor %} {{ path_argument.name() }}({ {% for item in path_argument.items() %} required this.{{ item }} {% endfor %} }); Map toMap() { var map = {}; {% for item in path_argument.items() %} map["{{ item }}"] = {{ item }}; {% endfor %} return map; } } {%- endfor %} {%- for interface in outline.interfaces() %} @JsonSerializable(explicitToJson: true, includeIfNull: false{% if !interface.is_output_result() %}{% endif %}{% if !interface.generic_names().is_empty() %}, genericArgumentFactories: true{% endif %}) class {{ interface.name() }}{{ interface.generics_declaration() }} { {%- for field in interface.fields_optional_at_last() %} {%- if should_escape(field.name()) %} @JsonKey(name: '{{ field.name() }}') {%- else if interface.is_output_result() && field.type().is_datetime() %} @JsonKey(fromJson: fromTeoDateTime) {%- else if interface.is_output_result() && field.type().is_decimal() %} @JsonKey(fromJson: fromTeoDecimal) {%- endif %} {{ append_question(lookup.call(fix_path(field.type(), namespace, conf).borrow()).unwrap(), interface.is_output_result()) }} {{ field.name()|escape_dart }}; {%- endfor %} {{ interface.name() }}({% if !interface.fields().is_empty() %}{ {%- for field in interface.fields_optional_at_last() %} {% if !(type_is_dynamic(lookup.call(field.type()).unwrap().borrow()) || field.type().is_optional() || interface.is_output_result()) %}required {% endif %}this.{{ field.name()|escape_dart }}, {%- endfor %} }{% endif %}); factory {{ interface.name() }}.fromJson(Map json{{ from_json_parameters(interface.generic_names()) }}) => _${{ interface.name() }}FromJson(json{{ from_json_arguments(interface.generic_names()) }}); Map toJson() => _${{ interface.name() }}ToJson(this{{ to_json_arguments(interface.generic_names()) }}); @override String toString() { var result = "{{ interface.name() }} { "; {%- for (index, field) in interface.fields().iter().enumerate() %} result += "{{ field.name() }}: "; if ({{ field.name()|escape_dart }} is String) { result += "\""; result += {{ field.name()|escape_dart }}.toString(); result += "\""; } else { result += {{ field.name()|escape_dart }}.toString(); } {%- if index != interface.fields().len() - 1 %} result += ", "; {% endif %} {%- endfor %} result += " }"; return result; } } {%- endfor %} {% if !namespace.is_std() %} {% for delegate in outline.delegates() %} class {{ delegate.name_with_conf(conf.class_name().to_string()) }} { final Map? _headers; {{ delegate.name_with_conf(conf.class_name().to_string()) }}(this._headers); {% for namespace_item in delegate.namespace_items() %} {% if !namespace_item.is_std() %} late {{ namespace_item.path().join(".") }} {{ namespace_item.property_name() }} = {{ namespace_item.path().join(".") }}(_headers); {% endif %} {% endfor %} {% for group_item in delegate.group_items() %} late {{ group_item.path().join(".") }} {{ group_item.property_name() }} = {{ group_item.path().join(".") }}(_headers); {% endfor %} {% for request_item in delegate.request_items() %} Future<{{ lookup.call(fix_path(request_item.output_type(), namespace, conf).borrow()).unwrap() }}> {{ request_item.name() }}({% if request_item.has_custom_url_args() %}Map pathArgs, {% endif %}{% if request_item.has_body_input() %}{{ lookup.call(fix_path(request_item.input_type(), namespace, conf).borrow()).unwrap() }} input, {% endif %}Map? headers{% if !request_item.is_builtin() %}, String? query{% endif %}) async { return await {% if request_item.is_form() %}formRequest{% else %}jsonRequest{% endif %}("{{ request_item.method() }}", {% if request_item.has_custom_url_args() %}replacePathArguments({% endif %}"{{ request_item.path() }}"{% if request_item.has_custom_url_args() %}, pathArgs){% endif %}, {% if request_item.has_body_input() %}input{% else %}null{% endif %}, {{ from_json_from_type(request_item.output_type()) }}, headers ?? _headers{% if !request_item.is_builtin() %}, query{% else %}null{% endif %}); } {% endfor %} } {% endfor %} {% endif %} {% if namespace.is_main() %} final {{ conf.object_name }} = {{ conf.object_name|capitalize_first }}(null); {% endif %}