Support map types in swagger generator #141
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 byadditionalProperties
.Internally,
protoc
generates a entry message typemessage MapFieldEntry {}
frommap<KeyType, ValueType> map_field = 1;
.So in this change,
mapEntry
messages are skipped in message render step andmapEntry
fields are expanded astype: object
andadditionalProperties
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