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

protobuf well known types aren't represented in swagger output correctly #160

Closed
tmc opened this issue May 17, 2016 · 7 comments
Closed

Comments

@tmc
Copy link
Collaborator

tmc commented May 17, 2016

Durations appear in swagger as {"seconds": 0, "nanos": 0} though jsonpb marshals and unmarshals them in a string form like: "45.000s"

@tmc tmc changed the title protobuf well known aren't represented in swagger output correclty protobuf well known types aren't represented in swagger output correclty May 17, 2016
@tmc
Copy link
Collaborator Author

tmc commented May 17, 2016

@yugui do you have thoughts here on how we should handle this problem? I'm happy to hack on a patch but have only been lightly watching the swagger and marshaler work.

@yugui
Copy link
Member

yugui commented May 20, 2016

I don't have much idea.

But the number of the well-known types is limited. So we could extend the mapping table to the swagger types.

@achew22
Copy link
Collaborator

achew22 commented Oct 4, 2016

@tmc with #209 in that provides a template for handling the custom times.

The special types are as follows:

  • Timestamp
    • Already in Swagger and OpenAPI
  • Duration (In neither Swagger nor OpenAPI
  • Any
    • Should be serialized as {"@type": "url", "f": v, … } which I would guess is possible with the existing swagger spec
  • Wrapper types
    • I'm not sure I totally understand the purpose of this. Is it just to provide nullability?
  • Struct
    • Should be possible to implement as well

Do you need any of the other ones?

@tmc tmc changed the title protobuf well known types aren't represented in swagger output correclty protobuf well known types aren't represented in swagger output correctly Nov 6, 2016
@stefanoj3
Copy link

Bump, and confirm that the issue is still there

@ianrose14
Copy link

jsonpb marshals and unmarshals them in a string form like: "45.000s"

Why is this? The Timestamp type by default will serialize as {"seconds": 0, "nanos": 0} so if you use any json-serializer on the client other than jsonpb you'll end up with a request body that jsonpb doesn't like on the server side. Why doesn't jsonpb just do the "normal" behavior and encode it the same way as encoding/json would do?

@achew22
Copy link
Collaborator

achew22 commented Aug 7, 2017

There is a set of well known types that are special coded in the proto3 spec when they are converted to JSON. This is the spec for duration

https://github.com/golang/protobuf/blob/master/jsonpb/jsonpb.go#L167
https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Duration

@johanbrandhorst
Copy link
Collaborator

I believe this has been fixed in recent months.

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

No branches or pull requests

6 participants