I am using swagger_dart_code_generator for my Flutter app to generate code based on an openapi.json.
It does its job for application/json requests, however it does not work with multipart/form-data.
I am sure that the api works, I tried it from the swagger web ui.
In case it helps, here are the relevant parts of the openapi.json:
"post": {
"operationId": "ImageListApiView_post_images_post",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/ImageMetaForm"
}
}
},
"required": true
},
/* ... */
},
"ImageMetaForm": {
"properties": {
"file": {
"description": "The image to upload.",
"format": "binary",
"title": "File",
"type": "string"
}
},
"required": [
"file"
],
"title": "ImageMetaForm",
"type": "object"
},
Here is the generated code:
@override
Future<Response<ResponseImageMetaTDO>> _apiV1ImagesPost(
{required ImageMetaForm body}) {
final Uri $url = Uri.parse('/api/v1/images');
final List<PartValue> $parts = <PartValue>[
PartValue<ImageMetaForm>(
'body',
body,
)
];
final Request $request = Request(
'POST',
$url,
client.baseUrl,
parts: $parts,
multipart: true,
);
return client.send<ResponseImageMetaTDO, ResponseImageMetaTDO>($request);
}
And here is the body of the outgoing request:
--dart-http-boundary-AJQBeUhjoUmCi.dny6r+q.hDb4gsBJeLma6Abmbpwx+0uiiNv4l
content-disposition: form-data; name="body"
{"file":"/home/melidon/Pictures/IMG_20230816_192752.jpg" }
--dart-http-boundary-AJQBeUhjoUmCi.dny6r+q.hDb4gsBJeLma6Abmbpwx+0uiiNv4l--
Any help is appreciated.