Bug Report Checklist
Description
Rust generator is not generating code properly for multipart with multiple files
openapi-generator version
7.19.9
OpenAPI declaration file content or url
{
"openapi": "3.0.4",
"info": {
"title": "x",
"description": "x",
"termsOfService": "https://x",
"contact": {
"name": "x",
"url": "https://x"
},
"license": {
"name": "License",
"url": "https://x"
},
"version": "v1"
},
"paths": {
"/api/report/send": {
"post": {
"tags": [
"Report"
],
"operationId": "SendReport",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/SendReport"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int32"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorDto"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorDto"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorDto"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorDto"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ErrorDto": {
"type": "object",
"properties": {
"statusCode": {
"type": "integer",
"format": "int32"
},
"exception": {
"type": "string",
"nullable": true
},
"message": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"SendReport": {
"required": [
"context",
"data",
"files",
"reason",
"type"
],
"type": "object",
"properties": {
"type": {
"$ref": "#/components/schemas/ReportTypeEnum"
},
"reason": {
"minLength": 1,
"type": "string"
},
"context": {
"minLength": 1,
"type": "string"
},
"data": {
"minLength": 1,
"type": "string"
},
"files": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
}
}
},
"additionalProperties": false
},
"ReportTypeEnum": {
"enum": [
"Event",
"Room",
"Comment",
"User"
],
"type": "string"
}
}
},
"tags": [
{
"name": "Report"
}
]
}
Generation Details
"generator-cli": {
"version": "7.19.0",
"generators": {
"v2.0": {
"generatorName": "rust",
"output": "./rust/openapi",
"inputSpec": "./swagger.json",
"additionalProperties": {
"packageVersion": "1.0.0",
"library": "reqwest",
"reqwestDefaultFeatures": "rustls-tls",
"useSerdePathToError": true,
"supportAsync": true,
"useEnumExtensions": true,
"ensureUniqueParams": false,
"enumUnknownDefaultCase": true,
"useSingleRequestParameter": true,
"prependFormOrBodyParameters": false
},
"globalProperty": {
"skipFormModel": false
}
}
}
}
Steps to reproduce
run it and expect in generated code error
the trait bound `Vec<PathBuf>: AsRef<std::path::Path>` is not satisfied
the following other types implement trait `AsRef<T>`:
`Vec<T, A>` implements `AsRef<Vec<T, A>>`
`Vec<T, A>` implements `AsRef<[T]>`
required for `&Vec<PathBuf>` to implement `AsRef<std::path::Path>
Suggest a fix
from:
let file = TokioFile::open(¶ms.files).await?;
let stream = FramedRead::new(file, BytesCodec::new());
let file_name = params.files.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
multipart_form = multipart_form.part("files", file_part);
to:
for path in p_form_files {
let file = TokioFile::open(&path).await.map_err(|e| Error::from(serde_json::Error::custom(format!("File open error: {e}"))))?;
let file_name = path.file_name()
.map(|n| n.to_string_lossy().to_string())
.unwrap_or_else(|| "file".into());
let stream = FramedRead::new(file, BytesCodec::new());
let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream))
.file_name(file_name);
// Use "files[]" if your backend expects an array, or "files" if it handles multiple parts with the same name
multipart_form = multipart_form.part("files", file_part);
}
Bug Report Checklist
Description
Rust generator is not generating code properly for multipart with multiple files
openapi-generator version
7.19.9
OpenAPI declaration file content or url
{ "openapi": "3.0.4", "info": { "title": "x", "description": "x", "termsOfService": "https://x", "contact": { "name": "x", "url": "https://x" }, "license": { "name": "License", "url": "https://x" }, "version": "v1" }, "paths": { "/api/report/send": { "post": { "tags": [ "Report" ], "operationId": "SendReport", "requestBody": { "content": { "multipart/form-data": { "schema": { "$ref": "#/components/schemas/SendReport" } } } }, "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "integer", "format": "int32" } } } }, "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorDto" } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorDto" } } } }, "400": { "description": "Bad Request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorDto" } } } }, "500": { "description": "Internal Server Error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorDto" } } } } } } } }, "components": { "schemas": { "ErrorDto": { "type": "object", "properties": { "statusCode": { "type": "integer", "format": "int32" }, "exception": { "type": "string", "nullable": true }, "message": { "type": "string", "nullable": true } }, "additionalProperties": false }, "SendReport": { "required": [ "context", "data", "files", "reason", "type" ], "type": "object", "properties": { "type": { "$ref": "#/components/schemas/ReportTypeEnum" }, "reason": { "minLength": 1, "type": "string" }, "context": { "minLength": 1, "type": "string" }, "data": { "minLength": 1, "type": "string" }, "files": { "type": "array", "items": { "type": "string", "format": "binary" } } }, "additionalProperties": false }, "ReportTypeEnum": { "enum": [ "Event", "Room", "Comment", "User" ], "type": "string" } } }, "tags": [ { "name": "Report" } ] }Generation Details
Steps to reproduce
run it and expect in generated code error
Suggest a fix
from:
to: