OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Dart] MultipartRequest array of int not generating correctly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am doing multipartRequest to dotnet backend.
The error i get is:
ApiException 400: {"errors":{"Interests":["The value '[6, 5]' is not valid."]}}
this is whats generated:
/// Parameters:
///
/// * [String] name (required):
///
/// * [String] introduction (required):
///
/// * [String] description (required):
///
/// * [List<int>] interests (required):
///
/// * [MultipartFile] file:
Future<Response> apiPageCreatePostWithHttpInfo(String name, String introduction, String description, List<int> interests, { MultipartFile? file, }) async {
// ignore: prefer_const_declarations
final path = r'/api/page/create';
// ignore: prefer_final_locals
Object? postBody;
final queryParams = <QueryParam>[];
final headerParams = <String, String>{};
final formParams = <String, String>{};
const contentTypes = <String>['multipart/form-data'];
bool hasFields = false;
final mp = MultipartRequest('POST', Uri.parse(path));
if (name != null) {
hasFields = true;
mp.fields[r'Name'] = parameterToString(name);
}
if (introduction != null) {
hasFields = true;
mp.fields[r'Introduction'] = parameterToString(introduction);
}
if (description != null) {
hasFields = true;
mp.fields[r'Description'] = parameterToString(description);
}
if (interests != null) {
hasFields = true;
mp.fields[r'Interests'] = parameterToString(interests); //HERE IS THE PROBLEM
}
if (file != null) {
hasFields = true;
mp.fields[r'File'] = file.field;
mp.files.add(file);
}
if (hasFields) {
postBody = mp;
}
return apiClient.invokeAPI(
path,
'POST',
queryParams,
postBody,
headerParams,
formParams,
contentTypes.isEmpty ? null : contentTypes.first,
);
}
openapi-generator version
6.6.0
OpenAPI declaration file content or url
"/api/page/create": {
"post": {
"tags": ["Page"],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"Description",
"Interests",
"Introduction",
"Name"
],
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"Introduction": {
"type": "string"
},
"Description": {
"type": "string"
},
"Interests": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
},
"File": {
"type": "string",
"format": "binary"
}
}
},
"encoding": {
"Name": {
"style": "form"
},
"Introduction": {
"style": "form"
},
"Description": {
"style": "form"
},
"Interests": {
"style": "form"
},
"File": {
"style": "form"
}
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PageData"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
},
}
},
Generation Details
openapi-generator-cli generate -g dart -i swagger.json -o ./lib/api/rest --additional-properties=useEnumExtensions=true,ensureUniqueParams=false
Steps to reproduce
- build
- try to call it
Suggest a fix
this could probably work?
if (interests != null) {
hasFields = true;
final interestsString = interests.map((e) => e.toString()).join(',');
mp.fields[r'Interests'] = parameterToString(interestsString);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Regenerate the Dart client from the supplied multipart OpenAPI schema using the listed openapi-generator-cli command, then inspect the generated apiPageCreatePostWithHttpInfo method and its Interests field handling. Reproduce the request against the reported .NET backend and verify that a List such as [6, 5] is encoded in a form the backend accepts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100