|
|
@ -603,6 +603,7 @@ class OpenAPIBuilder implements Builder { |
|
|
|
|
|
|
|
|
|
|
|
String? dataType; |
|
|
|
String? dataType; |
|
|
|
String? dataValue; |
|
|
|
String? dataValue; |
|
|
|
|
|
|
|
bool? dataNeedsAwait; |
|
|
|
if (response.content != null) { |
|
|
|
if (response.content != null) { |
|
|
|
if (response.content!.length > 1) { |
|
|
|
if (response.content!.length > 1) { |
|
|
|
throw Exception('Can not work with multiple mime types right now'); |
|
|
|
throw Exception('Can not work with multiple mime types right now'); |
|
|
@ -625,20 +626,24 @@ class OpenAPIBuilder implements Builder { |
|
|
|
if (mimeType == '*/*' || mimeType.startsWith('image/')) { |
|
|
|
if (mimeType == '*/*' || mimeType.startsWith('image/')) { |
|
|
|
dataType = 'Uint8List'; |
|
|
|
dataType = 'Uint8List'; |
|
|
|
dataValue = 'response.bodyBytes'; |
|
|
|
dataValue = 'response.bodyBytes'; |
|
|
|
|
|
|
|
dataNeedsAwait = true; |
|
|
|
} else if (mimeType.startsWith('text/')) { |
|
|
|
} else if (mimeType.startsWith('text/')) { |
|
|
|
dataType = 'String'; |
|
|
|
dataType = 'String'; |
|
|
|
dataValue = 'await response.body'; |
|
|
|
dataValue = 'response.body'; |
|
|
|
|
|
|
|
dataNeedsAwait = true; |
|
|
|
} else if (mimeType == 'application/json') { |
|
|
|
} else if (mimeType == 'application/json') { |
|
|
|
dataType = result.name; |
|
|
|
dataType = result.name; |
|
|
|
if (result.name == 'dynamic') { |
|
|
|
if (result.name == 'dynamic') { |
|
|
|
dataValue = ''; |
|
|
|
dataValue = ''; |
|
|
|
} else if (result.name == 'String') { |
|
|
|
} else if (result.name == 'String') { |
|
|
|
// avoid unnecessary_await_in_return lint |
|
|
|
|
|
|
|
dataValue = 'response.body'; |
|
|
|
dataValue = 'response.body'; |
|
|
|
|
|
|
|
dataNeedsAwait = true; |
|
|
|
} else if (result is TypeResultEnum || result is TypeResultBase) { |
|
|
|
} else if (result is TypeResultEnum || result is TypeResultBase) { |
|
|
|
dataValue = result.deserialize(result.decode('await response.body')); |
|
|
|
dataValue = result.deserialize(result.decode('await response.body')); |
|
|
|
|
|
|
|
dataNeedsAwait = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dataValue = result.deserialize('await response.jsonBody'); |
|
|
|
dataValue = result.deserialize('await response.jsonBody'); |
|
|
|
|
|
|
|
dataNeedsAwait = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
throw Exception('Can not parse mime type "$mimeType"'); |
|
|
|
throw Exception('Can not parse mime type "$mimeType"'); |
|
|
@ -649,7 +654,7 @@ class OpenAPIBuilder implements Builder { |
|
|
|
if (headersType != null && dataType != null) { |
|
|
|
if (headersType != null && dataType != null) { |
|
|
|
b.returns = refer('Future<${classPrefix}Response<$dataType, $headersType>>'); |
|
|
|
b.returns = refer('Future<${classPrefix}Response<$dataType, $headersType>>'); |
|
|
|
code.write( |
|
|
|
code.write( |
|
|
|
'return ${classPrefix}Response<$dataType, $headersType>($dataValue, $headersValue,);', |
|
|
|
'return ${classPrefix}Response<$dataType, $headersType>(${dataNeedsAwait ?? false ? 'await ' : ''}$dataValue, $headersValue,);', |
|
|
|
); |
|
|
|
); |
|
|
|
} else if (headersType != null) { |
|
|
|
} else if (headersType != null) { |
|
|
|
b.returns = refer('Future<$headersType>'); |
|
|
|
b.returns = refer('Future<$headersType>'); |
|
|
|