grpc-ecosystem / grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec
https://grpc-ecosystem.github.io/grpc-gateway/
BSD 3-Clause "New" or "Revised" License
18.01k stars 2.22k forks source link

Support for repeated path parameters #741

Closed maros7 closed 6 years ago

maros7 commented 6 years ago

I wonder if you would consider adding support for repeated path parameters á la "collectionFormat": "csv" from Swagger/OpenAPI? See e.g. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object-example. I would be interested in submitting a PR myself.

johanbrandhorst commented 6 years ago

Path parameters largely just need to be compatible with the http.proto HttpRule definition: https://github.com/googleapis/api-common-protos/blob/master/google/api/http.proto#L45. If your proposal can be described using that, I don't see why not :).

maros7 commented 6 years ago

Ideally I’d like to follow the OpenAPI 2.0 standard which allows csv (default), ssv, tsv, pipe and multi. The latter is only for query params though. But I don’t see how it would be possible to specify a ”separator” using the http annotation. As I see it I can implement/hard code csv and my assumption is that it would be sufficient for most people. The http annotation documentation also seems to state that this should be the way to do it if I interperet it and RFC 6570 (https://tools.ietf.org/html/rfc6570#section-3.2.2) correctly. On the other hand I guess it could be possible to have a custom annotation, like you have for the swagger generator (https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-swagger/options/annotations.proto) to support specifying the ”separator” type. Yet another option could be to make it configureable via a parameter provided to the plug-in, e.g. ”repeated_field_separator=csv”. What is your take?

maros7 commented 6 years ago

Sadly swagger-codgen doesn't support arrays as path parameters, even if the 2.0 spec says that it is supported. See https://github.com/swagger-api/swagger-codegen/blob/v2.2.2/modules/swagger-codegen/src/main/resources/go/api.mustache#L45. It will only generate correct code for arrays as query parameters. See https://github.com/swagger-api/swagger-codegen/blob/v2.2.2/modules/swagger-codegen/src/main/resources/go/api.mustache#L85-L86. Nonetheless, I'll submit a PR for review.