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

[Dart] Enum support #7498

Closed
cputoaster opened this issue Jan 25, 2018 · 1 comment
Closed

[Dart] Enum support #7498

cputoaster opened this issue Jan 25, 2018 · 1 comment

Comments

@cputoaster
Copy link

Description

Enum support for Dart is currently not working. There is a non-working partial implementation available that still uses the old dartson way.

Swagger-codegen version

git master at a5e26a4

Swagger declaration file content or url
"ACTION": {
   "enum": [
    "NONE",
    "LOGOUT",
    "UPGRADE",
    "RESET_CLIENT_DB",
    "RELOAD_PAGE",
    "REGISTER"
   ]
  },
Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i openapi.json -l dart -o api -DbrowserClient=false

Steps to reproduce
  • create openapi.json with an enum
  • use swagger-codgen to create dart api code
  • results in something non-working like this:
@Entity()
class ACTION {
  /// The underlying value of this enum member.
  final  value;

  const ACTION._internal(this.value);

  static const ACTION nONE_ = const ACTION._internal("NONE");
  ...
  static const ACTION rEGISTER_ = const ACTION._internal("REGISTER");
}

class ACTIONTypeTransformer extends TypeTransformer<ACTION> {

  @override
  dynamic encode(ACTION data) {
    return data.value;
  }

  @override
  ACTION decode(dynamic data) {
    switch (data) {
      case &quot;NONE&quot;: return ACTION.nONE_;
      ...
      case &quot;REGISTER&quot;: return ACTION.rEGISTER_;
      default: throw('Unknown enum value to decode: $data');
    }
  }
}
Related issues/PRs

first mentioned in:
#7418

Suggest a fix/enhancement

see
#7418 (comment)

@cputoaster
Copy link
Author

Duplicate of #5454

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

1 participant