Skip to content

Commit

Permalink
fix issues with payload and model
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Sep 18, 2024
1 parent 2372278 commit dcb5450
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion templates/dart/lib/services/service.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class {{ service.name | caseUcfirst }} extends Service {
{% if method.type == 'location' %}Future<Uint8List>{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel | overrideIdentifier }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async {
final String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}{% if parameter.enumValues | length > 0 %}.value{% endif %}){% endfor %};

{% if 'multipart/form-data' in method.consumes %}
{%~ if 'multipart/form-data' in method.consumes and method.type == "upload" %}
{{ include('dart/base/requests/file.twig') }}
{% elseif method.type == 'location' %}
{{ include('dart/base/requests/location.twig') }}
Expand Down
10 changes: 5 additions & 5 deletions templates/dart/lib/src/client_browser.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ class ClientBrowser extends ClientBase with ClientMixin {
Function(UploadProgress)? onProgress,
}) async {
Payload file = params[paramName];
if (file.bytes == null) {
throw {{spec.title | caseUcfirst}}Exception("File bytes must be provided for Flutter web");
if (file.data == null) {
throw {{spec.title | caseUcfirst}}Exception("File data must be provided for Flutter web");
}

int size = file.bytes!.length;
int size = file.data!.length;

late Response res;
if (size <= CHUNK_SIZE) {
params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename);
params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename);
return call(
HttpMethod.post,
path: path,
Expand All @@ -129,7 +129,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
while (offset < size) {
List<int> chunk = [];
final end = min(offset + CHUNK_SIZE, size);
chunk = file.bytes!.getRange(offset, end).toList();
chunk = file.fromBinary(length: offset, length: min(CHUNK_SIZE, size - offset));
params[paramName] =
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
headers['content-range'] =
Expand Down
5 changes: 3 additions & 2 deletions templates/dart/lib/src/models/model.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
{%- endif -%}
{%- else -%}
{%- if property.type == "integer" -%}
int.tryParse(
(map['{{property.name | escapeDollarSign }}'] is String) ?
int.tryParse(map['{{property.name | escapeDollarSign }}']) {%- if property.required %} ?? 0{% endif %}:
{%- endif -%}
map['{{property.name | escapeDollarSign }}']
{%- if property.type == "integer" -%}
?? ''){%- if property.required %} ?? 0{% endif %}
{%- if property.required %} ?? 0{% endif %}
{%- endif -%}
{%- if property.type == "number" -%}
{%- if not property.required %}?{% endif %}.toDouble()
Expand Down
2 changes: 1 addition & 1 deletion templates/flutter/lib/services/service.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class {{ service.name | caseUcfirst }} extends Service {
{% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}Future<Uint8List>{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel | overrideIdentifier }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async {
{% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}{% if parameter.enumValues | length > 0 %}.value{% endif %}){% endfor %};

{% if 'multipart/form-data' in method.consumes %}
{%~ if 'multipart/form-data' in method.consumes and method.type == "upload" %}
{{ include('flutter/base/requests/file.twig') }}
{% elseif method.type == 'webAuth' %}
{{ include('flutter/base/requests/oauth.twig') }}
Expand Down
10 changes: 5 additions & 5 deletions templates/flutter/lib/src/client_browser.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ class ClientBrowser extends ClientBase with ClientMixin {
Function(UploadProgress)? onProgress,
}) async {
InputFile file = params[paramName];
if (file.bytes == null) {
throw {{spec.title | caseUcfirst}}Exception("File bytes must be provided for Flutter web");
if (file.data == null) {
throw {{spec.title | caseUcfirst}}Exception("File data must be provided for Flutter web");
}

int size = file.bytes!.length;
int size = file.data!.length;

late Response res;
if (size <= CHUNK_SIZE) {
params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename);
params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename);
return call(
HttpMethod.post,
path: path,
Expand All @@ -150,7 +150,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
while (offset < size) {
List<int> chunk = [];
final end = min(offset + CHUNK_SIZE, size);
chunk = file.bytes!.getRange(offset, end).toList();
chunk = file.fromBinary(offset: offset, length: min(CHUNK_SIZE, size - offset)).toList();
params[paramName] =
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
headers['content-range'] =
Expand Down

0 comments on commit dcb5450

Please sign in to comment.