OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.81k stars 6.58k forks source link

[REQ] [dart-dio-next] Enum fallback values #10038

Closed josh-burton closed 2 years ago

josh-burton commented 3 years ago

BuiltValue supports setting an enum entry as a fallback to use if the serialized enum value doesn't exist.

This is great for backwards compatibility in APIs as an enum can fallback to an 'unknown' value.


## Describe the solution you'd like

In my API clients I generally modify the enum.mustache and inline_enum.mustache files to fallback to the first value.

@BuiltValueEnumConst({{#isInteger}}wireNumber: {{{value}}}{{/isInteger}}{{^isInteger}}wireName: r{{{value}}}{{/isInteger}}{{#-first}}, fallback: true{{/-first}})



A config flag could be added to enable this behaviour, or perhaps something more advanced like a config flag to determine which enum value to fallback to.

e.g. "enumFallbackValue": "unknown"

If an enum class is generated and has an "unknown" value, the fallback would be set on that value.

@kuhnroyal any thoughts?
kuhnroyal commented 3 years ago

Didn't get the mention cause of formatting. We should check if other generators have a fallback behavior. Maybe just use default?

kuhnroyal commented 3 years ago

@wing328 Is there something like fallback values somewhere?

kuhnroyal commented 2 years ago

Ran into an unannounced API update today that introduced new enum values :)

Couple links for future reference: https://github.com/OAI/OpenAPI-Specification/issues/1552 https://opensource.zalando.com/restful-api-guidelines/#112

kuhnroyal commented 2 years ago

@josh-burton What do you think about adding something like an x-enum-fallback?

josh-burton commented 2 years ago

@kuhnroyal yeah that would be great. Letting the user choose which value is the fallback would be the ideal solution.

kuhnroyal commented 2 years ago

@josh-burton This is fixed now :)

vasilich6107 commented 2 months ago

hi @kuhnroyal Could you clarify how this should work?| I do not see any usage in @JsonKey for unknownEnumValue parameter