OpenAPITools / OpenAPITools/openapi-generator
[Dart-dio-next] nullable fields sent when using multipart forms
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
This is what is generated today with last version:
Future<Response<User>> saveProfile({
String? email,
String? firstName,
String? lang,
String? lastName,
String? mobile,
String? password,
MultipartFile? avatar,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
})
....
_bodyData = FormData.fromMap(<String, dynamic>{
r'email': encodeFormParameter(_serializers, email, const FullType(String)),
r'firstName': encodeFormParameter(_serializers, firstName, const FullType(String)),
r'lang': encodeFormParameter(_serializers, lang, const FullType(String)),
r'lastName': encodeFormParameter(_serializers, lastName, const FullType(String)),
r'mobile': encodeFormParameter(_serializers, mobile, const FullType(String)),
r'password': encodeFormParameter(_serializers, password, const FullType(String)),
r'avatar': avatar,
});
Problem with that is that null fields are still sent to the payload, and even worse encodeFormParameter is forcing null field to be empty strings.
Basically here I don't want an empty string sent as a new password ^^, so I'm getting 400 all the time because password is not correct.
I guess an easy fix would be to wrap then into a if like this:
_bodyData = FormData.fromMap(<String, dynamic>{
if(email != null) r'email': encodeFormParameter(_serializers, email, const FullType(String)),
if(firstName != null) r'firstName': encodeFormParameter(_serializers, firstName, const FullType(String)),
if(lang != null) r'lang': encodeFormParameter(_serializers, lang, const FullType(String)),
if(lastName != null) r'lastName': encodeFormParameter(_serializers, lastName, const FullType(String)),
if(mobile != null) r'mobile': encodeFormParameter(_serializers, mobile, const FullType(String)),
if(password != null) r'password': encodeFormParameter(_serializers, password, const FullType(String)),
if(avatar != null) r'avatar': avatar,
});
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
Start with the Dart-dio-next generated saveProfile method and trace how encodeFormParameter is used in the FormData.fromMap payload. Verify how nullable multipart parameters are represented and compare that with the requested conditional entries. Done means omitted nullable fields are not sent while non-null fields, including avatar, remain in the payload without being converted to empty strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100