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

ENUM in swagger.json makes client code failed to parse response from gateway #153

Closed
fabware opened this issue May 10, 2016 · 5 comments
Closed

Comments

@fabware
Copy link

fabware commented May 10, 2016

gRPC objective-C binding is currently broken, I come cross this project as rescue. It looks promising, except ENUM not working properly.

enumerate type in swagger.json is $ref.ENUM_TYPE of string enums, which cause swagger editor generated swift client code incompatible with http response of gateway, which actually treat enums as integers.

manually edit the swagger file to replace $ref.ENUM_TYPE with integer can solve the problem.

So, why not generate integer for enum type in the first place and make it actually works by default?

@igateno
Copy link

igateno commented May 11, 2016

I'm having this same issue right now. I don't think the right solution is to generate integer for enum type, that would defeat the purpose of having an enum in the first place. Here's what I would suggest:

If I have the proto message

message Ticket {
  int ID = 1;
  enum Priority {
    LOW = 0;
    HIGH = 1;
  }
  Priority priority = 2;
}

Then I should be able to create a ticket by making a POST request with this body

{
  "priority": "HIGH"
}

And I'd expect grpc-gateway to give me an error if I tried to set priority to "FOO" instead of "LOW" or "HIGH". Does that make sense?

@fabware
Copy link
Author

fabware commented May 12, 2016

It would be fine to use strings, if

  1. response from gateway also treat ENUM as strings;
  2. correct swagger client code can be generated.

Translate JSON by hand at client side can be very tedious.

@igateno
Copy link

igateno commented May 12, 2016

@fabware this issue is fixed if you pull the latest from master. It works exactly as I describe able.

@fabware
Copy link
Author

fabware commented May 14, 2016

Yes, I found it working that way, it's been a huge commit. Thanks for your reminder anyway.

Still swagger ENUM object of swift client code seems not compatible with string.

I have to modify protoc-swagger-gen to produce enum as strings, it is now working like charm.

@achew22
Copy link
Collaborator

achew22 commented Jan 4, 2017

Just doing a little bit of tidying. I hope that your question was answered in a way that let your project continue. If you have any more questions feel free to open another issue.

@achew22 achew22 closed this as completed Jan 4, 2017
@tamalsaha tamalsaha mentioned this issue Mar 30, 2017
1 task
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