Skip to content
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

handle Enum in response and request #559

Open
billyandco opened this issue Mar 29, 2023 · 2 comments
Open

handle Enum in response and request #559

billyandco opened this issue Mar 29, 2023 · 2 comments

Comments

@billyandco
Copy link

While using swager_parse library to generate retrofit from swagger
there's some case where enum can be use in queryParameter
and some case where enum can be used for response but will need a fromJson method on enum

you will check in this pull request that we tried to find a way to deal with it
but when json is a String and generator try to cast as Map<String, dynamic>, it can be broken
we made a solution for toJson on enum, but i think it can be handle inside retrofit generator

Carapacik/swagger_parser#18

@knyghtryda
Copy link

I'm currently running into this as well. The workaround is to create an extension on the enum for the toJson(), but this ideally should be handled by retrofit directly.

@sooxt98
Copy link
Contributor

sooxt98 commented Nov 10, 2023

update: seems like the retrofit patch doesn't fix the issue, it still using .name

this could be solved all together with configuration below

# pubspec.yaml
swagger_parser:
  enums_to_json: true

# build.yaml
targets:
  $default:
    builders:
      json_serializable:
        options:
          explicit_to_json: true

#596
rrousselGit/freezed#86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants