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

Support map types in swagger generator #141

Merged
merged 2 commits into from
May 9, 2016

Conversation

t-yuki
Copy link
Contributor

@t-yuki t-yuki commented May 2, 2016

According to Swagger Schema Object spec http://swagger.io/specification/#schemaObject and proto3 json spec https://developers.google.com/protocol-buffers/docs/proto3#json , map<string, v> field should be represented by additionalProperties.

Internally, protoc generates a entry message type message MapFieldEntry {} from map<KeyType, ValueType> map_field = 1;.
So in this change, mapEntry messages are skipped in message render step and mapEntry fields are expanded as type: object and additionalProperties parameter.
See: https://github.com/golang/protobuf/blob/001690d39bd620847bb265d93a7c5e1bd3737308/protoc-gen-go/descriptor/descriptor.pb.go#L1123

Refs #140

Note that non-string keyed map is not supported yet even though the proto3 json spec said it will be converted to string automatically.
Note 2: generated Go struct field is already map[string]*Object type so there is no fix for grpc-gateway itself and jsonpb is not required. see: https://developers.google.com/protocol-buffers/docs/reference/go-generated#map

@yugui yugui merged commit 6c01d4f into grpc-ecosystem:master May 9, 2016
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

Successfully merging this pull request may close these issues.

2 participants