question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][dart-dio] wrong value sent for integer enums in query parameters

See original GitHub issue

Bug Report Checklist

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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bmxbanditacommented, Jul 27, 2021

Ohh, i think i know whats the problem, did you use the --additional-properties generateAliasAsModel=true property for the generator?

0reactions
kuhnroyalcommented, Jul 28, 2021

generateAliasAsModel was the key to generating the spec. County is an integer enum but it gets generated with wireName. This happens because additionalProperties is declared which effectively makes this a map object, and then the correct wire type can not be detected. additionalProperties usage is also why generateAliasAsModel is needed in the first place.

Removing additionalProperties generates:

  @BuiltValueEnumConst(wireNumber: 36)
  static const Country number36 = _$number36;

Nevertheless, I was not able to find anything that should cause n36 to be serialized even with additionalProperties in place.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] [dart-dio-next] Enum values based on Integers ... - GitHub
I think the problem is in the isInteger property: it will be true when using either int or int32, or no format at...
Read more >
SQL query in Java with enum return error of Incorrect integer ...
I get this error massage: java.sql.SQLException: Incorrect integer value: '\xAC\xED\x00\x05~r\x00... the query is working, but if I put the ...
Read more >
Using Enums as Request Parameters in Spring - Baeldung
Learn how to use enums as request parameters in Spring REST controllers and how to handle exceptions triggered by invalid input.
Read more >
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >
Enums - Swagger
Enums. You can use the enum keyword to specify possible values of a request parameter or a model property. For example, the sort...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found