diff --git a/github.com/andy-kimball/arenaskl/arena.go b/github.com/andy-kimball/arenaskl/arena.go index 277e9179d8..1565fb108a 100644 --- a/github.com/andy-kimball/arenaskl/arena.go +++ b/github.com/andy-kimball/arenaskl/arena.go @@ -62,7 +62,7 @@ func (a *Arena) Reset() { atomic.StoreUint32(&a.n, 1) } -func (a *Arena) Alloc(size uint16, align Align) (uint32, error) { +func (a *Arena) Alloc(size uint32, align Align) (uint32, error) { // Pad the allocation with enough bytes to ensure the requested alignment. padded := uint32(size) + uint32(align) @@ -76,12 +76,12 @@ func (a *Arena) Alloc(size uint16, align Align) (uint32, error) { return offset, nil } -func (a *Arena) GetBytes(offset uint32, size uint16) []byte { +func (a *Arena) GetBytes(offset uint32, size uint32) []byte { if offset == 0 { return nil } - return a.buf[offset : offset+uint32(size)] + return a.buf[offset : offset+size] } func (a *Arena) GetPointer(offset uint32) unsafe.Pointer { diff --git a/github.com/andy-kimball/arenaskl/iterator.go b/github.com/andy-kimball/arenaskl/iterator.go index f13667c11f..0bfe7b6a7a 100644 --- a/github.com/andy-kimball/arenaskl/iterator.go +++ b/github.com/andy-kimball/arenaskl/iterator.go @@ -62,7 +62,7 @@ func (it *Iterator) Key() []byte { // Value returns the value at the current position. func (it *Iterator) Value() []byte { valOffset, valSize := decodeValue(it.value) - return it.arena.GetBytes(valOffset, valSize) + return it.arena.GetBytes(valOffset, uint32(valSize)) } // Meta returns the metadata at the current position. diff --git a/github.com/andy-kimball/arenaskl/node.go b/github.com/andy-kimball/arenaskl/node.go index 6dde8ff126..8a236e8193 100644 --- a/github.com/andy-kimball/arenaskl/node.go +++ b/github.com/andy-kimball/arenaskl/node.go @@ -34,10 +34,7 @@ func (l *links) init(prevOffset, nextOffset uint32) { type node struct { // Immutable fields, so no need to lock to access key. keyOffset uint32 - keySize uint16 - - // Height of this node's tower. - height uint16 + keySize uint32 // Multiple parts of the value are encoded as a single uint64 so that it // can be atomically loaded and stored: @@ -65,19 +62,17 @@ func newNode(arena *Arena, height uint32) (nd *node, err error) { // is less than maxHeight. unusedSize := (maxHeight - int(height)) * linksSize - nodeOffset, err := arena.Alloc(uint16(MaxNodeSize-unusedSize), Align8) + nodeOffset, err := arena.Alloc(uint32(MaxNodeSize-unusedSize), Align8) if err != nil { return } nd = (*node)(arena.GetPointer(nodeOffset)) - nd.height = uint16(height) - return } func (n *node) getKey(arena *Arena) []byte { - return arena.GetBytes(n.keyOffset, uint16(n.keySize)) + return arena.GetBytes(n.keyOffset, n.keySize) } func (n *node) nextOffset(h int) uint32 { diff --git a/github.com/andy-kimball/arenaskl/skl.go b/github.com/andy-kimball/arenaskl/skl.go index bbfb9470f6..c75f307315 100644 --- a/github.com/andy-kimball/arenaskl/skl.go +++ b/github.com/andy-kimball/arenaskl/skl.go @@ -171,12 +171,12 @@ func (s *Skiplist) randomHeight() uint32 { return h } -func (s *Skiplist) allocKey(key []byte) (keyOffset uint32, keySize uint16, err error) { - if len(key) > math.MaxUint16 { +func (s *Skiplist) allocKey(key []byte) (keyOffset uint32, keySize uint32, err error) { + if len(key) > math.MaxUint32 { panic("key is too large") } - keySize = uint16(len(key)) + keySize = uint32(len(key)) keyOffset, err = s.arena.Alloc(keySize, Align1) if err == nil { copy(s.arena.GetBytes(keyOffset, keySize), key) @@ -191,13 +191,12 @@ func (s *Skiplist) allocVal(val []byte, meta uint16) (uint64, error) { } valSize := uint16(len(val)) - - valOffset, err := s.arena.Alloc(valSize, Align1) + valOffset, err := s.arena.Alloc(uint32(valSize), Align1) if err != nil { return 0, err } - copy(s.arena.GetBytes(valOffset, valSize), val) + copy(s.arena.GetBytes(valOffset, uint32(valSize)), val) return encodeValue(valOffset, valSize, meta), nil } diff --git a/github.com/grpc-ecosystem/grpc-gateway/.gitignore b/github.com/grpc-ecosystem/grpc-gateway/.gitignore index 88ddcdf4d4..eb15433281 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/.gitignore +++ b/github.com/grpc-ecosystem/grpc-gateway/.gitignore @@ -1 +1,2 @@ _output/ +.idea diff --git a/github.com/grpc-ecosystem/grpc-gateway/.travis.yml b/github.com/grpc-ecosystem/grpc-gateway/.travis.yml index 9ca6f5d702..eea6dd8202 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/.travis.yml +++ b/github.com/grpc-ecosystem/grpc-gateway/.travis.yml @@ -35,4 +35,4 @@ env: - "PATH=$PATH:$HOME/local/bin" matrix: - GATEWAY_PLUGIN_FLAGS= - - GATEWAY_PLUGIN_FLAGS=request_context=true + - GATEWAY_PLUGIN_FLAGS=request_context=false diff --git a/github.com/grpc-ecosystem/grpc-gateway/Makefile b/github.com/grpc-ecosystem/grpc-gateway/Makefile index 5fe3c4850e..c6a645e0ef 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/Makefile +++ b/github.com/grpc-ecosystem/grpc-gateway/Makefile @@ -43,6 +43,9 @@ OUTPUT_DIR=_output RUNTIME_PROTO=runtime/internal/stream_chunk.proto RUNTIME_GO=$(RUNTIME_PROTO:.proto=.pb.go) +OPENAPIV2_PROTO=protoc-gen-swagger/options/openapiv2.proto protoc-gen-swagger/options/annotations.proto +OPENAPIV2_GO=$(OPENAPIV2_PROTO:.proto=.pb.go) + PKGMAP=Mgoogle/protobuf/descriptor.proto=$(GO_PLUGIN_PKG)/descriptor,Mexamples/sub/message.proto=$(PKG)/examples/sub ADDITIONAL_FLAGS= ifneq "$(GATEWAY_PLUGIN_FLAGS)" "" @@ -83,17 +86,20 @@ generate: $(RUNTIME_GO) .SUFFIXES: .go .proto -$(GO_PLUGIN): +$(GO_PLUGIN): go get $(GO_PLUGIN_PKG) go build -o $@ $(GO_PLUGIN_PKG) $(RUNTIME_GO): $(RUNTIME_PROTO) $(GO_PLUGIN) protoc -I $(PROTOC_INC_PATH) --plugin=$(GO_PLUGIN) -I. --go_out=$(PKGMAP):. $(RUNTIME_PROTO) +$(OPENAPIV2_GO): $(OPENAPIV2_PROTO) $(GO_PLUGIN) + protoc -I $(PROTOC_INC_PATH) --plugin=$(GO_PLUGIN) -I. --go_out=$(PKGMAP):$(GOPATH)/src $(OPENAPIV2_PROTO) + $(GATEWAY_PLUGIN): $(RUNTIME_GO) $(GATEWAY_PLUGIN_SRC) go build -o $@ $(GATEWAY_PLUGIN_PKG) -$(SWAGGER_PLUGIN): $(SWAGGER_PLUGIN_SRC) +$(SWAGGER_PLUGIN): $(SWAGGER_PLUGIN_SRC) $(OPENAPIV2_GO) go build -o $@ $(SWAGGER_PLUGIN_PKG) $(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(EXAMPLES) @@ -143,5 +149,6 @@ realclean: distclean rm -f $(GO_PLUGIN) rm -f $(SWAGGER_PLUGIN) rm -f $(EXAMPLE_CLIENT_SRCS) + rm -f $(OPENAPIV2_GO) .PHONY: generate examples test lint clean distclean realclean diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_nested.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_nested.go index 909f478b7d..095e8c5f11 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_nested.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_nested.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_service_api.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_service_api.go index 669a12aed7..d66b34f54b 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_service_api.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/a_bit_of_everything_service_api.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ @@ -91,7 +91,7 @@ func (a ABitOfEverythingServiceApi) Create(floatValue float32, doubleValue float } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -101,6 +101,7 @@ func (a ABitOfEverythingServiceApi) Create(floatValue float32, doubleValue float // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -150,7 +151,7 @@ func (a ABitOfEverythingServiceApi) CreateBody(body ExamplepbABitOfEverything) ( } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -160,6 +161,7 @@ func (a ABitOfEverythingServiceApi) CreateBody(body ExamplepbABitOfEverything) ( // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -213,7 +215,7 @@ func (a ABitOfEverythingServiceApi) DeepPathEcho(singleNestedName string, body E } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -223,6 +225,7 @@ func (a ABitOfEverythingServiceApi) DeepPathEcho(singleNestedName string, body E // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -275,7 +278,7 @@ func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIRes } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -285,6 +288,7 @@ func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIRes // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -311,7 +315,8 @@ func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIRes } /** - * + * Echo allows posting a StringMessage value. + * It also exposes multiple bindings. This makes it useful when validating that the OpenAPI v2 API description exposes documentation correctly on all paths defined as additional_bindings in the proto. * * @param value * @return *SubStringMessage @@ -335,7 +340,7 @@ func (a ABitOfEverythingServiceApi) Echo(value string) (*SubStringMessage, *APIR } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -345,6 +350,7 @@ func (a ABitOfEverythingServiceApi) Echo(value string) (*SubStringMessage, *APIR // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -371,14 +377,15 @@ func (a ABitOfEverythingServiceApi) Echo(value string) (*SubStringMessage, *APIR } /** - * + * Echo allows posting a StringMessage value. + * It also exposes multiple bindings. This makes it useful when validating that the OpenAPI v2 API description exposes documentation correctly on all paths defined as additional_bindings in the proto. * - * @param value + * @param body * @return *SubStringMessage */ -func (a ABitOfEverythingServiceApi) Echo_1(value string) (*SubStringMessage, *APIResponse, error) { +func (a ABitOfEverythingServiceApi) Echo2(body string) (*SubStringMessage, *APIResponse, error) { - var localVarHttpMethod = strings.ToUpper("Get") + var localVarHttpMethod = strings.ToUpper("Post") // create path and map variables localVarPath := a.Configuration.BasePath + "/v2/example/echo" @@ -392,10 +399,9 @@ func (a ABitOfEverythingServiceApi) Echo_1(value string) (*SubStringMessage, *AP for key := range a.Configuration.DefaultHeader { localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] } - localVarQueryParams.Add("value", a.Configuration.APIClient.ParameterToString(value, "")) // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -405,6 +411,7 @@ func (a ABitOfEverythingServiceApi) Echo_1(value string) (*SubStringMessage, *AP // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -412,12 +419,14 @@ func (a ABitOfEverythingServiceApi) Echo_1(value string) (*SubStringMessage, *AP if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } + // body params + localVarPostBody = &body var successPayload = new(SubStringMessage) localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) var localVarURL, _ = url.Parse(localVarPath) localVarURL.RawQuery = localVarQueryParams.Encode() - var localVarAPIResponse = &APIResponse{Operation: "Echo_0", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + var localVarAPIResponse = &APIResponse{Operation: "Echo2", Method: localVarHttpMethod, RequestURL: localVarURL.String()} if localVarHttpResponse != nil { localVarAPIResponse.Response = localVarHttpResponse.RawResponse localVarAPIResponse.Payload = localVarHttpResponse.Body() @@ -431,14 +440,15 @@ func (a ABitOfEverythingServiceApi) Echo_1(value string) (*SubStringMessage, *AP } /** - * + * Echo allows posting a StringMessage value. + * It also exposes multiple bindings. This makes it useful when validating that the OpenAPI v2 API description exposes documentation correctly on all paths defined as additional_bindings in the proto. * - * @param body + * @param value * @return *SubStringMessage */ -func (a ABitOfEverythingServiceApi) Echo_2(body string) (*SubStringMessage, *APIResponse, error) { +func (a ABitOfEverythingServiceApi) Echo3(value string) (*SubStringMessage, *APIResponse, error) { - var localVarHttpMethod = strings.ToUpper("Post") + var localVarHttpMethod = strings.ToUpper("Get") // create path and map variables localVarPath := a.Configuration.BasePath + "/v2/example/echo" @@ -452,9 +462,10 @@ func (a ABitOfEverythingServiceApi) Echo_2(body string) (*SubStringMessage, *API for key := range a.Configuration.DefaultHeader { localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] } + localVarQueryParams.Add("value", a.Configuration.APIClient.ParameterToString(value, "")) // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -464,6 +475,7 @@ func (a ABitOfEverythingServiceApi) Echo_2(body string) (*SubStringMessage, *API // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -471,14 +483,12 @@ func (a ABitOfEverythingServiceApi) Echo_2(body string) (*SubStringMessage, *API if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } - // body params - localVarPostBody = &body var successPayload = new(SubStringMessage) localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) var localVarURL, _ = url.Parse(localVarPath) localVarURL.RawQuery = localVarQueryParams.Encode() - var localVarAPIResponse = &APIResponse{Operation: "Echo_1", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + var localVarAPIResponse = &APIResponse{Operation: "Echo3", Method: localVarHttpMethod, RequestURL: localVarURL.String()} if localVarHttpResponse != nil { localVarAPIResponse.Response = localVarHttpResponse.RawResponse localVarAPIResponse.Payload = localVarHttpResponse.Body() @@ -566,7 +576,7 @@ func (a ABitOfEverythingServiceApi) GetQuery(uuid string, singleNestedName strin // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -576,6 +586,7 @@ func (a ABitOfEverythingServiceApi) GetQuery(uuid string, singleNestedName strin // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -626,7 +637,7 @@ func (a ABitOfEverythingServiceApi) Lookup(uuid string) (*ExamplepbABitOfEveryth } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -636,6 +647,7 @@ func (a ABitOfEverythingServiceApi) Lookup(uuid string) (*ExamplepbABitOfEveryth // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -684,7 +696,7 @@ func (a ABitOfEverythingServiceApi) Timeout() (*ProtobufEmpty, *APIResponse, err } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -694,6 +706,7 @@ func (a ABitOfEverythingServiceApi) Timeout() (*ProtobufEmpty, *APIResponse, err // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header @@ -745,7 +758,7 @@ func (a ABitOfEverythingServiceApi) Update(uuid string, body ExamplepbABitOfEver } // to determine the Content-Type header - localVarHttpContentTypes := []string{ "application/json", } + localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", } // set Content-Type header localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) @@ -755,6 +768,7 @@ func (a ABitOfEverythingServiceApi) Update(uuid string, body ExamplepbABitOfEver // to determine the Accept header localVarHttpHeaderAccepts := []string{ "application/json", + "application/x-foo-mime", } // set Accept header diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_client.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_client.go index 2825dd48e1..bf3e21a9fb 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_client.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_client.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_response.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_response.go index 8c14424b57..ee1315f513 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_response.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/api_response.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/configuration.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/configuration.go index 5cacaadcb9..ccc319c34a 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/configuration.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/configuration.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_a_bit_of_everything.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_a_bit_of_everything.go index 338ac37987..d8775d9c86 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_a_bit_of_everything.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_a_bit_of_everything.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_numeric_enum.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_numeric_enum.go index bfb776292b..e953bbe34e 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_numeric_enum.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/examplepb_numeric_enum.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/nested_deep_enum.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/nested_deep_enum.go index 50bf6235a2..e5fc17d50a 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/nested_deep_enum.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/nested_deep_enum.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/protobuf_empty.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/protobuf_empty.go index 0cf664849d..97c7bf612b 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/protobuf_empty.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/protobuf_empty.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/sub_string_message.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/sub_string_message.go index 0331c7abb9..2a0874fc5f 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/sub_string_message.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe/sub_string_message.go @@ -1,10 +1,10 @@ /* - * examples/examplepb/a_bit_of_everything.proto + * A Bit of Everything * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * - * OpenAPI spec version: version not set - * + * OpenAPI spec version: 1.0 + * Contact: none@example.com * Generated by: https://github.com/swagger-api/swagger-codegen.git */ diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo/echo_service_api.go b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo/echo_service_api.go index a37a837adb..1f562327d3 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo/echo_service_api.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo/echo_service_api.go @@ -99,16 +99,20 @@ func (a EchoServiceApi) Echo(id string) (*ExamplepbSimpleMessage, *APIResponse, } /** - * EchoBody method receives a simple message and returns it. + * Echo method receives a simple message and returns it. + * The message posted as the id parameter will also be returned. * - * @param body + * @param id + * @param num * @return *ExamplepbSimpleMessage */ -func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleMessage, *APIResponse, error) { +func (a EchoServiceApi) Echo2(id string, num string) (*ExamplepbSimpleMessage, *APIResponse, error) { - var localVarHttpMethod = strings.ToUpper("Post") + var localVarHttpMethod = strings.ToUpper("Get") // create path and map variables - localVarPath := a.Configuration.BasePath + "/v1/example/echo_body" + localVarPath := a.Configuration.BasePath + "/v1/example/echo/{id}/{num}" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", fmt.Sprintf("%v", id), -1) + localVarPath = strings.Replace(localVarPath, "{"+"num"+"}", fmt.Sprintf("%v", num), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -139,14 +143,12 @@ func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleM if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } - // body params - localVarPostBody = &body var successPayload = new(ExamplepbSimpleMessage) localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) var localVarURL, _ = url.Parse(localVarPath) localVarURL.RawQuery = localVarQueryParams.Encode() - var localVarAPIResponse = &APIResponse{Operation: "EchoBody", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + var localVarAPIResponse = &APIResponse{Operation: "Echo2", Method: localVarHttpMethod, RequestURL: localVarURL.String()} if localVarHttpResponse != nil { localVarAPIResponse.Response = localVarHttpResponse.RawResponse localVarAPIResponse.Payload = localVarHttpResponse.Body() @@ -160,20 +162,16 @@ func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleM } /** - * Echo method receives a simple message and returns it. - * The message posted as the id parameter will also be returned. + * EchoBody method receives a simple message and returns it. * - * @param id - * @param num + * @param body * @return *ExamplepbSimpleMessage */ -func (a EchoServiceApi) Echo_1(id string, num string) (*ExamplepbSimpleMessage, *APIResponse, error) { +func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleMessage, *APIResponse, error) { - var localVarHttpMethod = strings.ToUpper("Get") + var localVarHttpMethod = strings.ToUpper("Post") // create path and map variables - localVarPath := a.Configuration.BasePath + "/v1/example/echo/{id}/{num}" - localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", fmt.Sprintf("%v", id), -1) - localVarPath = strings.Replace(localVarPath, "{"+"num"+"}", fmt.Sprintf("%v", num), -1) + localVarPath := a.Configuration.BasePath + "/v1/example/echo_body" localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -204,12 +202,14 @@ func (a EchoServiceApi) Echo_1(id string, num string) (*ExamplepbSimpleMessage, if localVarHttpHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHttpHeaderAccept } + // body params + localVarPostBody = &body var successPayload = new(ExamplepbSimpleMessage) localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) var localVarURL, _ = url.Parse(localVarPath) localVarURL.RawQuery = localVarQueryParams.Encode() - var localVarAPIResponse = &APIResponse{Operation: "Echo_0", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + var localVarAPIResponse = &APIResponse{Operation: "EchoBody", Method: localVarHttpMethod, RequestURL: localVarURL.String()} if localVarHttpResponse != nil { localVarAPIResponse.Response = localVarHttpResponse.RawResponse localVarAPIResponse.Payload = localVarHttpResponse.Body() diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.go b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.go index 30afc97d2d..2727fba7b0 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.go @@ -12,6 +12,7 @@ import google_protobuf2 "github.com/golang/protobuf/ptypes/duration" import grpc_gateway_examples_sub "github.com/grpc-ecosystem/grpc-gateway/examples/sub" import sub2 "github.com/grpc-ecosystem/grpc-gateway/examples/sub2" import google_protobuf3 "github.com/golang/protobuf/ptypes/timestamp" +import _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options" import ( context "golang.org/x/net/context" @@ -452,6 +453,13 @@ type ABitOfEverythingServiceClient interface { Update(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) Delete(ctx context.Context, in *sub2.IdMessage, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) GetQuery(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) + // Echo allows posting a StringMessage value. + // + // It also exposes multiple bindings. + // + // This makes it useful when validating that the OpenAPI v2 API + // description exposes documentation correctly on all paths + // defined as additional_bindings in the proto. Echo(ctx context.Context, in *grpc_gateway_examples_sub.StringMessage, opts ...grpc.CallOption) (*grpc_gateway_examples_sub.StringMessage, error) DeepPathEcho(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) NoBindings(ctx context.Context, in *google_protobuf2.Duration, opts ...grpc.CallOption) (*google_protobuf1.Empty, error) @@ -565,6 +573,13 @@ type ABitOfEverythingServiceServer interface { Update(context.Context, *ABitOfEverything) (*google_protobuf1.Empty, error) Delete(context.Context, *sub2.IdMessage) (*google_protobuf1.Empty, error) GetQuery(context.Context, *ABitOfEverything) (*google_protobuf1.Empty, error) + // Echo allows posting a StringMessage value. + // + // It also exposes multiple bindings. + // + // This makes it useful when validating that the OpenAPI v2 API + // description exposes documentation correctly on all paths + // defined as additional_bindings in the proto. Echo(context.Context, *grpc_gateway_examples_sub.StringMessage) (*grpc_gateway_examples_sub.StringMessage, error) DeepPathEcho(context.Context, *ABitOfEverything) (*ABitOfEverything, error) NoBindings(context.Context, *google_protobuf2.Duration) (*google_protobuf1.Empty, error) @@ -871,87 +886,105 @@ var _AnotherServiceWithNoBindings_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("examples/examplepb/a_bit_of_everything.proto", fileDescriptor1) } var fileDescriptor1 = []byte{ - // 1297 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x57, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xcf, 0xd8, 0x89, 0x13, 0x3f, 0xc7, 0x89, 0x33, 0x69, 0x53, 0xd7, 0x2d, 0x64, 0x71, 0x01, - 0xad, 0x42, 0xb5, 0xab, 0xba, 0x15, 0x6a, 0x23, 0x41, 0x95, 0x34, 0x86, 0x22, 0xda, 0xb4, 0xdd, - 0xfe, 0x41, 0x8a, 0x5a, 0xac, 0xb5, 0x3d, 0xb6, 0x57, 0xf1, 0xee, 0x2c, 0xbb, 0xb3, 0x26, 0x96, - 0x31, 0x07, 0x0e, 0x5c, 0x38, 0x72, 0xef, 0x05, 0x09, 0x71, 0xe1, 0xc8, 0x19, 0xbe, 0x03, 0x5f, - 0x81, 0x03, 0x1f, 0x03, 0xed, 0xcc, 0xec, 0x76, 0xd7, 0x89, 0xe5, 0x26, 0x45, 0xbd, 0xed, 0xcc, - 0x7b, 0xef, 0xf7, 0x7b, 0x7f, 0xe6, 0xbd, 0x99, 0x85, 0xab, 0xe4, 0xc8, 0xb4, 0xdd, 0x3e, 0xf1, - 0x75, 0xf9, 0xe1, 0x36, 0x75, 0xb3, 0xd1, 0xb4, 0x58, 0x83, 0x76, 0x1a, 0x64, 0x40, 0xbc, 0x21, - 0xeb, 0x59, 0x4e, 0x57, 0x73, 0x3d, 0xca, 0x28, 0xde, 0xec, 0x7a, 0x6e, 0x4b, 0xeb, 0x9a, 0x8c, - 0x7c, 0x6b, 0x0e, 0xb5, 0xc8, 0x54, 0x8b, 0x4d, 0x2b, 0x97, 0xbb, 0x94, 0x76, 0xfb, 0x44, 0x37, - 0x5d, 0x4b, 0x37, 0x1d, 0x87, 0x32, 0x93, 0x59, 0xd4, 0xf1, 0x85, 0x79, 0xe5, 0x92, 0x94, 0xf2, - 0x55, 0x33, 0xe8, 0xe8, 0xc4, 0x76, 0xd9, 0x50, 0x0a, 0xdf, 0x9d, 0x14, 0xb6, 0x03, 0x8f, 0x5b, - 0x4b, 0x79, 0x25, 0xf6, 0xd4, 0x0f, 0x9a, 0xba, 0x4d, 0x7c, 0xdf, 0xec, 0x92, 0x08, 0x38, 0x29, - 0xab, 0x4d, 0x08, 0x37, 0x27, 0x81, 0x99, 0x65, 0x13, 0x9f, 0x99, 0xb6, 0x2b, 0x14, 0xaa, 0x7f, - 0xad, 0x42, 0x69, 0x67, 0xd7, 0x62, 0x0f, 0x3a, 0xf5, 0x38, 0x60, 0xfc, 0x02, 0x8a, 0xbe, 0xe5, - 0x74, 0xfb, 0xa4, 0xe1, 0x10, 0x9f, 0x91, 0x76, 0xf9, 0xa2, 0x82, 0xd4, 0x42, 0xed, 0xa6, 0x36, - 0x23, 0x05, 0xda, 0x24, 0x92, 0xb6, 0xcf, 0xed, 0x8d, 0x65, 0x01, 0x27, 0x56, 0x18, 0xc3, 0x7c, - 0x10, 0x58, 0xed, 0x32, 0x52, 0x90, 0x9a, 0x37, 0x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b, 0xd5, 0x1b, 0x33, 0xcb, 0x9e, 0xfa, 0x0b, 0xd3, - 0xc2, 0x9b, 0x9b, 0x1f, 0xb5, 0x1d, 0x80, 0x7d, 0xba, 0x6b, 0x39, 0x6d, 0xcb, 0xe9, 0xfa, 0xf8, - 0xe2, 0xb1, 0xaa, 0xee, 0xc9, 0xbf, 0xc7, 0xa9, 0x05, 0x9f, 0xc3, 0xcf, 0x60, 0x31, 0x7c, 0x9a, - 0xd0, 0x80, 0xe1, 0x29, 0x4a, 0x53, 0x8d, 0x2f, 0x71, 0xf7, 0xcf, 0xe3, 0xf5, 0x64, 0x3e, 0x99, - 0x00, 0xab, 0x7d, 0x0d, 0x97, 0x77, 0x1c, 0xca, 0x7a, 0xc4, 0x93, 0x17, 0xcc, 0x57, 0x16, 0xeb, - 0x25, 0x9c, 0xfd, 0x34, 0xe5, 0xfa, 0x69, 0xa9, 0xe7, 0x76, 0x0b, 0x07, 0xf9, 0x38, 0xb3, 0xcd, - 0x1c, 0x17, 0x5f, 0xff, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xab, 0xe5, 0x92, 0x0d, 0xc9, 0x0f, 0x00, - 0x00, + // 1590 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x57, 0xcf, 0x6f, 0x1b, 0xc5, + 0x17, 0xcf, 0xd8, 0x89, 0x13, 0x8f, 0xf3, 0xc3, 0x99, 0xb4, 0xa9, 0xeb, 0xe6, 0xfb, 0xcd, 0xd4, + 0x2d, 0x68, 0x15, 0xe2, 0x5d, 0xe2, 0x56, 0xa8, 0xb5, 0x04, 0xc5, 0x49, 0xdc, 0x1f, 0xa2, 0x4d, + 0xdb, 0xed, 0x0f, 0xaa, 0xd0, 0x12, 0xad, 0xed, 0xb1, 0xbd, 0x8d, 0x77, 0x67, 0xd9, 0x9d, 0x4d, + 0x63, 0x19, 0x73, 0xe0, 0x80, 0xd4, 0x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d, 0x5a, 0xd7, + 0xd9, 0xdd, 0x7a, 0x39, 0x4c, 0x0f, 0x7a, 0x06, 0x67, 0x1c, 0xdd, 0x6c, 0xb4, 0xc8, 0x8e, 0x49, + 0x1c, 0x46, 0x6a, 0x99, 0xb3, 0x18, 0x48, 0xa9, 0xc2, 0x15, 0xf9, 0x98, 0x84, 0xc9, 0xfd, 0x4c, + 0xf2, 0x16, 0xb7, 0x57, 0xa7, 0x05, 0x9d, 0x18, 0x21, 0x04, 0xc7, 0x5d, 0x57, 0xaf, 0x65, 0x00, + 0x06, 0x52, 0x52, 0xe5, 0xdf, 0xe8, 0x1e, 0x4c, 0xf8, 0x5a, 0x31, 0x1c, 0x7f, 0x23, 0x2d, 0x9f, + 0x07, 0x2d, 0xc3, 0x54, 0xbd, 0x45, 0x35, 0xb6, 0xb3, 0xa7, 0xb5, 0x5c, 0x92, 0x89, 0x63, 0x20, + 0xc5, 0x54, 0xc8, 0xa7, 0x1e, 0x7b, 0x33, 0xe8, 0x3c, 0x9c, 0xae, 0x51, 0xb7, 0xd2, 0x22, 0x3e, + 0x62, 0x1c, 0x03, 0x09, 0xa8, 0x29, 0x31, 0x27, 0x20, 0xcb, 0x30, 0xa5, 0x9b, 0xec, 0x83, 0xcb, + 0x3e, 0x62, 0x02, 0x03, 0x29, 0xae, 0x42, 0x3e, 0x15, 0x72, 0xb8, 0x51, 0x44, 0x02, 0x03, 0x69, + 0x5c, 0x4d, 0xb9, 0x11, 0x88, 0xe0, 0xb8, 0x54, 0xf0, 0x11, 0x93, 0x18, 0x48, 0x13, 0x9c, 0xe3, + 0x52, 0x41, 0x00, 0x2e, 0xc0, 0x99, 0xba, 0xbe, 0x4f, 0x6a, 0x21, 0xc9, 0x14, 0x06, 0x52, 0x42, + 0x9d, 0xf6, 0x27, 0x7b, 0x41, 0x21, 0x4f, 0x12, 0x03, 0x69, 0xd2, 0x07, 0x05, 0x4c, 0xff, 0x83, + 0xb0, 0x42, 0x69, 0xcb, 0x47, 0x40, 0x0c, 0xa4, 0x29, 0x35, 0xe9, 0xcd, 0x84, 0xce, 0x3a, 0xcc, + 0xd6, 0xcd, 0x86, 0x0f, 0x48, 0xf1, 0xfc, 0xa7, 0xc4, 0x5c, 0x4f, 0x3c, 0xa1, 0xca, 0x0c, 0x06, + 0xd2, 0x8c, 0x88, 0x27, 0x10, 0xf9, 0x04, 0x42, 0x62, 0xba, 0x86, 0x0f, 0x98, 0xc5, 0x40, 0x9a, + 0x2d, 0xac, 0x1e, 0xbb, 0x5b, 0x5b, 0xae, 0x41, 0x6c, 0xbd, 0x5a, 0x36, 0x5d, 0x43, 0x4d, 0x7a, + 0xf6, 0x82, 0xec, 0x1d, 0x38, 0xeb, 0xf4, 0xc6, 0x35, 0x87, 0x81, 0x34, 0xa7, 0xce, 0x38, 0x3d, + 0x81, 0x85, 0xb0, 0x30, 0x47, 0x69, 0x0c, 0xa4, 0x74, 0x00, 0x8b, 0xec, 0x86, 0x13, 0xf5, 0x7e, + 0x1e, 0x03, 0x69, 0x5e, 0x4d, 0x39, 0x11, 0xef, 0x7d, 0x48, 0xc8, 0x83, 0x30, 0x90, 0x90, 0x80, + 0x04, 0x2c, 0x05, 0x78, 0xda, 0x26, 0x16, 0xd1, 0x18, 0xa9, 0xed, 0xf4, 0xe4, 0x6b, 0x01, 0xc7, + 0xa5, 0xa4, 0xba, 0x10, 0x2c, 0x3e, 0x88, 0xe4, 0xed, 0x2a, 0x4c, 0x51, 0x93, 0x78, 0x4d, 0xc6, + 0xeb, 0x01, 0x99, 0x53, 0xbc, 0x5e, 0x16, 0x65, 0x51, 0xab, 0x72, 0x50, 0xab, 0x72, 0xd9, 0x5b, + 0xbd, 0x39, 0xa6, 0x42, 0x0e, 0xe6, 0x23, 0x74, 0x01, 0x4e, 0x0b, 0x53, 0xa1, 0x95, 0x39, 0xed, + 0xed, 0xca, 0xcd, 0x31, 0x55, 0x10, 0x0a, 0x11, 0xf4, 0x14, 0x26, 0x0d, 0xcd, 0xf2, 0xfd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xac, 0x96, 0x5e, 0xe5, 0xa9, 0x54, 0x9e, + 0x3b, 0xd4, 0x2c, 0x2c, 0x46, 0x67, 0xf6, 0xf3, 0x75, 0x4a, 0xf3, 0x86, 0x6e, 0x90, 0xe2, 0x00, + 0xb2, 0x38, 0x04, 0x69, 0xdf, 0x82, 0x67, 0xee, 0x1c, 0xe6, 0x3f, 0x1a, 0xc2, 0xa8, 0xae, 0x6f, + 0x27, 0xc3, 0xd2, 0xa9, 0x24, 0x78, 0xf6, 0x2e, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x88, 0x7d, + 0xbe, 0x6f, 0xd5, 0x12, 0x00, 0x00, } diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.gw.go b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.gw.go index c62dbd038f..25885abd8e 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.gw.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.pb.gw.go @@ -489,7 +489,7 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ABitOfEverythingServiceClient) error { mux.Handle("POST", pattern_ABitOfEverythingService_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -518,7 +518,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("POST", pattern_ABitOfEverythingService_CreateBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -547,7 +547,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("GET", pattern_ABitOfEverythingService_Lookup_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -576,7 +576,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("PUT", pattern_ABitOfEverythingService_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -605,7 +605,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("DELETE", pattern_ABitOfEverythingService_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -634,7 +634,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("GET", pattern_ABitOfEverythingService_GetQuery_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -663,7 +663,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("GET", pattern_ABitOfEverythingService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -692,7 +692,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("POST", pattern_ABitOfEverythingService_Echo_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -721,7 +721,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("GET", pattern_ABitOfEverythingService_Echo_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -750,7 +750,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("POST", pattern_ABitOfEverythingService_DeepPathEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -779,7 +779,7 @@ func RegisterABitOfEverythingServiceHandlerClient(ctx context.Context, mux *runt }) mux.Handle("GET", pattern_ABitOfEverythingService_Timeout_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.proto b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.proto index 91e561e06a..6250bdd438 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.proto +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.proto @@ -8,10 +8,43 @@ import "google/protobuf/duration.proto"; import "examples/sub/message.proto"; import "examples/sub2/message.proto"; import "google/protobuf/timestamp.proto"; +import "protoc-gen-swagger/options/annotations.proto"; + +option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { + info: { + title: "A Bit of Everything"; + version: "1.0"; + contact: { + name: "gRPC-Gateway project"; + url: "https://github.com/grpc-ecosystem/grpc-gateway"; + email: "none@example.com"; + }; + }; + // Overwriting host entry breaks tests, so this is not done here. + external_docs: { + url: "https://github.com/grpc-ecosystem/grpc-gateway"; + description: "More about gRPC-Gateway"; + } + schemes: HTTP; + schemes: HTTPS; + schemes: WSS; + consumes: "application/json"; + consumes: "application/x-foo-mime"; + produces: "application/json"; + produces: "application/x-foo-mime"; +}; + // Intentionaly complicated message type to cover much features of Protobuf. // NEXT ID: 27 message ABitOfEverything { + option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = { + external_docs: { + url: "https://github.com/grpc-ecosystem/grpc-gateway"; + description: "Find out more about ABitOfEverything"; + } + }; + // Nested is nested type. message Nested { // name is nested field. @@ -72,7 +105,18 @@ enum NumericEnum { ONE = 1; } +// ABitOfEverything service is used to validate that APIs with complicated +// proto messages and URL templates are still processed correctly. service ABitOfEverythingService { + + option (grpc.gateway.protoc_gen_swagger.options.openapiv2_tag) = { + description: "ABitOfEverythingService description -- which should not be used in place of the documentation comment!" + external_docs: { + url: "https://github.com/grpc-ecosystem/grpc-gateway"; + description: "Find out more about EchoService"; + } + }; + rpc Create(ABitOfEverything) returns (ABitOfEverything) { // TODO add enum_value option (google.api.http) = { @@ -105,7 +149,21 @@ service ABitOfEverythingService { option (google.api.http) = { get: "/v1/example/a_bit_of_everything/query/{uuid}" }; + option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { + deprecated: true // For testing purposes. + external_docs: { + url: "https://github.com/grpc-ecosystem/grpc-gateway"; + description: "Find out more about GetQuery"; + } + }; } + // Echo allows posting a StringMessage value. + // + // It also exposes multiple bindings. + // + // This makes it useful when validating that the OpenAPI v2 API + // description exposes documentation correctly on all paths + // defined as additional_bindings in the proto. rpc Echo(grpc.gateway.examples.sub.StringMessage) returns (grpc.gateway.examples.sub.StringMessage) { option (google.api.http) = { get: "/v1/example/a_bit_of_everything/echo/{value}" @@ -117,6 +175,12 @@ service ABitOfEverythingService { get: "/v2/example/echo" } }; + option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { + external_docs: { + url: "https://github.com/grpc-ecosystem/grpc-gateway"; + description: "Find out more Echo"; + } + }; } rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) { option (google.api.http) = { diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.swagger.json b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.swagger.json index 052b256b50..c42cd34ed1 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.swagger.json +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/a_bit_of_everything.swagger.json @@ -1,18 +1,26 @@ { "swagger": "2.0", "info": { - "title": "examples/examplepb/a_bit_of_everything.proto", - "version": "version not set" + "title": "A Bit of Everything", + "version": "1.0", + "contact": { + "name": "gRPC-Gateway project", + "url": "https://github.com/grpc-ecosystem/grpc-gateway", + "email": "none@example.com" + } }, "schemes": [ "http", - "https" + "https", + "wss" ], "consumes": [ - "application/json" + "application/json", + "application/x-foo-mime" ], "produces": [ - "application/json" + "application/json", + "application/x-foo-mime" ], "paths": { "/v1/example/a_bit_of_everything": { @@ -43,6 +51,8 @@ }, "/v1/example/a_bit_of_everything/echo/{value}": { "get": { + "summary": "Echo allows posting a StringMessage value.", + "description": "It also exposes multiple bindings.\n\nThis makes it useful when validating that the OpenAPI v2 API\ndescription exposes documentation correctly on all paths\ndefined as additional_bindings in the proto.", "operationId": "Echo", "responses": { "200": { @@ -62,7 +72,11 @@ ], "tags": [ "ABitOfEverythingService" - ] + ], + "externalDocs": { + "description": "Find out more Echo", + "url": "https://github.com/grpc-ecosystem/grpc-gateway" + } } }, "/v1/example/a_bit_of_everything/query/{uuid}": { @@ -264,7 +278,12 @@ ], "tags": [ "ABitOfEverythingService" - ] + ], + "deprecated": true, + "externalDocs": { + "description": "Find out more about GetQuery", + "url": "https://github.com/grpc-ecosystem/grpc-gateway" + } } }, "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}": { @@ -498,7 +517,9 @@ }, "/v2/example/echo": { "get": { - "operationId": "Echo", + "summary": "Echo allows posting a StringMessage value.", + "description": "It also exposes multiple bindings.\n\nThis makes it useful when validating that the OpenAPI v2 API\ndescription exposes documentation correctly on all paths\ndefined as additional_bindings in the proto.", + "operationId": "Echo3", "responses": { "200": { "description": "", @@ -517,10 +538,16 @@ ], "tags": [ "ABitOfEverythingService" - ] + ], + "externalDocs": { + "description": "Find out more Echo", + "url": "https://github.com/grpc-ecosystem/grpc-gateway" + } }, "post": { - "operationId": "Echo", + "summary": "Echo allows posting a StringMessage value.", + "description": "It also exposes multiple bindings.\n\nThis makes it useful when validating that the OpenAPI v2 API\ndescription exposes documentation correctly on all paths\ndefined as additional_bindings in the proto.", + "operationId": "Echo2", "responses": { "200": { "description": "", @@ -541,7 +568,11 @@ ], "tags": [ "ABitOfEverythingService" - ] + ], + "externalDocs": { + "description": "Find out more Echo", + "url": "https://github.com/grpc-ecosystem/grpc-gateway" + } } }, "/v2/example/timeout": { @@ -707,7 +738,11 @@ "title": "repeated enum value. it is comma-separated in query" } }, - "title": "Intentionaly complicated message type to cover much features of Protobuf.\nNEXT ID: 27" + "title": "Intentionaly complicated message type to cover much features of Protobuf.\nNEXT ID: 27", + "externalDocs": { + "description": "Find out more about ABitOfEverything", + "url": "https://github.com/grpc-ecosystem/grpc-gateway" + } }, "examplepbNumericEnum": { "type": "string", @@ -731,5 +766,9 @@ } } } + }, + "externalDocs": { + "description": "More about gRPC-Gateway", + "url": "https://github.com/grpc-ecosystem/grpc-gateway" } } diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.gw.go b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.gw.go index 100b0dd030..654919e659 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.gw.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.pb.gw.go @@ -153,7 +153,7 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn func RegisterEchoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client EchoServiceClient) error { mux.Handle("POST", pattern_EchoService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -182,7 +182,7 @@ func RegisterEchoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux }) mux.Handle("GET", pattern_EchoService_Echo_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -211,7 +211,7 @@ func RegisterEchoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux }) mux.Handle("POST", pattern_EchoService_EchoBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.swagger.json b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.swagger.json index c58fbc54ce..cf61793221 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.swagger.json +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/echo_service.swagger.json @@ -46,7 +46,7 @@ "get": { "summary": "Echo method receives a simple message and returns it.", "description": "The message posted as the id parameter will also be\nreturned.", - "operationId": "Echo", + "operationId": "Echo2", "responses": { "200": { "description": "", diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.gw.go b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.gw.go index a7b9e3b2d5..2f868050ae 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.gw.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/flow_combination.pb.gw.go @@ -1024,7 +1024,7 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.ServeMux, client FlowCombinationClient) error { mux.Handle("POST", pattern_FlowCombination_RpcEmptyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1053,7 +1053,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcEmptyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1082,7 +1082,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_StreamEmptyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1111,7 +1111,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_StreamEmptyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1140,7 +1140,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1169,7 +1169,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1198,7 +1198,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1227,7 +1227,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_3, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1256,7 +1256,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_4, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1285,7 +1285,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_5, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1314,7 +1314,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_6, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1343,7 +1343,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathSingleNestedRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1372,7 +1372,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1401,7 +1401,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1430,7 +1430,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1459,7 +1459,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1488,7 +1488,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1517,7 +1517,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1546,7 +1546,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_3, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1575,7 +1575,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_4, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1604,7 +1604,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_5, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1633,7 +1633,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_6, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1662,7 +1662,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathSingleNestedStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1691,7 +1691,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1720,7 +1720,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -1749,7 +1749,7 @@ func RegisterFlowCombinationHandlerClient(ctx context.Context, mux *runtime.Serv }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { diff --git a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.gw.go b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.gw.go index 91a9065f4b..3ef9faacd6 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.gw.go +++ b/github.com/grpc-ecosystem/grpc-gateway/examples/examplepb/stream.pb.gw.go @@ -179,7 +179,7 @@ func RegisterStreamServiceHandler(ctx context.Context, mux *runtime.ServeMux, co func RegisterStreamServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client StreamServiceClient) error { mux.Handle("POST", pattern_StreamService_BulkCreate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -208,7 +208,7 @@ func RegisterStreamServiceHandlerClient(ctx context.Context, mux *runtime.ServeM }) mux.Handle("GET", pattern_StreamService_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -237,7 +237,7 @@ func RegisterStreamServiceHandlerClient(ctx context.Context, mux *runtime.ServeM }) mux.Handle("POST", pattern_StreamService_BulkEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/registry.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/registry.go index 9e4f3428dd..61d6eb9bc7 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/registry.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/registry.go @@ -25,6 +25,9 @@ type Registry struct { // prefix is a prefix to be inserted to golang package paths generated from proto package names. prefix string + // importPath is used as the package if no input files declare go_package. If it contains slashes, everything up to the rightmost slash is ignored. + importPath string + // pkgMap is a user-specified mapping from file path to proto package. pkgMap map[string]string @@ -212,6 +215,13 @@ func (r *Registry) SetPrefix(prefix string) { r.prefix = prefix } +// SetImportPath registers the importPath which is used as the package if no +// input files declare go_package. If it contains slashes, everything up to the +// rightmost slash is ignored. +func (r *Registry) SetImportPath(importPath string) { + r.importPath = importPath +} + // ReserveGoPackageAlias reserves the unique alias of go package. // If succeeded, the alias will be never used for other packages in generated go files. // If failed, the alias is already taken by another package, so you need to use another @@ -237,6 +247,9 @@ func (r *Registry) goPackagePath(f *descriptor.FileDescriptorProto) string { } gopkg := f.Options.GetGoPackage() + if len(gopkg) == 0 { + gopkg = r.importPath + } idx := strings.LastIndex(gopkg, "/") if idx >= 0 { if sc := strings.LastIndex(gopkg, ";"); sc > 0 { diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go index c9dfec8e04..a62bd06fe1 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/services.go @@ -194,7 +194,12 @@ func (r *Registry) newParam(meth *Method, path string) (Parameter, error) { target := fields[l-1].Target switch target.GetType() { case descriptor.FieldDescriptorProto_TYPE_MESSAGE, descriptor.FieldDescriptorProto_TYPE_GROUP: - return Parameter{}, fmt.Errorf("aggregate type %s in parameter of %s.%s: %s", target.Type, meth.Service.GetName(), meth.GetName(), path) + glog.V(2).Infoln("found aggregate type:", target, target.TypeName) + if IsWellKnownType(*target.TypeName) { + glog.V(2).Infoln("found well known aggregate type:", target) + } else { + return Parameter{}, fmt.Errorf("aggregate type %s in parameter of %s.%s: %s", target.Type, meth.Service.GetName(), meth.GetName(), path) + } } return Parameter{ FieldPath: FieldPath(fields), diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/types.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/types.go index 248538e7ba..c24bd61c89 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/types.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor/types.go @@ -9,6 +9,12 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule" ) +// IsWellKnownType returns true if the provided fully qualified type name is considered 'well-known'. +func IsWellKnownType(typeName string) bool { + _, ok := wellKnownTypeConv[typeName] + return ok +} + // GoPackage represents a golang package type GoPackage struct { // Path is the package path to the package. @@ -194,6 +200,9 @@ func (p Parameter) ConvertFuncExpr() (string, error) { } typ := p.Target.GetType() conv, ok := tbl[typ] + if !ok { + conv, ok = wellKnownTypeConv[p.Target.GetTypeName()] + } if !ok { return "", fmt.Errorf("unsupported field type %s of parameter %s in %s.%s", typ, p.FieldPath, p.Method.Service.GetName(), p.Method.GetName()) } @@ -319,4 +328,9 @@ var ( descriptor.FieldDescriptorProto_TYPE_SINT32: "runtime.Int32P", descriptor.FieldDescriptorProto_TYPE_SINT64: "runtime.Int64P", } + + wellKnownTypeConv = map[string]string{ + ".google.protobuf.Timestamp": "runtime.Timestamp", + ".google.protobuf.Duration": "runtime.Duration", + } ) diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator.go index d08609bc72..cb2f5e14a9 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator.go @@ -78,6 +78,9 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*plugin.CodeGenerato return nil, err } name := file.GetName() + if file.GoPkg.Path != "" { + name = fmt.Sprintf("%s/%s", file.GoPkg.Path, filepath.Base(name)) + } ext := filepath.Ext(name) base := strings.TrimSuffix(name, ext) output := fmt.Sprintf("%s.pb.gw.go", base) diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator_test.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator_test.go index 755a09236e..986ff4151e 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator_test.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator_test.go @@ -1,6 +1,7 @@ package gengateway import ( + "path/filepath" "strings" "testing" @@ -9,7 +10,16 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor" ) -func TestGenerateServiceWithoutBindings(t *testing.T) { +func newExampleFileDescriptor() *descriptor.File { + return newExampleFileDescriptorWithGoPkg( + &descriptor.GoPackage{ + Path: "example.com/path/to/example/example.pb", + Name: "example_pb", + }, + ) +} + +func newExampleFileDescriptorWithGoPkg(gp *descriptor.GoPackage) *descriptor.File { msgdesc := &protodescriptor.DescriptorProto{ Name: proto.String("ExampleMessage"), } @@ -39,7 +49,7 @@ func TestGenerateServiceWithoutBindings(t *testing.T) { Name: proto.String("ExampleService"), Method: []*protodescriptor.MethodDescriptorProto{meth, meth1}, } - file := descriptor.File{ + return &descriptor.File{ FileDescriptorProto: &protodescriptor.FileDescriptorProto{ Name: proto.String("example.proto"), Package: proto.String("example"), @@ -47,10 +57,7 @@ func TestGenerateServiceWithoutBindings(t *testing.T) { MessageType: []*protodescriptor.DescriptorProto{msgdesc}, Service: []*protodescriptor.ServiceDescriptorProto{svc}, }, - GoPkg: descriptor.GoPackage{ - Path: "example.com/path/to/example/example.pb", - Name: "example_pb", - }, + GoPkg: *gp, Messages: []*descriptor.Message{msg}, Services: []*descriptor.Service{ { @@ -76,8 +83,12 @@ func TestGenerateServiceWithoutBindings(t *testing.T) { }, }, } +} + +func TestGenerateServiceWithoutBindings(t *testing.T) { + file := newExampleFileDescriptor() g := &generator{} - got, err := g.generate(crossLinkFixture(&file)) + got, err := g.generate(crossLinkFixture(file)) if err != nil { t.Errorf("generate(%#v) failed with %v; want success", file, err) return @@ -86,3 +97,57 @@ func TestGenerateServiceWithoutBindings(t *testing.T) { t.Errorf("generate(%#v) = %s; does not want to contain %s", file, got, notwanted) } } + +func TestGenerateOutputPath(t *testing.T) { + cases := []struct { + file *descriptor.File + expected string + }{ + { + file: newExampleFileDescriptorWithGoPkg( + &descriptor.GoPackage{ + Path: "example.com/path/to/example", + Name: "example_pb", + }, + ), + expected: "example.com/path/to/example", + }, + { + file: newExampleFileDescriptorWithGoPkg( + &descriptor.GoPackage{ + Path: "example", + Name: "example_pb", + }, + ), + expected: "example", + }, + } + + g := &generator{} + for _, c := range cases { + file := c.file + gots, err := g.Generate([]*descriptor.File{crossLinkFixture(file)}) + if err != nil { + t.Errorf("Generate(%#v) failed with %v; wants success", file, err) + return + } + + if len(gots) != 1 { + t.Errorf("Generate(%#v) failed; expects on result got %d", file, len(gots)) + return + } + + got := gots[0] + if got.Name == nil { + t.Errorf("Generate(%#v) failed; expects non-nil Name(%v)", file, got.Name) + return + } + + gotPath := filepath.Dir(*got.Name) + expectedPath := c.expected + if gotPath != expectedPath { + t.Errorf("Generate(%#v) failed; got path: %s expected path: %s", file, gotPath, expectedPath) + return + } + } +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go index cf365f249e..4b875d51b3 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go @@ -24,7 +24,8 @@ import ( var ( importPrefix = flag.String("import_prefix", "", "prefix to be added to go package paths for imported proto files") - useRequestContext = flag.Bool("request_context", false, "determine whether to use http.Request's context or not") + importPath = flag.String("import_path", "", "used as the package if no input files declare go_package. If it contains slashes, everything up to the rightmost slash is ignored.") + useRequestContext = flag.Bool("request_context", true, "determine whether to use http.Request's context or not") allowDeleteBody = flag.Bool("allow_delete_body", false, "unless set, HTTP DELETE methods may not have a body") ) @@ -78,6 +79,7 @@ func main() { g := gengateway.New(reg, *useRequestContext) reg.SetPrefix(*importPrefix) + reg.SetImportPath(*importPath) reg.SetAllowDeleteBody(*allowDeleteBody) if err := reg.Load(req); err != nil { emitError(err) diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go index a7ef682ea8..bf671963ef 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go @@ -11,10 +11,22 @@ import ( "strings" "sync" + "github.com/golang/protobuf/proto" pbdescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor" + swagger_options "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options" ) +var wktSchemas = map[string]schemaCore{ + ".google.protobuf.Timestamp": schemaCore{ + Type: "string", + Format: "date-time", + }, + ".google.protobuf.Duration": schemaCore{ + Type: "string", + }, +} + func listEnumNames(enum *descriptor.Enum) (names []string) { for _, value := range enum.GetValue() { names = append(names, value.GetName()) @@ -163,6 +175,8 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, switch name { case ".google.protobuf.Timestamp": continue + case ".google.protobuf.Duration": + continue } if opt := msg.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry { continue @@ -176,6 +190,25 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, if err := updateSwaggerDataFromComments(&schema, msgComments); err != nil { panic(err) } + opts, err := extractSchemaOptionFromMessageDescriptor(msg.DescriptorProto) + if err != nil { + panic(err) + } + if opts != nil { + if opts.ExternalDocs != nil { + if schema.ExternalDocs == nil { + schema.ExternalDocs = &swaggerExternalDocumentationObject{} + } + if opts.ExternalDocs.Description != "" { + schema.ExternalDocs.Description = opts.ExternalDocs.Description + } + if opts.ExternalDocs.Url != "" { + schema.ExternalDocs.URL = opts.ExternalDocs.Url + } + } + + // TODO(ivucica): add remaining fields of schema object + } for _, f := range msg.Fields { fieldValue := schemaOfField(f, reg) @@ -215,11 +248,8 @@ func schemaOfField(f *descriptor.Field, reg *descriptor.Registry) swaggerSchemaO switch ft := fd.GetType(); ft { case pbdescriptor.FieldDescriptorProto_TYPE_ENUM, pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE, pbdescriptor.FieldDescriptorProto_TYPE_GROUP: - if fd.GetTypeName() == ".google.protobuf.Timestamp" && pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE == ft { - core = schemaCore{ - Type: "string", - Format: "date-time", - } + if wktSchema, ok := wktSchemas[fd.GetTypeName()]; ok { + core = wktSchema } else { core = schemaCore{ Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(fd.GetTypeName(), reg), @@ -452,7 +482,7 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re // Correctness of svcIdx and methIdx depends on 'services' containing the services in the same order as the 'file.Service' array. for svcIdx, svc := range services { for methIdx, meth := range svc.Methods { - for _, b := range meth.Bindings { + for bIdx, b := range meth.Bindings { // Iterate over all the swagger parameters parameters := swaggerParametersObject{} for _, parameter := range b.PathParams { @@ -460,7 +490,13 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re var paramType, paramFormat string switch pt := parameter.Target.GetType(); pt { case pbdescriptor.FieldDescriptorProto_TYPE_GROUP, pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE: - return fmt.Errorf("only primitive types are allowed in path parameters") + if descriptor.IsWellKnownType(parameter.Target.GetTypeName()) { + schema := schemaOfField(parameter.Target, reg) + paramType = schema.Type + paramFormat = schema.Format + } else { + return fmt.Errorf("only primitive and well-known types are allowed in path parameters") + } case pbdescriptor.FieldDescriptorProto_TYPE_ENUM: paramType = fullyQualifiedNameToSwaggerName(parameter.Target.GetTypeName(), reg) paramFormat = "" @@ -527,9 +563,8 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re desc += "(streaming responses)" } operationObject := &swaggerOperationObject{ - Tags: []string{svc.GetName()}, - OperationID: fmt.Sprintf("%s", meth.GetName()), - Parameters: parameters, + Tags: []string{svc.GetName()}, + Parameters: parameters, Responses: swaggerResponsesObject{ "200": swaggerResponseObject{ Description: desc, @@ -541,6 +576,12 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re }, }, } + if bIdx == 0 { + operationObject.OperationID = fmt.Sprintf("%s", meth.GetName()) + } else { + // OperationID must be unique in an OpenAPI v2 definition. + operationObject.OperationID = fmt.Sprintf("%s%d", meth.GetName(), bIdx+1) + } // Fill reference map with referenced request messages for _, param := range operationObject.Parameters { @@ -554,6 +595,28 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re panic(err) } + opts, err := extractOperationOptionFromMethodDescriptor(meth.MethodDescriptorProto) + if opts != nil { + if err != nil { + panic(err) + } + if opts.ExternalDocs != nil { + if operationObject.ExternalDocs == nil { + operationObject.ExternalDocs = &swaggerExternalDocumentationObject{} + } + if opts.ExternalDocs.Description != "" { + operationObject.ExternalDocs.Description = opts.ExternalDocs.Description + } + if opts.ExternalDocs.Url != "" { + operationObject.ExternalDocs.URL = opts.ExternalDocs.Url + } + } + // TODO(ivucica): this would be better supported by looking whether the method is deprecated in the proto file + operationObject.Deprecated = opts.Deprecated + + // TODO(ivucica): add remaining fields of operation object + } + switch b.HTTPMethod { case "DELETE": pathItemObject.Delete = operationObject @@ -620,6 +683,73 @@ func applyTemplate(p param) (string, error) { panic(err) } + // There may be additional options in the swagger option in the proto. + spb, err := extractSwaggerOptionFromFileDescriptor(p.FileDescriptorProto) + if err != nil { + panic(err) + } + if spb != nil { + if spb.Swagger != "" { + s.Swagger = spb.Swagger + } + if spb.Info != nil { + if spb.Info.Title != "" { + s.Info.Title = spb.Info.Title + } + if spb.Info.Version != "" { + s.Info.Version = spb.Info.Version + } + if spb.Info.Contact != nil { + if s.Info.Contact == nil { + s.Info.Contact = &swaggerContactObject{} + } + if spb.Info.Contact.Name != "" { + s.Info.Contact.Name = spb.Info.Contact.Name + } + if spb.Info.Contact.Url != "" { + s.Info.Contact.URL = spb.Info.Contact.Url + } + if spb.Info.Contact.Email != "" { + s.Info.Contact.Email = spb.Info.Contact.Email + } + } + } + if spb.Host != "" { + s.Host = spb.Host + } + if spb.BasePath != "" { + s.BasePath = spb.BasePath + } + if len(spb.Schemes) > 0 { + s.Schemes = make([]string, len(spb.Schemes)) + for i, scheme := range spb.Schemes { + s.Schemes[i] = strings.ToLower(scheme.String()) + } + } + if len(spb.Consumes) > 0 { + s.Consumes = make([]string, len(spb.Consumes)) + copy(s.Consumes, spb.Consumes) + } + if len(spb.Produces) > 0 { + s.Produces = make([]string, len(spb.Produces)) + copy(s.Produces, spb.Produces) + } + if spb.ExternalDocs != nil { + if s.ExternalDocs == nil { + s.ExternalDocs = &swaggerExternalDocumentationObject{} + } + if spb.ExternalDocs.Description != "" { + s.ExternalDocs.Description = spb.ExternalDocs.Description + } + if spb.ExternalDocs.Url != "" { + s.ExternalDocs.URL = spb.ExternalDocs.Url + } + } + + // Additional fields on the OpenAPI v2 spec's "Swagger" object + // should be added here, once supported in the proto. + } + // We now have rendered the entire swagger object. Write the bytes out to a // string so it can be written to disk. var w bytes.Buffer @@ -632,9 +762,9 @@ func applyTemplate(p param) (string, error) { // updateSwaggerDataFromComments updates a Swagger object based on a comment // from the proto file. // -// First paragraph of a comment is used for summary. Remaining paragraphs of a -// comment are used for description. If 'Summary' field is not present on the -// passed swaggerObject, the summary and description are joined by \n\n. +// First paragraph of a comment is used for summary. Remaining paragraphs of +// a comment are used for description. If 'Summary' field is not present on +// the passed swaggerObject, the summary and description are joined by \n\n. // // If there is a field named 'Info', its 'Summary' and 'Description' fields // will be updated instead. @@ -664,17 +794,15 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) er usingTitle = true } + paragraphs := strings.Split(comment, "\n\n") + // If there is a summary (or summary-equivalent), use the first // paragraph as summary, and the rest as description. if summaryValue.CanSet() { - paragraphs := strings.Split(comment, "\n\n") - summary := strings.TrimSpace(paragraphs[0]) description := strings.TrimSpace(strings.Join(paragraphs[1:], "\n\n")) - if !usingTitle || summary == "" || summary[len(summary)-1] != '.' { - if len(summary) > 0 { - summaryValue.Set(reflect.ValueOf(summary)) - } + if !usingTitle || (len(summary) > 0 && summary[len(summary)-1] != '.') { + summaryValue.Set(reflect.ValueOf(summary)) if len(description) > 0 { if !descriptionValue.CanSet() { return fmt.Errorf("Encountered object type with a summary, but no description") @@ -688,7 +816,7 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) er // There was no summary field on the swaggerObject. Try to apply the // whole comment into description. if descriptionValue.CanSet() { - descriptionValue.Set(reflect.ValueOf(comment)) + descriptionValue.Set(reflect.ValueOf(strings.Join(paragraphs, "\n\n"))) return nil } @@ -854,3 +982,63 @@ func protoPathIndex(descriptorType reflect.Type, what string) int32 { return int32(path) } + +// extractOperationOptionFromMethodDescriptor extracts the message of type +// swagger_options.Operation from a given proto method's descriptor. +func extractOperationOptionFromMethodDescriptor(meth *pbdescriptor.MethodDescriptorProto) (*swagger_options.Operation, error) { + if meth.Options == nil { + return nil, nil + } + if !proto.HasExtension(meth.Options, swagger_options.E_Openapiv2Operation) { + return nil, nil + } + ext, err := proto.GetExtension(meth.Options, swagger_options.E_Openapiv2Operation) + if err != nil { + return nil, err + } + opts, ok := ext.(*swagger_options.Operation) + if !ok { + return nil, fmt.Errorf("extension is %T; want an Operation", ext) + } + return opts, nil +} + +// extractSchemaOptionFromMessageDescriptor extracts the message of type +// swagger_options.Schema from a given proto message's descriptor. +func extractSchemaOptionFromMessageDescriptor(msg *pbdescriptor.DescriptorProto) (*swagger_options.Schema, error) { + if msg.Options == nil { + return nil, nil + } + if !proto.HasExtension(msg.Options, swagger_options.E_Openapiv2Schema) { + return nil, nil + } + ext, err := proto.GetExtension(msg.Options, swagger_options.E_Openapiv2Schema) + if err != nil { + return nil, err + } + opts, ok := ext.(*swagger_options.Schema) + if !ok { + return nil, fmt.Errorf("extension is %T; want a Schema", ext) + } + return opts, nil +} + +// extractSwaggerOptionFromFileDescriptor extracts the message of type +// swagger_options.Swagger from a given proto method's descriptor. +func extractSwaggerOptionFromFileDescriptor(file *pbdescriptor.FileDescriptorProto) (*swagger_options.Swagger, error) { + if file.Options == nil { + return nil, nil + } + if !proto.HasExtension(file.Options, swagger_options.E_Openapiv2Swagger) { + return nil, nil + } + ext, err := proto.GetExtension(file.Options, swagger_options.E_Openapiv2Swagger) + if err != nil { + return nil, err + } + opts, ok := ext.(*swagger_options.Swagger) + if !ok { + return nil, fmt.Errorf("extension is %T; want a Swagger object", ext) + } + return opts, nil +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/types.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/types.go index c328d1c60c..7263e66b7e 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/types.go +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/types.go @@ -23,9 +23,8 @@ type swaggerInfoObject struct { TermsOfService string `json:"termsOfService,omitempty"` Version string `json:"version"` - Contact *swaggerContactObject `json:"contact,omitempty"` - License *swaggerLicenseObject `json:"license,omitempty"` - ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"` + Contact *swaggerContactObject `json:"contact,omitempty"` + License *swaggerLicenseObject `json:"license,omitempty"` } // http://swagger.io/specification/#contactObject @@ -49,15 +48,16 @@ type swaggerExternalDocumentationObject struct { // http://swagger.io/specification/#swaggerObject type swaggerObject struct { - Swagger string `json:"swagger"` - Info swaggerInfoObject `json:"info"` - Host string `json:"host,omitempty"` - BasePath string `json:"basePath,omitempty"` - Schemes []string `json:"schemes"` - Consumes []string `json:"consumes"` - Produces []string `json:"produces"` - Paths swaggerPathsObject `json:"paths"` - Definitions swaggerDefinitionsObject `json:"definitions"` + Swagger string `json:"swagger"` + Info swaggerInfoObject `json:"info"` + Host string `json:"host,omitempty"` + BasePath string `json:"basePath,omitempty"` + Schemes []string `json:"schemes"` + Consumes []string `json:"consumes"` + Produces []string `json:"produces"` + Paths swaggerPathsObject `json:"paths"` + Definitions swaggerDefinitionsObject `json:"definitions"` + ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"` } // http://swagger.io/specification/#pathsObject @@ -80,6 +80,7 @@ type swaggerOperationObject struct { Responses swaggerResponsesObject `json:"responses"` Parameters swaggerParametersObject `json:"parameters,omitempty"` Tags []string `json:"tags,omitempty"` + Deprecated bool `json:"deprecated,omitempty"` ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"` } @@ -170,6 +171,8 @@ type swaggerSchemaObject struct { Description string `json:"description,omitempty"` Title string `json:"title,omitempty"` + + ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"` } // http://swagger.io/specification/#referenceObject diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/annotations.pb.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/annotations.pb.go new file mode 100644 index 0000000000..7bc93b91c6 --- /dev/null +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/annotations.pb.go @@ -0,0 +1,83 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: protoc-gen-swagger/options/annotations.proto + +package options + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import google_protobuf1 "github.com/golang/protobuf/protoc-gen-go/descriptor" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +var E_Openapiv2Swagger = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf1.FileOptions)(nil), + ExtensionType: (*Swagger)(nil), + Field: 1042, + Name: "grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger", + Tag: "bytes,1042,opt,name=openapiv2_swagger,json=openapiv2Swagger", + Filename: "protoc-gen-swagger/options/annotations.proto", +} + +var E_Openapiv2Operation = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf1.MethodOptions)(nil), + ExtensionType: (*Operation)(nil), + Field: 1042, + Name: "grpc.gateway.protoc_gen_swagger.options.openapiv2_operation", + Tag: "bytes,1042,opt,name=openapiv2_operation,json=openapiv2Operation", + Filename: "protoc-gen-swagger/options/annotations.proto", +} + +var E_Openapiv2Schema = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf1.MessageOptions)(nil), + ExtensionType: (*Schema)(nil), + Field: 1042, + Name: "grpc.gateway.protoc_gen_swagger.options.openapiv2_schema", + Tag: "bytes,1042,opt,name=openapiv2_schema,json=openapiv2Schema", + Filename: "protoc-gen-swagger/options/annotations.proto", +} + +var E_Openapiv2Tag = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf1.ServiceOptions)(nil), + ExtensionType: (*Tag)(nil), + Field: 1042, + Name: "grpc.gateway.protoc_gen_swagger.options.openapiv2_tag", + Tag: "bytes,1042,opt,name=openapiv2_tag,json=openapiv2Tag", + Filename: "protoc-gen-swagger/options/annotations.proto", +} + +func init() { + proto.RegisterExtension(E_Openapiv2Swagger) + proto.RegisterExtension(E_Openapiv2Operation) + proto.RegisterExtension(E_Openapiv2Schema) + proto.RegisterExtension(E_Openapiv2Tag) +} + +func init() { proto.RegisterFile("protoc-gen-swagger/options/annotations.proto", fileDescriptor1) } + +var fileDescriptor1 = []byte{ + // 311 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x4b, 0x03, 0x31, + 0x10, 0x85, 0xe9, 0x45, 0x64, 0x55, 0xac, 0xeb, 0x45, 0x8a, 0x68, 0x6f, 0x8a, 0xb4, 0x89, 0xd4, + 0xdb, 0xde, 0x54, 0xf0, 0x26, 0x85, 0x6d, 0x4f, 0x5e, 0x4a, 0x9a, 0x8e, 0xd3, 0x40, 0x9b, 0x09, + 0x49, 0xda, 0x52, 0xe8, 0xd1, 0x5f, 0xe0, 0x2f, 0x16, 0x93, 0xed, 0x56, 0xd6, 0x2a, 0x7b, 0xdb, + 0x99, 0x9d, 0xf7, 0xbe, 0xc7, 0x23, 0x49, 0xc7, 0x58, 0xf2, 0x24, 0xbb, 0x08, 0xba, 0xeb, 0x56, + 0x02, 0x11, 0x2c, 0x27, 0xe3, 0x15, 0x69, 0xc7, 0x85, 0xd6, 0xe4, 0x45, 0xf8, 0x66, 0xe1, 0x2c, + 0xbd, 0x41, 0x6b, 0x24, 0x43, 0xe1, 0x61, 0x25, 0xd6, 0x71, 0x27, 0x47, 0x08, 0x7a, 0x54, 0x48, + 0x59, 0x21, 0x6d, 0xdd, 0xfd, 0x63, 0x4b, 0x06, 0xb4, 0x30, 0x6a, 0xd9, 0x8b, 0x06, 0xad, 0x36, + 0x12, 0xe1, 0x0c, 0x78, 0x98, 0xc6, 0x8b, 0x77, 0x3e, 0x01, 0x27, 0xad, 0x32, 0x9e, 0x6c, 0xbc, + 0xc8, 0x36, 0xc9, 0x59, 0x29, 0xda, 0xa2, 0xd2, 0x4b, 0x16, 0x75, 0x6c, 0xab, 0x63, 0x2f, 0x6a, + 0x06, 0xfd, 0x08, 0xb9, 0xf8, 0x3c, 0x6c, 0x37, 0x6e, 0x8f, 0x7a, 0xf7, 0xac, 0x66, 0x62, 0x36, + 0x88, 0x73, 0xde, 0x2c, 0x49, 0xc5, 0x26, 0xfb, 0x68, 0x24, 0xe7, 0x3b, 0x3c, 0x19, 0xb0, 0xa1, + 0x93, 0xf4, 0xea, 0x57, 0x80, 0x57, 0xf0, 0x53, 0x9a, 0x54, 0x22, 0xf4, 0x6a, 0x47, 0xe8, 0x6f, + 0xad, 0xf3, 0xb4, 0xe4, 0x95, 0xbb, 0x6c, 0x93, 0x34, 0x7f, 0x94, 0x20, 0xa7, 0x30, 0x17, 0xe9, + 0xf5, 0x9e, 0x08, 0xce, 0x09, 0xac, 0xd6, 0xc0, 0xeb, 0xd7, 0x10, 0x8c, 0xf3, 0xd3, 0x5d, 0x0b, + 0x61, 0x91, 0xb9, 0xe4, 0x64, 0x47, 0xf7, 0x02, 0xf7, 0xa0, 0x07, 0x60, 0x97, 0x4a, 0x56, 0xd1, + 0x9d, 0xda, 0xe8, 0xa1, 0xc0, 0xfc, 0xb8, 0x84, 0x0c, 0x05, 0x3e, 0x3d, 0xbf, 0x3d, 0xa2, 0xf2, + 0xd3, 0xc5, 0x98, 0x49, 0x9a, 0xf3, 0x6f, 0x9f, 0x2e, 0x48, 0x72, 0x6b, 0xe7, 0xa1, 0x18, 0x0b, + 0x5b, 0xfe, 0xf7, 0x73, 0x1b, 0x1f, 0x84, 0x7f, 0x0f, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x80, + 0x7f, 0xc1, 0x6a, 0xea, 0x02, 0x00, 0x00, +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/annotations.proto b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/annotations.proto new file mode 100644 index 0000000000..8746192b7a --- /dev/null +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/annotations.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package grpc.gateway.protoc_gen_swagger.options; + +option go_package = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options"; + +import "protoc-gen-swagger/options/openapiv2.proto"; +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FileOptions { + // ID assigned by protobuf-global-extension-registry@google.com for grpc-gateway project. + // + // All IDs are the same, as assigned. It is okay that they are the same, as they extend + // different descriptor messages. + Swagger openapiv2_swagger = 1042; +} +extend google.protobuf.MethodOptions { + // ID assigned by protobuf-global-extension-registry@google.com for grpc-gateway project. + // + // All IDs are the same, as assigned. It is okay that they are the same, as they extend + // different descriptor messages. + Operation openapiv2_operation = 1042; +} +extend google.protobuf.MessageOptions { + // ID assigned by protobuf-global-extension-registry@google.com for grpc-gateway project. + // + // All IDs are the same, as assigned. It is okay that they are the same, as they extend + // different descriptor messages. + Schema openapiv2_schema = 1042; +} +extend google.protobuf.ServiceOptions { + // ID assigned by protobuf-global-extension-registry@google.com for grpc-gateway project. + // + // All IDs are the same, as assigned. It is okay that they are the same, as they extend + // different descriptor messages. + Tag openapiv2_tag = 1042; +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/openapiv2.pb.go b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/openapiv2.pb.go new file mode 100644 index 0000000000..7564c52e50 --- /dev/null +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/openapiv2.pb.go @@ -0,0 +1,739 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: protoc-gen-swagger/options/openapiv2.proto + +/* +Package options is a generated protocol buffer package. + +It is generated from these files: + protoc-gen-swagger/options/openapiv2.proto + protoc-gen-swagger/options/annotations.proto + +It has these top-level messages: + Swagger + Operation + Info + Contact + ExternalDocumentation + Schema + JSONSchema + Tag +*/ +package options + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import google_protobuf "github.com/golang/protobuf/ptypes/any" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type Swagger_SwaggerScheme int32 + +const ( + Swagger_UNKNOWN Swagger_SwaggerScheme = 0 + Swagger_HTTP Swagger_SwaggerScheme = 1 + Swagger_HTTPS Swagger_SwaggerScheme = 2 + Swagger_WS Swagger_SwaggerScheme = 3 + Swagger_WSS Swagger_SwaggerScheme = 4 +) + +var Swagger_SwaggerScheme_name = map[int32]string{ + 0: "UNKNOWN", + 1: "HTTP", + 2: "HTTPS", + 3: "WS", + 4: "WSS", +} +var Swagger_SwaggerScheme_value = map[string]int32{ + "UNKNOWN": 0, + "HTTP": 1, + "HTTPS": 2, + "WS": 3, + "WSS": 4, +} + +func (x Swagger_SwaggerScheme) String() string { + return proto.EnumName(Swagger_SwaggerScheme_name, int32(x)) +} +func (Swagger_SwaggerScheme) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0, 0} } + +type JSONSchema_JSONSchemaSimpleTypes int32 + +const ( + JSONSchema_UNKNOWN JSONSchema_JSONSchemaSimpleTypes = 0 + JSONSchema_ARRAY JSONSchema_JSONSchemaSimpleTypes = 1 + JSONSchema_BOOLEAN JSONSchema_JSONSchemaSimpleTypes = 2 + JSONSchema_INTEGER JSONSchema_JSONSchemaSimpleTypes = 3 + JSONSchema_NULL JSONSchema_JSONSchemaSimpleTypes = 4 + JSONSchema_NUMBER JSONSchema_JSONSchemaSimpleTypes = 5 + JSONSchema_OBJECT JSONSchema_JSONSchemaSimpleTypes = 6 + JSONSchema_STRING JSONSchema_JSONSchemaSimpleTypes = 7 +) + +var JSONSchema_JSONSchemaSimpleTypes_name = map[int32]string{ + 0: "UNKNOWN", + 1: "ARRAY", + 2: "BOOLEAN", + 3: "INTEGER", + 4: "NULL", + 5: "NUMBER", + 6: "OBJECT", + 7: "STRING", +} +var JSONSchema_JSONSchemaSimpleTypes_value = map[string]int32{ + "UNKNOWN": 0, + "ARRAY": 1, + "BOOLEAN": 2, + "INTEGER": 3, + "NULL": 4, + "NUMBER": 5, + "OBJECT": 6, + "STRING": 7, +} + +func (x JSONSchema_JSONSchemaSimpleTypes) String() string { + return proto.EnumName(JSONSchema_JSONSchemaSimpleTypes_name, int32(x)) +} +func (JSONSchema_JSONSchemaSimpleTypes) EnumDescriptor() ([]byte, []int) { + return fileDescriptor0, []int{6, 0} +} + +// `Swagger` is a representation of OpenAPI v2 specification's Swagger object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#swaggerObject +// +// TODO(ivucica): document fields +type Swagger struct { + Swagger string `protobuf:"bytes,1,opt,name=swagger" json:"swagger,omitempty"` + Info *Info `protobuf:"bytes,2,opt,name=info" json:"info,omitempty"` + Host string `protobuf:"bytes,3,opt,name=host" json:"host,omitempty"` + BasePath string `protobuf:"bytes,4,opt,name=base_path,json=basePath" json:"base_path,omitempty"` + Schemes []Swagger_SwaggerScheme `protobuf:"varint,5,rep,packed,name=schemes,enum=grpc.gateway.protoc_gen_swagger.options.Swagger_SwaggerScheme" json:"schemes,omitempty"` + Consumes []string `protobuf:"bytes,6,rep,name=consumes" json:"consumes,omitempty"` + Produces []string `protobuf:"bytes,7,rep,name=produces" json:"produces,omitempty"` + ExternalDocs *ExternalDocumentation `protobuf:"bytes,14,opt,name=external_docs,json=externalDocs" json:"external_docs,omitempty"` +} + +func (m *Swagger) Reset() { *m = Swagger{} } +func (m *Swagger) String() string { return proto.CompactTextString(m) } +func (*Swagger) ProtoMessage() {} +func (*Swagger) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +func (m *Swagger) GetSwagger() string { + if m != nil { + return m.Swagger + } + return "" +} + +func (m *Swagger) GetInfo() *Info { + if m != nil { + return m.Info + } + return nil +} + +func (m *Swagger) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *Swagger) GetBasePath() string { + if m != nil { + return m.BasePath + } + return "" +} + +func (m *Swagger) GetSchemes() []Swagger_SwaggerScheme { + if m != nil { + return m.Schemes + } + return nil +} + +func (m *Swagger) GetConsumes() []string { + if m != nil { + return m.Consumes + } + return nil +} + +func (m *Swagger) GetProduces() []string { + if m != nil { + return m.Produces + } + return nil +} + +func (m *Swagger) GetExternalDocs() *ExternalDocumentation { + if m != nil { + return m.ExternalDocs + } + return nil +} + +// `Operation` is a representation of OpenAPI v2 specification's Operation object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#operationObject +// +// TODO(ivucica): document fields +type Operation struct { + Tags []string `protobuf:"bytes,1,rep,name=tags" json:"tags,omitempty"` + Summary string `protobuf:"bytes,2,opt,name=summary" json:"summary,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description" json:"description,omitempty"` + ExternalDocs *ExternalDocumentation `protobuf:"bytes,4,opt,name=external_docs,json=externalDocs" json:"external_docs,omitempty"` + OperationId string `protobuf:"bytes,5,opt,name=operation_id,json=operationId" json:"operation_id,omitempty"` + Consumes []string `protobuf:"bytes,6,rep,name=consumes" json:"consumes,omitempty"` + Produces []string `protobuf:"bytes,7,rep,name=produces" json:"produces,omitempty"` + Schemes []string `protobuf:"bytes,10,rep,name=schemes" json:"schemes,omitempty"` + Deprecated bool `protobuf:"varint,11,opt,name=deprecated" json:"deprecated,omitempty"` +} + +func (m *Operation) Reset() { *m = Operation{} } +func (m *Operation) String() string { return proto.CompactTextString(m) } +func (*Operation) ProtoMessage() {} +func (*Operation) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *Operation) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + +func (m *Operation) GetSummary() string { + if m != nil { + return m.Summary + } + return "" +} + +func (m *Operation) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *Operation) GetExternalDocs() *ExternalDocumentation { + if m != nil { + return m.ExternalDocs + } + return nil +} + +func (m *Operation) GetOperationId() string { + if m != nil { + return m.OperationId + } + return "" +} + +func (m *Operation) GetConsumes() []string { + if m != nil { + return m.Consumes + } + return nil +} + +func (m *Operation) GetProduces() []string { + if m != nil { + return m.Produces + } + return nil +} + +func (m *Operation) GetSchemes() []string { + if m != nil { + return m.Schemes + } + return nil +} + +func (m *Operation) GetDeprecated() bool { + if m != nil { + return m.Deprecated + } + return false +} + +// `Info` is a representation of OpenAPI v2 specification's Info object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#infoObject +// +// TODO(ivucica): document fields +type Info struct { + Title string `protobuf:"bytes,1,opt,name=title" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description" json:"description,omitempty"` + TermsOfService string `protobuf:"bytes,3,opt,name=terms_of_service,json=termsOfService" json:"terms_of_service,omitempty"` + Contact *Contact `protobuf:"bytes,4,opt,name=contact" json:"contact,omitempty"` + Version string `protobuf:"bytes,6,opt,name=version" json:"version,omitempty"` +} + +func (m *Info) Reset() { *m = Info{} } +func (m *Info) String() string { return proto.CompactTextString(m) } +func (*Info) ProtoMessage() {} +func (*Info) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *Info) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *Info) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *Info) GetTermsOfService() string { + if m != nil { + return m.TermsOfService + } + return "" +} + +func (m *Info) GetContact() *Contact { + if m != nil { + return m.Contact + } + return nil +} + +func (m *Info) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +// `Contact` is a representation of OpenAPI v2 specification's Contact object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#contactObject +// +// TODO(ivucica): document fields +type Contact struct { + Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Url string `protobuf:"bytes,2,opt,name=url" json:"url,omitempty"` + Email string `protobuf:"bytes,3,opt,name=email" json:"email,omitempty"` +} + +func (m *Contact) Reset() { *m = Contact{} } +func (m *Contact) String() string { return proto.CompactTextString(m) } +func (*Contact) ProtoMessage() {} +func (*Contact) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +func (m *Contact) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Contact) GetUrl() string { + if m != nil { + return m.Url + } + return "" +} + +func (m *Contact) GetEmail() string { + if m != nil { + return m.Email + } + return "" +} + +// `ExternalDocumentation` is a representation of OpenAPI v2 specification's +// ExternalDocumentation object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#externalDocumentationObject +// +// TODO(ivucica): document fields +type ExternalDocumentation struct { + Description string `protobuf:"bytes,1,opt,name=description" json:"description,omitempty"` + Url string `protobuf:"bytes,2,opt,name=url" json:"url,omitempty"` +} + +func (m *ExternalDocumentation) Reset() { *m = ExternalDocumentation{} } +func (m *ExternalDocumentation) String() string { return proto.CompactTextString(m) } +func (*ExternalDocumentation) ProtoMessage() {} +func (*ExternalDocumentation) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } + +func (m *ExternalDocumentation) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *ExternalDocumentation) GetUrl() string { + if m != nil { + return m.Url + } + return "" +} + +// `Schema` is a representation of OpenAPI v2 specification's Schema object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject +// +// TODO(ivucica): document fields +type Schema struct { + JsonSchema *JSONSchema `protobuf:"bytes,1,opt,name=json_schema,json=jsonSchema" json:"json_schema,omitempty"` + Discriminator string `protobuf:"bytes,2,opt,name=discriminator" json:"discriminator,omitempty"` + ReadOnly bool `protobuf:"varint,3,opt,name=read_only,json=readOnly" json:"read_only,omitempty"` + ExternalDocs *ExternalDocumentation `protobuf:"bytes,5,opt,name=external_docs,json=externalDocs" json:"external_docs,omitempty"` + Example *google_protobuf.Any `protobuf:"bytes,6,opt,name=example" json:"example,omitempty"` +} + +func (m *Schema) Reset() { *m = Schema{} } +func (m *Schema) String() string { return proto.CompactTextString(m) } +func (*Schema) ProtoMessage() {} +func (*Schema) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } + +func (m *Schema) GetJsonSchema() *JSONSchema { + if m != nil { + return m.JsonSchema + } + return nil +} + +func (m *Schema) GetDiscriminator() string { + if m != nil { + return m.Discriminator + } + return "" +} + +func (m *Schema) GetReadOnly() bool { + if m != nil { + return m.ReadOnly + } + return false +} + +func (m *Schema) GetExternalDocs() *ExternalDocumentation { + if m != nil { + return m.ExternalDocs + } + return nil +} + +func (m *Schema) GetExample() *google_protobuf.Any { + if m != nil { + return m.Example + } + return nil +} + +// `JSONSchema` represents properties from JSON Schema taken, and as used, in +// the OpenAPI v2 spec. +// +// This includes changes made by OpenAPI v2. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject +// +// See also: https://cswr.github.io/JsonSchema/spec/basic_types/, +// https://github.com/json-schema-org/json-schema-spec/blob/master/schema.json +// +// TODO(ivucica): document fields +type JSONSchema struct { + Title string `protobuf:"bytes,5,opt,name=title" json:"title,omitempty"` + Description string `protobuf:"bytes,6,opt,name=description" json:"description,omitempty"` + Default string `protobuf:"bytes,7,opt,name=default" json:"default,omitempty"` + MultipleOf float64 `protobuf:"fixed64,10,opt,name=multiple_of,json=multipleOf" json:"multiple_of,omitempty"` + Maximum float64 `protobuf:"fixed64,11,opt,name=maximum" json:"maximum,omitempty"` + ExclusiveMaximum bool `protobuf:"varint,12,opt,name=exclusive_maximum,json=exclusiveMaximum" json:"exclusive_maximum,omitempty"` + Minimum float64 `protobuf:"fixed64,13,opt,name=minimum" json:"minimum,omitempty"` + ExclusiveMinimum bool `protobuf:"varint,14,opt,name=exclusive_minimum,json=exclusiveMinimum" json:"exclusive_minimum,omitempty"` + MaxLength uint64 `protobuf:"varint,15,opt,name=max_length,json=maxLength" json:"max_length,omitempty"` + MinLength uint64 `protobuf:"varint,16,opt,name=min_length,json=minLength" json:"min_length,omitempty"` + Pattern string `protobuf:"bytes,17,opt,name=pattern" json:"pattern,omitempty"` + MaxItems uint64 `protobuf:"varint,20,opt,name=max_items,json=maxItems" json:"max_items,omitempty"` + MinItems uint64 `protobuf:"varint,21,opt,name=min_items,json=minItems" json:"min_items,omitempty"` + UniqueItems bool `protobuf:"varint,22,opt,name=unique_items,json=uniqueItems" json:"unique_items,omitempty"` + MaxProperties uint64 `protobuf:"varint,24,opt,name=max_properties,json=maxProperties" json:"max_properties,omitempty"` + MinProperties uint64 `protobuf:"varint,25,opt,name=min_properties,json=minProperties" json:"min_properties,omitempty"` + Required []string `protobuf:"bytes,26,rep,name=required" json:"required,omitempty"` + // Items in 'array' must be unique. + Array []string `protobuf:"bytes,34,rep,name=array" json:"array,omitempty"` + Type []JSONSchema_JSONSchemaSimpleTypes `protobuf:"varint,35,rep,packed,name=type,enum=grpc.gateway.protoc_gen_swagger.options.JSONSchema_JSONSchemaSimpleTypes" json:"type,omitempty"` +} + +func (m *JSONSchema) Reset() { *m = JSONSchema{} } +func (m *JSONSchema) String() string { return proto.CompactTextString(m) } +func (*JSONSchema) ProtoMessage() {} +func (*JSONSchema) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } + +func (m *JSONSchema) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *JSONSchema) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *JSONSchema) GetDefault() string { + if m != nil { + return m.Default + } + return "" +} + +func (m *JSONSchema) GetMultipleOf() float64 { + if m != nil { + return m.MultipleOf + } + return 0 +} + +func (m *JSONSchema) GetMaximum() float64 { + if m != nil { + return m.Maximum + } + return 0 +} + +func (m *JSONSchema) GetExclusiveMaximum() bool { + if m != nil { + return m.ExclusiveMaximum + } + return false +} + +func (m *JSONSchema) GetMinimum() float64 { + if m != nil { + return m.Minimum + } + return 0 +} + +func (m *JSONSchema) GetExclusiveMinimum() bool { + if m != nil { + return m.ExclusiveMinimum + } + return false +} + +func (m *JSONSchema) GetMaxLength() uint64 { + if m != nil { + return m.MaxLength + } + return 0 +} + +func (m *JSONSchema) GetMinLength() uint64 { + if m != nil { + return m.MinLength + } + return 0 +} + +func (m *JSONSchema) GetPattern() string { + if m != nil { + return m.Pattern + } + return "" +} + +func (m *JSONSchema) GetMaxItems() uint64 { + if m != nil { + return m.MaxItems + } + return 0 +} + +func (m *JSONSchema) GetMinItems() uint64 { + if m != nil { + return m.MinItems + } + return 0 +} + +func (m *JSONSchema) GetUniqueItems() bool { + if m != nil { + return m.UniqueItems + } + return false +} + +func (m *JSONSchema) GetMaxProperties() uint64 { + if m != nil { + return m.MaxProperties + } + return 0 +} + +func (m *JSONSchema) GetMinProperties() uint64 { + if m != nil { + return m.MinProperties + } + return 0 +} + +func (m *JSONSchema) GetRequired() []string { + if m != nil { + return m.Required + } + return nil +} + +func (m *JSONSchema) GetArray() []string { + if m != nil { + return m.Array + } + return nil +} + +func (m *JSONSchema) GetType() []JSONSchema_JSONSchemaSimpleTypes { + if m != nil { + return m.Type + } + return nil +} + +// `Tag` is a representation of OpenAPI v2 specification's Tag object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#tagObject +// +// TODO(ivucica): document fields +type Tag struct { + // TODO(ivucica): Description should be extracted from comments on the proto + // service object. + Description string `protobuf:"bytes,2,opt,name=description" json:"description,omitempty"` + ExternalDocs *ExternalDocumentation `protobuf:"bytes,3,opt,name=external_docs,json=externalDocs" json:"external_docs,omitempty"` +} + +func (m *Tag) Reset() { *m = Tag{} } +func (m *Tag) String() string { return proto.CompactTextString(m) } +func (*Tag) ProtoMessage() {} +func (*Tag) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } + +func (m *Tag) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *Tag) GetExternalDocs() *ExternalDocumentation { + if m != nil { + return m.ExternalDocs + } + return nil +} + +func init() { + proto.RegisterType((*Swagger)(nil), "grpc.gateway.protoc_gen_swagger.options.Swagger") + proto.RegisterType((*Operation)(nil), "grpc.gateway.protoc_gen_swagger.options.Operation") + proto.RegisterType((*Info)(nil), "grpc.gateway.protoc_gen_swagger.options.Info") + proto.RegisterType((*Contact)(nil), "grpc.gateway.protoc_gen_swagger.options.Contact") + proto.RegisterType((*ExternalDocumentation)(nil), "grpc.gateway.protoc_gen_swagger.options.ExternalDocumentation") + proto.RegisterType((*Schema)(nil), "grpc.gateway.protoc_gen_swagger.options.Schema") + proto.RegisterType((*JSONSchema)(nil), "grpc.gateway.protoc_gen_swagger.options.JSONSchema") + proto.RegisterType((*Tag)(nil), "grpc.gateway.protoc_gen_swagger.options.Tag") + proto.RegisterEnum("grpc.gateway.protoc_gen_swagger.options.Swagger_SwaggerScheme", Swagger_SwaggerScheme_name, Swagger_SwaggerScheme_value) + proto.RegisterEnum("grpc.gateway.protoc_gen_swagger.options.JSONSchema_JSONSchemaSimpleTypes", JSONSchema_JSONSchemaSimpleTypes_name, JSONSchema_JSONSchemaSimpleTypes_value) +} + +func init() { proto.RegisterFile("protoc-gen-swagger/options/openapiv2.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 1175 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xed, 0x6e, 0xdb, 0x36, + 0x17, 0x7e, 0x65, 0xd3, 0x36, 0x7d, 0x6c, 0xe7, 0x65, 0xd5, 0x74, 0x63, 0xd3, 0x8f, 0xb9, 0x5e, + 0x87, 0x19, 0x2d, 0xe2, 0x0c, 0xe9,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20, 0x45, 0xba, 0x87, 0xcf, 0x7f, 0x3a, 0x58, 0x0a, 0x75, 0x9a, 0x9f, + 0x0c, 0x82, 0x38, 0xda, 0xd3, 0xfa, 0xbb, 0x3c, 0x88, 0xb3, 0x75, 0xa6, 0xb8, 0x35, 0xed, 0xe7, + 0xf6, 0xfe, 0xf9, 0x7f, 0xeb, 0x49, 0xdd, 0x70, 0xcf, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xf8, + 0x2b, 0xe7, 0x47, 0xdc, 0x0a, 0x00, 0x00, +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/openapiv2.proto b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/openapiv2.proto new file mode 100644 index 0000000000..6c1854613d --- /dev/null +++ b/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/openapiv2.proto @@ -0,0 +1,223 @@ +syntax = "proto3"; + +package grpc.gateway.protoc_gen_swagger.options; + +option go_package = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options"; + +import "google/protobuf/any.proto"; + +// `Swagger` is a representation of OpenAPI v2 specification's Swagger object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#swaggerObject +// +// TODO(ivucica): document fields +message Swagger { + string swagger = 1; + Info info = 2; + string host = 3; + string base_path = 4; + enum SwaggerScheme { + UNKNOWN = 0; + HTTP = 1; + HTTPS = 2; + WS = 3; + WSS = 4; + } + repeated SwaggerScheme schemes = 5; + repeated string consumes = 6; + repeated string produces = 7; + // field 8 is reserved for 'paths'. + reserved 8; + // field 9 is reserved for 'definitions', which at this time are already + // exposed as and customizable as proto messages. + reserved 9; + // field 10 is reserved for 'responses'. + reserved 10; + // field 11 is reserved for 'securityDefinitions'. + reserved 11; + // field 12 is reserved for repeated 'security'. + reserved 12; + // field 13 is reserved for 'tags', which are supposed to be exposed as and + // customizable as proto services. TODO(ivucica): add processing of proto + // service objects into OpenAPI v2 Tag objects. + reserved 13; + ExternalDocumentation external_docs = 14; +} + +// `Operation` is a representation of OpenAPI v2 specification's Operation object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#operationObject +// +// TODO(ivucica): document fields +message Operation { + repeated string tags = 1; + string summary = 2; + string description = 3; + ExternalDocumentation external_docs = 4; + string operation_id = 5; + repeated string consumes = 6; + repeated string produces = 7; + // field 8 is reserved for 'parameters'. + reserved 8; + // field 9 is reserved for 'responses'. + reserved 9; + repeated string schemes = 10; + bool deprecated = 11; + // field 12 is reserved for 'security'. + reserved 12; + +} + +// `Info` is a representation of OpenAPI v2 specification's Info object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#infoObject +// +// TODO(ivucica): document fields +message Info { + string title = 1; + string description = 2; + string terms_of_service = 3; + Contact contact = 4; + // field 5 is reserved for 'license'. + reserved 5; + string version = 6; +} + +// `Contact` is a representation of OpenAPI v2 specification's Contact object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#contactObject +// +// TODO(ivucica): document fields +message Contact { + string name = 1; + string url = 2; + string email = 3; +} + +// `ExternalDocumentation` is a representation of OpenAPI v2 specification's +// ExternalDocumentation object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#externalDocumentationObject +// +// TODO(ivucica): document fields +message ExternalDocumentation { + string description = 1; + string url = 2; +} + +// `Schema` is a representation of OpenAPI v2 specification's Schema object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject +// +// TODO(ivucica): document fields +message Schema { + JSONSchema json_schema = 1; + string discriminator = 2; + bool read_only = 3; + // field 4 is reserved for 'xml'. + reserved 4; + ExternalDocumentation external_docs = 5; + google.protobuf.Any example = 6; +} + +// `JSONSchema` represents properties from JSON Schema taken, and as used, in +// the OpenAPI v2 spec. +// +// This includes changes made by OpenAPI v2. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject +// +// See also: https://cswr.github.io/JsonSchema/spec/basic_types/, +// https://github.com/json-schema-org/json-schema-spec/blob/master/schema.json +// +// TODO(ivucica): document fields +message JSONSchema { + // field 1 is reserved for '$id', omitted from OpenAPI v2. + reserved 1; + // field 2 is reserved for '$schema', omitted from OpenAPI v2. + reserved 2; + // field 3 is reserved for '$ref', although it is unclear how it would be used. + reserved 3; + // field 4 is reserved for '$comment', omitted from OpenAPI v2. + reserved 4; + string title = 5; + string description = 6; + string default = 7; + // field 8 is reserved for 'readOnly', which has an OpenAPI v2-specific meaning and is defined there. + reserved 8; + // field 9 is reserved for 'examples', which is omitted from OpenAPI v2 in favor of 'example' field. + reserved 9; + double multiple_of = 10; + double maximum = 11; + bool exclusive_maximum = 12; + double minimum = 13; + bool exclusive_minimum = 14; + uint64 max_length = 15; + uint64 min_length = 16; + string pattern = 17; + // field 18 is reserved for 'additionalItems', omitted from OpenAPI v2. + reserved 18; + // field 19 is reserved for 'items', but in OpenAPI-specific way. TODO(ivucica): add 'items'? + reserved 19; + uint64 max_items = 20; + uint64 min_items = 21; + bool unique_items = 22; + // field 23 is reserved for 'contains', omitted from OpenAPI v2. + reserved 23; + uint64 max_properties = 24; + uint64 min_properties = 25; + repeated string required = 26; + // field 27 is reserved for 'additionalProperties', but in OpenAPI-specific way. TODO(ivucica): add 'additionalProperties'? + reserved 27; + // field 28 is reserved for 'definitions', omitted from OpenAPI v2. + reserved 28; + // field 29 is reserved for 'properties', but in OpenAPI-specific way. TODO(ivucica): add 'additionalProperties'? + reserved 29; + // following fields are reserved, as the properties have been omitted from OpenAPI v2: + // patternProperties, dependencies, propertyNames, const + reserved 30 to 33; + // Items in 'array' must be unique. + repeated string array = 34; + + enum JSONSchemaSimpleTypes { + UNKNOWN = 0; + ARRAY = 1; + BOOLEAN = 2; + INTEGER = 3; + NULL = 4; + NUMBER = 5; + OBJECT = 6; + STRING = 7; + } + + repeated JSONSchemaSimpleTypes type = 35; + // following fields are reserved, as the properties have been omitted from OpenAPI v2: + // format, contentMediaType, contentEncoding, if, then, else + reserved 36 to 41; + // field 42 is reserved for 'allOf', but in OpenAPI-specific way. TODO(ivucica): add 'allOf'? + reserved 42; + // following fields are reserved, as the properties have been omitted from OpenAPI v2: + // anyOf, oneOf, not + reserved 43 to 45; +} + +// `Tag` is a representation of OpenAPI v2 specification's Tag object. +// +// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#tagObject +// +// TODO(ivucica): document fields +message Tag { + // field 1 is reserved for 'name'. In our generator, this is (to be) extracted + // from the name of proto service, and thus not exposed to the user, as + // changing tag object's name would break the link to the references to the + // tag in individual operation specifications. + // + // TODO(ivucica): Add 'name' property. Use it to allow override of the name of + // global Tag object, then use that name to reference the tag throughout the + // Swagger file. + reserved 1; + // TODO(ivucica): Description should be extracted from comments on the proto + // service object. + string description = 2; + ExternalDocumentation external_docs = 3; +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go index 1af5cc4ebd..f893186410 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go @@ -2,6 +2,10 @@ package runtime import ( "strconv" + + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/ptypes/duration" + "github.com/golang/protobuf/ptypes/timestamp" ) // String just returns the given string. @@ -56,3 +60,17 @@ func Uint32(val string) (uint32, error) { } return uint32(i), nil } + +// Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp. +func Timestamp(val string) (*timestamp.Timestamp, error) { + var r *timestamp.Timestamp + err := jsonpb.UnmarshalString(val, r) + return r, err +} + +// Duration converts the given string into a timestamp.Duration. +func Duration(val string) (*duration.Duration, error) { + var r *duration.Duration + err := jsonpb.UnmarshalString(val, r) + return r, err +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go index ae6a5d551c..1770b85344 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go @@ -34,34 +34,47 @@ func ForwardResponseStream(ctx context.Context, mux *ServeMux, marshaler Marshal w.Header().Set("Transfer-Encoding", "chunked") w.Header().Set("Content-Type", marshaler.ContentType()) if err := handleForwardResponseOptions(ctx, w, nil, opts); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + HTTPError(ctx, mux, marshaler, w, req, err) return } - w.WriteHeader(http.StatusOK) - f.Flush() + + var delimiter []byte + if d, ok := marshaler.(Delimited); ok { + delimiter = d.Delimiter() + } else { + delimiter = []byte("\n") + } + + var wroteHeader bool for { resp, err := recv() if err == io.EOF { return } if err != nil { - handleForwardResponseStreamError(marshaler, w, err) + handleForwardResponseStreamError(wroteHeader, marshaler, w, err) return } if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil { - handleForwardResponseStreamError(marshaler, w, err) + handleForwardResponseStreamError(wroteHeader, marshaler, w, err) return } buf, err := marshaler.Marshal(streamChunk(resp, nil)) if err != nil { grpclog.Printf("Failed to marshal response chunk: %v", err) + handleForwardResponseStreamError(wroteHeader, marshaler, w, err) return } if _, err = w.Write(buf); err != nil { grpclog.Printf("Failed to send response chunk: %v", err) return } + wroteHeader = true + if _, err = w.Write(delimiter); err != nil { + grpclog.Printf("Failed to send delimiter chunk: %v", err) + return + } f.Flush() } } @@ -134,13 +147,20 @@ func handleForwardResponseOptions(ctx context.Context, w http.ResponseWriter, re return nil } -func handleForwardResponseStreamError(marshaler Marshaler, w http.ResponseWriter, err error) { +func handleForwardResponseStreamError(wroteHeader bool, marshaler Marshaler, w http.ResponseWriter, err error) { buf, merr := marshaler.Marshal(streamChunk(nil, err)) if merr != nil { grpclog.Printf("Failed to marshal an error: %v", merr) return } - if _, werr := fmt.Fprintf(w, "%s\n", buf); werr != nil { + if !wroteHeader { + s, ok := status.FromError(err) + if !ok { + s = status.New(codes.Unknown, err.Error()) + } + w.WriteHeader(HTTPStatusFromCode(s.Code())) + } + if _, werr := w.Write(buf); werr != nil { grpclog.Printf("Failed to notify error to client: %v", werr) return } diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/handler_test.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/handler_test.go index 8c61ee1510..493aa5e549 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/runtime/handler_test.go +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/handler_test.go @@ -11,57 +11,194 @@ import ( pb "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb" "github.com/grpc-ecosystem/grpc-gateway/runtime" "golang.org/x/net/context" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" ) func TestForwardResponseStream(t *testing.T) { - var ( - msgs = []proto.Message{ - &pb.SimpleMessage{Id: "One"}, - &pb.SimpleMessage{Id: "Two"}, - } + type msg struct { + pb proto.Message + err error + } + tests := []struct { + name string + msgs []msg + statusCode int + }{{ + name: "encoding", + msgs: []msg{ + {&pb.SimpleMessage{Id: "One"}, nil}, + {&pb.SimpleMessage{Id: "Two"}, nil}, + }, + statusCode: http.StatusOK, + }, { + name: "empty", + statusCode: http.StatusOK, + }, { + name: "error", + msgs: []msg{{nil, grpc.Errorf(codes.OutOfRange, "400")}}, + statusCode: http.StatusBadRequest, + }, { + name: "stream_error", + msgs: []msg{ + {&pb.SimpleMessage{Id: "One"}, nil}, + {nil, grpc.Errorf(codes.OutOfRange, "400")}, + }, + statusCode: http.StatusOK, + }} - ctx = runtime.NewServerMetadataContext( - context.Background(), runtime.ServerMetadata{}, - ) - mux = runtime.NewServeMux() - marshaler = &runtime.JSONPb{} - req = httptest.NewRequest("GET", "http://example.com/foo", nil) - resp = httptest.NewRecorder() - count = 0 - recv = func() (proto.Message, error) { - if count >= len(msgs) { + newTestRecv := func(t *testing.T, msgs []msg) func() (proto.Message, error) { + var count int + return func() (proto.Message, error) { + if count == len(msgs) { return nil, io.EOF + } else if count > len(msgs) { + t.Errorf("recv() called %d times for %d messages", count, len(msgs)) } count++ - return msgs[count-1], nil + msg := msgs[count-1] + return msg.pb, msg.err } - ) + } + ctx := runtime.NewServerMetadataContext(context.Background(), runtime.ServerMetadata{}) + marshaler := &runtime.JSONPb{} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + recv := newTestRecv(t, tt.msgs) + req := httptest.NewRequest("GET", "http://example.com/foo", nil) + resp := httptest.NewRecorder() - runtime.ForwardResponseStream(ctx, mux, marshaler, resp, req, recv) + runtime.ForwardResponseStream(ctx, runtime.NewServeMux(), marshaler, resp, req, recv) - w := resp.Result() - if w.StatusCode != http.StatusOK { - t.Errorf(" got %d want %d", w.StatusCode, http.StatusOK) - } - if h := w.Header.Get("Transfer-Encoding"); h != "chunked" { - t.Errorf("ForwardResponseStream missing header chunked") + w := resp.Result() + if w.StatusCode != tt.statusCode { + t.Errorf("StatusCode %d want %d", w.StatusCode, tt.statusCode) + } + if h := w.Header.Get("Transfer-Encoding"); h != "chunked" { + t.Errorf("ForwardResponseStream missing header chunked") + } + body, err := ioutil.ReadAll(w.Body) + if err != nil { + t.Errorf("Failed to read response body with %v", err) + } + w.Body.Close() + + var want []byte + for _, msg := range tt.msgs { + if msg.err != nil { + t.Skip("checking erorr encodings") + } + b, err := marshaler.Marshal(map[string]proto.Message{"result": msg.pb}) + if err != nil { + t.Errorf("marshaler.Marshal() failed %v", err) + } + want = append(want, b...) + want = append(want, marshaler.Delimiter()...) + } + + if string(body) != string(want) { + t.Errorf("ForwardResponseStream() = \"%s\" want \"%s\"", body, want) + } + }) } - body, err := ioutil.ReadAll(w.Body) - if err != nil { - t.Errorf("Failed to read response body with %v", err) +} + + +// A custom marshaler implementation, that doesn't implement the delimited interface +type CustomMarshaler struct { + m *runtime.JSONPb +} +func (c *CustomMarshaler) Marshal(v interface{}) ([]byte, error) { return c.m.Marshal(v) } +func (c *CustomMarshaler) Unmarshal(data []byte, v interface{}) error { return c.m.Unmarshal(data, v) } +func (c *CustomMarshaler) NewDecoder(r io.Reader) runtime.Decoder { return c.m.NewDecoder(r) } +func (c *CustomMarshaler) NewEncoder(w io.Writer) runtime.Encoder { return c.m.NewEncoder(w) } +func (c *CustomMarshaler) ContentType() string { return c.m.ContentType() } + + +func TestForwardResponseStreamCustomMarshaler(t *testing.T) { + type msg struct { + pb proto.Message + err error } - w.Body.Close() + tests := []struct { + name string + msgs []msg + statusCode int + }{{ + name: "encoding", + msgs: []msg{ + {&pb.SimpleMessage{Id: "One"}, nil}, + {&pb.SimpleMessage{Id: "Two"}, nil}, + }, + statusCode: http.StatusOK, + }, { + name: "empty", + statusCode: http.StatusOK, + }, { + name: "error", + msgs: []msg{{nil, grpc.Errorf(codes.OutOfRange, "400")}}, + statusCode: http.StatusBadRequest, + }, { + name: "stream_error", + msgs: []msg{ + {&pb.SimpleMessage{Id: "One"}, nil}, + {nil, grpc.Errorf(codes.OutOfRange, "400")}, + }, + statusCode: http.StatusOK, + }} - var want []byte - for _, msg := range msgs { - b, err := marshaler.Marshal(map[string]proto.Message{"result": msg}) - if err != nil { - t.Errorf("marshaler.Marshal() failed %v", err) + newTestRecv := func(t *testing.T, msgs []msg) func() (proto.Message, error) { + var count int + return func() (proto.Message, error) { + if count == len(msgs) { + return nil, io.EOF + } else if count > len(msgs) { + t.Errorf("recv() called %d times for %d messages", count, len(msgs)) + } + count++ + msg := msgs[count-1] + return msg.pb, msg.err } - want = append(want, b...) } + ctx := runtime.NewServerMetadataContext(context.Background(), runtime.ServerMetadata{}) + marshaler := &CustomMarshaler{&runtime.JSONPb{}} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + recv := newTestRecv(t, tt.msgs) + req := httptest.NewRequest("GET", "http://example.com/foo", nil) + resp := httptest.NewRecorder() + + runtime.ForwardResponseStream(ctx, runtime.NewServeMux(), marshaler, resp, req, recv) - if string(body) != string(want) { - t.Errorf("ForwardResponseStream() = \"%s\" want \"%s\"", body, want) + w := resp.Result() + if w.StatusCode != tt.statusCode { + t.Errorf("StatusCode %d want %d", w.StatusCode, tt.statusCode) + } + if h := w.Header.Get("Transfer-Encoding"); h != "chunked" { + t.Errorf("ForwardResponseStream missing header chunked") + } + body, err := ioutil.ReadAll(w.Body) + if err != nil { + t.Errorf("Failed to read response body with %v", err) + } + w.Body.Close() + + var want []byte + for _, msg := range tt.msgs { + if msg.err != nil { + t.Skip("checking erorr encodings") + } + b, err := marshaler.Marshal(map[string]proto.Message{"result": msg.pb}) + if err != nil { + t.Errorf("marshaler.Marshal() failed %v", err) + } + want = append(want, b...) + want = append(want, "\n"...) + } + + if string(body) != string(want) { + t.Errorf("ForwardResponseStream() = \"%s\" want \"%s\"", body, want) + } + }) } } diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go index 0acd2ca29e..b3a21418be 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go @@ -35,3 +35,8 @@ func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder { func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder { return json.NewEncoder(w) } + +// Delimiter for newline encoded JSON streams. +func (j *JSONBuiltin) Delimiter() []byte { + return []byte("\n") +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go index 49f13f7fc7..d42cc593e5 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go @@ -182,3 +182,8 @@ type protoEnum interface { } var typeProtoMessage = reflect.TypeOf((*proto.Message)(nil)).Elem() + +// Delimiter for newline encoded JSON streams. +func (j *JSONPb) Delimiter() []byte { + return []byte("\n") +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go new file mode 100644 index 0000000000..f65d1a2676 --- /dev/null +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go @@ -0,0 +1,62 @@ +package runtime + +import ( + "io" + + "errors" + "github.com/golang/protobuf/proto" + "io/ioutil" +) + +// ProtoMarshaller is a Marshaller which marshals/unmarshals into/from serialize proto bytes +type ProtoMarshaller struct{} + +// ContentType always returns "application/octet-stream". +func (*ProtoMarshaller) ContentType() string { + return "application/octet-stream" +} + +// Marshal marshals "value" into Proto +func (*ProtoMarshaller) Marshal(value interface{}) ([]byte, error) { + message, ok := value.(proto.Message) + if !ok { + return nil, errors.New("unable to marshal non proto field") + } + return proto.Marshal(message) +} + +// Unmarshal unmarshals proto "data" into "value" +func (*ProtoMarshaller) Unmarshal(data []byte, value interface{}) error { + message, ok := value.(proto.Message) + if !ok { + return errors.New("unable to unmarshal non proto field") + } + return proto.Unmarshal(data, message) +} + +// NewDecoder returns a Decoder which reads proto stream from "reader". +func (marshaller *ProtoMarshaller) NewDecoder(reader io.Reader) Decoder { + return DecoderFunc(func(value interface{}) error { + buffer, err := ioutil.ReadAll(reader) + if err != nil { + return err + } + return marshaller.Unmarshal(buffer, value) + }) +} + +// NewEncoder returns an Encoder which writes proto stream into "writer". +func (marshaller *ProtoMarshaller) NewEncoder(writer io.Writer) Encoder { + return EncoderFunc(func(value interface{}) error { + buffer, err := marshaller.Marshal(value) + if err != nil { + return err + } + _, err = writer.Write(buffer) + if err != nil { + return err + } + + return nil + }) +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto_test.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto_test.go new file mode 100644 index 0000000000..07dac47bd5 --- /dev/null +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto_test.go @@ -0,0 +1,91 @@ +package runtime_test + +import ( + "reflect" + "testing" + + "bytes" + "github.com/golang/protobuf/ptypes/timestamp" + "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb" + "github.com/grpc-ecosystem/grpc-gateway/runtime" +) + +var message = &examplepb.ABitOfEverything{ + SingleNested: &examplepb.ABitOfEverything_Nested{}, + RepeatedStringValue: nil, + MappedStringValue: nil, + MappedNestedValue: nil, + RepeatedEnumValue: nil, + TimestampValue: ×tamp.Timestamp{}, + Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7", + Nested: []*examplepb.ABitOfEverything_Nested{ + { + Name: "foo", + Amount: 12345, + }, + }, + Uint64Value: 0xFFFFFFFFFFFFFFFF, + EnumValue: examplepb.NumericEnum_ONE, + OneofValue: &examplepb.ABitOfEverything_OneofString{ + OneofString: "bar", + }, + MapValue: map[string]examplepb.NumericEnum{ + "a": examplepb.NumericEnum_ONE, + "b": examplepb.NumericEnum_ZERO, + }, +} + +func TestProtoMarshalUnmarshal(t *testing.T) { + marshaller := runtime.ProtoMarshaller{} + + // Marshal + buffer, err := marshaller.Marshal(message) + if err != nil { + t.Fatalf("Marshalling returned error: %s", err.Error()) + } + + // Unmarshal + unmarshalled := &examplepb.ABitOfEverything{} + err = marshaller.Unmarshal(buffer, unmarshalled) + if err != nil { + t.Fatalf("Unmarshalling returned error: %s", err.Error()) + } + + if !reflect.DeepEqual(unmarshalled, message) { + t.Errorf( + "Unmarshalled didn't match original message: (original = %v) != (unmarshalled = %v)", + unmarshalled, + message, + ) + } +} + +func TestProtoEncoderDecodert(t *testing.T) { + marshaller := runtime.ProtoMarshaller{} + + var buf bytes.Buffer + + encoder := marshaller.NewEncoder(&buf) + decoder := marshaller.NewDecoder(&buf) + + // Encode + err := encoder.Encode(message) + if err != nil { + t.Fatalf("Encoding returned error: %s", err.Error()) + } + + // Decode + unencoded := &examplepb.ABitOfEverything{} + err = decoder.Decode(unencoded) + if err != nil { + t.Fatalf("Unmarshalling returned error: %s", err.Error()) + } + + if !reflect.DeepEqual(unencoded, message) { + t.Errorf( + "Unencoded didn't match original message: (original = %v) != (unencoded = %v)", + unencoded, + message, + ) + } +} diff --git a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go index 6d434f13cb..98fe6e88ac 100644 --- a/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go +++ b/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go @@ -40,3 +40,9 @@ type EncoderFunc func(v interface{}) error // Encode delegates invocations to the underlying function itself. func (f EncoderFunc) Encode(v interface{}) error { return f(v) } + +// Delimited defines the streaming delimiter. +type Delimited interface { + // Delimiter returns the record seperator for the stream. + Delimiter() []byte +}