[BUG][dart-dio] wrong value sent for integer enums in query parameters
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue? https://gist.github.com/bmxbandita/5c162d525a82c769e3329d09d23d40ff
- Have you validated the input using an OpenAPI validator (example)? valid
- Have you tested with the latest master to confirm the issue still exists? yes, and 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
My spec has an integer type enum schema, and the generator generates an enumClass, with the following:
@BuiltValueEnumConst(wireName: r'36') static const Country n36 = _$n36;
If there is an endpoint with this integer enum model as query parameter, it will send ‘n36’, not ‘36’ what the server would accept. It seems that the serialization is completely ignored for Enum query parameters, and the literal field name is sent.
openapi-generator version
5.1.1 and latest master branch
OpenAPI declaration file content or url
https://gist.github.com/bmxbandita/5c162d525a82c769e3329d09d23d40ff
Generation Details
java -jar openapi-generator-cli.jar generate -i spec_sample.yml --additional-properties generateAliasAsModel=true,nullableFields=true -g dart-dio-next
I tried with dart-dio and dart dio-next generators as well, all the same results.
Steps to reproduce
Generate a dart-dio or dart-dio-next client with the provided spec.
Call the ‘/user/invoice_address’ endpoint that has an integer type enum as query parameter like so:
getUserAccountApi().invoiceAddressUserInvoiceAddressPut(country: Country.n36, currency: Currency.HUF);
The ‘currency’ param has the correct value ‘HUF’, but the ‘country’ param has the wrong ‘n36’ value, instead of the correct ‘36’.
Suggest a fix
Serialize EnumClasses for query parameters as well.
cc: @kuhnroyal
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Ohh, i think i know whats the problem, did you use the --additional-properties generateAliasAsModel=true property for the generator?
generateAliasAsModel
was the key to generating the spec.County
is an integer enum but it gets generated withwireName
. This happens becauseadditionalProperties
is declared which effectively makes this a map object, and then the correct wire type can not be detected.additionalProperties
usage is also whygenerateAliasAsModel
is needed in the first place.Removing
additionalProperties
generates:Nevertheless, I was not able to find anything that should cause
n36
to be serialized even withadditionalProperties
in place.