-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][dart-dio] Accept header not generated #15427
Comments
what should happen when there are multiple content children ? @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08) |
Yea that is the question, and probably why we don't generate this yet. |
Another approach is maybe to generate the The main issue we have with the current implementation is, that it doesn't play well with media type versioning. For example we have something like By the way: How do other generators handle this scenario? |
Well yea, but we do not support xml or whatnot so we can ignore those and reduce it to json/text content types. And after that, check what is left and then see if there is a single one left.
I don't know but some support XML and also some other wire formats, so that doesn't really matter here. |
This question came to me when I was doing #14346
so take for example this existing generated method Future<Response<Pet>> testEchoBodyPet({
Pet? pet,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/echo/body/Pet';
final _options = Options(
method: r'POST',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
contentType: 'application/json',
validateStatus: validateStatus,
);
dynamic _bodyData;
try {
const _type = FullType(Pet);
_bodyData = pet == null
? null
: _serializers.serialize(pet, specifiedType: _type);
} catch (error, stackTrace) {
throw DioError(
requestOptions: _options.compose(
_dio.options,
_path,
),
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
final _response = await _dio.request<Object>(
_path,
data: _bodyData,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
Pet _responseData;
try {
const _responseType = FullType(Pet);
_responseData = _serializers.deserialize(
_response.data!,
specifiedType: _responseType,
) as Pet;
} catch (error, stackTrace) {
throw DioError(
requestOptions: _response.requestOptions,
response: _response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<Pet>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}
} it can be refactored into 2 parts
Future<Response<Object>> testEchoBodyPetRaw({
Object? data,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
//Extra parameters for raw
String? requestContentType,
String? acceptContentType,
}) async {
final _path = r'/echo/body/Pet';
final _options = Options(
method: r'POST',
headers: <String, dynamic>{
if (acceptContentType != null) 'Accept': acceptContentType,
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
contentType: requestContentType,
validateStatus: validateStatus,
);
final _response = await _dio.request<Object>(
_path,
data: data,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
return _response;
}
Future<Response<Pet>> testEchoBodyPet({
Pet? pet,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _bodyData = pet == null
? null
: _serializers.serialize(pet, specifiedType: const FullType(Pet));
final _response = await testEchoBodyPetRaw(
data: _bodyData,
// change these depending on the return type
// sometimes we want to send files, or receive files
requestContentType: 'application/json',
acceptContentType: 'application/json',
cancelToken: cancelToken,
extra: extra,
headers: headers,
onReceiveProgress: onReceiveProgress,
onSendProgress: onSendProgress,
validateStatus: validateStatus,
);
final _rawResponseData = _response.data;
final _responseData = _rawResponseData == null
? null
: _serializers.deserialize(
_rawResponseData,
specifiedType: const FullType(Pet),
) as Pet;
return Response<Pet>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
} this way consumers can select different content types, on the expense they handle serialization/deserialization themselves |
I like the RAW idea but I think this is out of scope here. Can you summarise this in another issue? :) |
Bug Report Checklist
Description
dart-dio generator seems to not generate
Accept
header even though it is specified inresponses.<code>.content.<media-type>
. According to the docs I would assume that the generator sets theAccept
header to<media-type>
. This seems not to happen. Am I missing something here?openapi-generator version
6.5.0
OpenAPI declaration file content or url
Suggest a fix
The specs above should generate something like this:
The text was updated successfully, but these errors were encountered: