diff --git a/.travis.yml b/.travis.yml index c1113a5c282..37d1b5468e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,10 +11,11 @@ cache: - ${TRAVIS_BUILD_DIR}/examples/browser/node_modules before_install: - ./.travis/install-protoc.sh 3.1.0 -- ./.travis/install-swagger-codegen.sh 2.1.6 +- ./.travis/install-swagger-codegen.sh 2.2.2 - nvm install v6.1 && nvm use v6.1 && node --version - go get github.com/golang/lint/golint - go get github.com/dghubble/sling +- go get github.com/go-resty/resty install: - go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway - go get github.com/grpc-ecosystem/grpc-gateway/runtime diff --git a/Makefile b/Makefile index accde9800fe..5fe3c4850e0 100644 --- a/Makefile +++ b/Makefile @@ -109,12 +109,16 @@ $(EXAMPLE_SWAGGERSRCS): $(SWAGGER_PLUGIN) $(SWAGGER_EXAMPLES) $(ECHO_EXAMPLE_SRCS): $(ECHO_EXAMPLE_SPEC) $(SWAGGER_CODEGEN) generate -i $(ECHO_EXAMPLE_SPEC) \ - -l go -o examples/clients --additional-properties packageName=echo - @rm -f $(EXAMPLE_CLIENT_DIR)/README.md $(EXAMPLE_CLIENT_DIR)/git_push.sh $(EXAMPLE_CLIENT_DIR)/.gitignore + -l go -o examples/clients/echo --additional-properties packageName=echo + @rm -f $(EXAMPLE_CLIENT_DIR)/echo/README.md \ + $(EXAMPLE_CLIENT_DIR)/echo/git_push.sh \ + $(EXAMPLE_CLIENT_DIR)/echo/.travis.yml $(ABE_EXAMPLE_SRCS): $(ABE_EXAMPLE_SPEC) $(SWAGGER_CODEGEN) generate -i $(ABE_EXAMPLE_SPEC) \ - -l go -o examples/clients --additional-properties packageName=abe - @rm -f $(EXAMPLE_CLIENT_DIR)/README.md $(EXAMPLE_CLIENT_DIR)/git_push.sh $(EXAMPLE_CLIENT_DIR)/.gitignore + -l go -o examples/clients/abe --additional-properties packageName=abe + @rm -f $(EXAMPLE_CLIENT_DIR)/abe/README.md \ + $(EXAMPLE_CLIENT_DIR)/abe/git_push.sh \ + $(EXAMPLE_CLIENT_DIR)/abe/.travis.yml examples: $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_DEPSRCS) $(EXAMPLE_SWAGGERSRCS) $(EXAMPLE_CLIENT_SRCS) test: examples diff --git a/examples/client_test.go b/examples/client_test.go index 0574d9fbb0c..536a7a27fc2 100644 --- a/examples/client_test.go +++ b/examples/client_test.go @@ -18,7 +18,7 @@ func TestEchoClient(t *testing.T) { } cl := echo.NewEchoServiceApiWithBasePath("http://localhost:8080") - resp, err := cl.Echo("foo") + resp, _, err := cl.Echo("foo") if err != nil { t.Errorf(`cl.Echo("foo") failed with %v; want success`, err) } @@ -35,7 +35,7 @@ func TestEchoBodyClient(t *testing.T) { cl := echo.NewEchoServiceApiWithBasePath("http://localhost:8080") req := echo.ExamplepbSimpleMessage{Id: "foo"} - resp, err := cl.EchoBody(req) + resp, _, err := cl.EchoBody(req) if err != nil { t.Errorf("cl.EchoBody(%#v) failed with %v; want success", req, err) } @@ -56,7 +56,7 @@ func TestAbitOfEverythingClient(t *testing.T) { } func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) { - want := abe.ExamplepbABitOfEverything{ + want := &abe.ExamplepbABitOfEverything{ FloatValue: 1.5, DoubleValue: 2.5, Int64Value: "4294967296", @@ -73,7 +73,7 @@ func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) { Sint64Value: "4611686018427387903", NonConventionalNameValue: "camelCase", } - resp, err := cl.Create( + resp, _, err := cl.Create( want.FloatValue, want.DoubleValue, want.Int64Value, @@ -148,7 +148,7 @@ func testABEClientCreateBody(t *testing.T, cl *abe.ABitOfEverythingServiceApi) { "b": {Name: "y", Amount: 2}, }, } - resp, err := cl.CreateBody(want) + resp, _, err := cl.CreateBody(want) if err != nil { t.Errorf("cl.CreateBody(%#v) failed with %v; want success", want, err) } diff --git a/examples/clients/abe/.gitignore b/examples/clients/abe/.gitignore new file mode 100644 index 00000000000..2f88269126d --- /dev/null +++ b/examples/clients/abe/.gitignore @@ -0,0 +1 @@ +/docs diff --git a/examples/clients/abe/.swagger-codegen-ignore b/examples/clients/abe/.swagger-codegen-ignore new file mode 100644 index 00000000000..6c7b69a0156 --- /dev/null +++ b/examples/clients/abe/.swagger-codegen-ignore @@ -0,0 +1 @@ +.gitignore diff --git a/examples/clients/abe/ABitOfEverythingNested.go b/examples/clients/abe/ABitOfEverythingNested.go deleted file mode 100644 index 7e5488e37a7..00000000000 --- a/examples/clients/abe/ABitOfEverythingNested.go +++ /dev/null @@ -1,11 +0,0 @@ -package abe - -import ( -) - -type ABitOfEverythingNested struct { - Name string `json:"name,omitempty"` - Amount int64 `json:"amount,omitempty"` - Ok NestedDeepEnum `json:"ok,omitempty"` - -} diff --git a/examples/clients/abe/ABitOfEverythingServiceApi.go b/examples/clients/abe/ABitOfEverythingServiceApi.go deleted file mode 100644 index fcc60763608..00000000000 --- a/examples/clients/abe/ABitOfEverythingServiceApi.go +++ /dev/null @@ -1,764 +0,0 @@ -package abe - -import ( - "strings" - "fmt" - "encoding/json" - "errors" - "github.com/dghubble/sling" - "time" -) - -type ABitOfEverythingServiceApi struct { - basePath string -} - -func NewABitOfEverythingServiceApi() *ABitOfEverythingServiceApi{ - return &ABitOfEverythingServiceApi { - basePath: "http://localhost", - } -} - -func NewABitOfEverythingServiceApiWithBasePath(basePath string) *ABitOfEverythingServiceApi{ - return &ABitOfEverythingServiceApi { - basePath: basePath, - } -} - -/** - * - * - * @param floatValue - * @param doubleValue - * @param int64Value - * @param uint64Value - * @param int32Value - * @param fixed64Value - * @param fixed32Value - * @param boolValue - * @param stringValue - * @param uint32Value - * @param sfixed32Value - * @param sfixed64Value - * @param sint32Value - * @param sint64Value - * @param nonConventionalNameValue - * @return ExamplepbABitOfEverything - */ -//func (a ABitOfEverythingServiceApi) Create (floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string) (ExamplepbABitOfEverything, error) { -func (a ABitOfEverythingServiceApi) Create (floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string) (ExamplepbABitOfEverything, error) { - - _sling := sling.New().Post(a.basePath) - - // create path and map variables - path := "/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}" - path = strings.Replace(path, "{" + "float_value" + "}", fmt.Sprintf("%v", floatValue), -1) - path = strings.Replace(path, "{" + "double_value" + "}", fmt.Sprintf("%v", doubleValue), -1) - path = strings.Replace(path, "{" + "int64_value" + "}", fmt.Sprintf("%v", int64Value), -1) - path = strings.Replace(path, "{" + "uint64_value" + "}", fmt.Sprintf("%v", uint64Value), -1) - path = strings.Replace(path, "{" + "int32_value" + "}", fmt.Sprintf("%v", int32Value), -1) - path = strings.Replace(path, "{" + "fixed64_value" + "}", fmt.Sprintf("%v", fixed64Value), -1) - path = strings.Replace(path, "{" + "fixed32_value" + "}", fmt.Sprintf("%v", fixed32Value), -1) - path = strings.Replace(path, "{" + "bool_value" + "}", fmt.Sprintf("%v", boolValue), -1) - path = strings.Replace(path, "{" + "string_value" + "}", fmt.Sprintf("%v", stringValue), -1) - path = strings.Replace(path, "{" + "uint32_value" + "}", fmt.Sprintf("%v", uint32Value), -1) - path = strings.Replace(path, "{" + "sfixed32_value" + "}", fmt.Sprintf("%v", sfixed32Value), -1) - path = strings.Replace(path, "{" + "sfixed64_value" + "}", fmt.Sprintf("%v", sfixed64Value), -1) - path = strings.Replace(path, "{" + "sint32_value" + "}", fmt.Sprintf("%v", sint32Value), -1) - path = strings.Replace(path, "{" + "sint64_value" + "}", fmt.Sprintf("%v", sint64Value), -1) - path = strings.Replace(path, "{" + "nonConventionalNameValue" + "}", fmt.Sprintf("%v", nonConventionalNameValue), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ExamplepbABitOfEverything) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param body - * @return ExamplepbABitOfEverything - */ -//func (a ABitOfEverythingServiceApi) CreateBody (body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) { -func (a ABitOfEverythingServiceApi) CreateBody (body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) { - - _sling := sling.New().Post(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything" - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - -// body params - _sling = _sling.BodyJSON(body) - - var successPayload = new(ExamplepbABitOfEverything) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param singleNestedName - * @param body - * @return ExamplepbABitOfEverything - */ -//func (a ABitOfEverythingServiceApi) DeepPathEcho (singleNestedName string, body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) { -func (a ABitOfEverythingServiceApi) DeepPathEcho (singleNestedName string, body ExamplepbABitOfEverything) (ExamplepbABitOfEverything, error) { - - _sling := sling.New().Post(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything/{single_nested.name}" - path = strings.Replace(path, "{" + "single_nested.name" + "}", fmt.Sprintf("%v", singleNestedName), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - -// body params - _sling = _sling.BodyJSON(body) - - var successPayload = new(ExamplepbABitOfEverything) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param uuid - * @return ProtobufEmpty - */ -//func (a ABitOfEverythingServiceApi) Delete (uuid string) (ProtobufEmpty, error) { -func (a ABitOfEverythingServiceApi) Delete (uuid string) (ProtobufEmpty, error) { - - _sling := sling.New().Delete(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything/{uuid}" - path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ProtobufEmpty) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param value - * @return SubStringMessage - */ -//func (a ABitOfEverythingServiceApi) Echo (value string) (SubStringMessage, error) { -func (a ABitOfEverythingServiceApi) Echo (value string) (SubStringMessage, error) { - - _sling := sling.New().Get(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything/echo/{value}" - path = strings.Replace(path, "{" + "value" + "}", fmt.Sprintf("%v", value), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(SubStringMessage) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param value - * @return SubStringMessage - */ -//func (a ABitOfEverythingServiceApi) Echo_1 (value string) (SubStringMessage, error) { -func (a ABitOfEverythingServiceApi) Echo_1 (value string) (SubStringMessage, error) { - - _sling := sling.New().Get(a.basePath) - - // create path and map variables - path := "/v2/example/echo" - - _sling = _sling.Path(path) - - type QueryParams struct { - value string `url:"value,omitempty"` - -} - _sling = _sling.QueryStruct(&QueryParams{ value: value }) - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(SubStringMessage) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param body - * @return SubStringMessage - */ -//func (a ABitOfEverythingServiceApi) Echo_2 (body string) (SubStringMessage, error) { -func (a ABitOfEverythingServiceApi) Echo_2 (body string) (SubStringMessage, error) { - - _sling := sling.New().Post(a.basePath) - - // create path and map variables - path := "/v2/example/echo" - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - -// body params - _sling = _sling.BodyJSON(body) - - var successPayload = new(SubStringMessage) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param uuid - * @param singleNestedName name is nested field. - * @param singleNestedAmount - * @param singleNestedOk - FALSE: FALSE is false.\n - TRUE: TRUE is true. - * @param floatValue - * @param doubleValue - * @param int64Value - * @param uint64Value - * @param int32Value - * @param fixed64Value - * @param fixed32Value - * @param boolValue - * @param stringValue - * @param uint32Value TODO(yugui) add bytes_value. - * @param enumValue - ZERO: ZERO means 0\n - ONE: ONE means 1 - * @param sfixed32Value - * @param sfixed64Value - * @param sint32Value - * @param sint64Value - * @param repeatedStringValue - * @param oneofString - * @param nonConventionalNameValue - * @param timestampValue - * @param repeatedEnumValue repeated enum value. it is comma-separated in query.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1 - * @return ProtobufEmpty - */ -//func (a ABitOfEverythingServiceApi) GetQuery (uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, enumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (ProtobufEmpty, error) { -func (a ABitOfEverythingServiceApi) GetQuery (uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, enumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (ProtobufEmpty, error) { - - _sling := sling.New().Get(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything/query/{uuid}" - path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1) - - _sling = _sling.Path(path) - - type QueryParams struct { - singleNestedName string `url:"single_nested.name,omitempty"` - singleNestedAmount int64 `url:"single_nested.amount,omitempty"` - singleNestedOk string `url:"single_nested.ok,omitempty"` - floatValue float32 `url:"float_value,omitempty"` - doubleValue float64 `url:"double_value,omitempty"` - int64Value string `url:"int64_value,omitempty"` - uint64Value string `url:"uint64_value,omitempty"` - int32Value int32 `url:"int32_value,omitempty"` - fixed64Value string `url:"fixed64_value,omitempty"` - fixed32Value int64 `url:"fixed32_value,omitempty"` - boolValue bool `url:"bool_value,omitempty"` - stringValue string `url:"string_value,omitempty"` - uint32Value int64 `url:"uint32_value,omitempty"` - enumValue string `url:"enum_value,omitempty"` - sfixed32Value int32 `url:"sfixed32_value,omitempty"` - sfixed64Value string `url:"sfixed64_value,omitempty"` - sint32Value int32 `url:"sint32_value,omitempty"` - sint64Value string `url:"sint64_value,omitempty"` - repeatedStringValue []string `url:"repeated_string_value,omitempty"` - oneofString string `url:"oneof_string,omitempty"` - nonConventionalNameValue string `url:"nonConventionalNameValue,omitempty"` - timestampValue time.Time `url:"timestamp_value,omitempty"` - repeatedEnumValue []string `url:"repeated_enum_value,omitempty"` - -} - _sling = _sling.QueryStruct(&QueryParams{ singleNestedName: singleNestedName,singleNestedAmount: singleNestedAmount,singleNestedOk: singleNestedOk,floatValue: floatValue,doubleValue: doubleValue,int64Value: int64Value,uint64Value: uint64Value,int32Value: int32Value,fixed64Value: fixed64Value,fixed32Value: fixed32Value,boolValue: boolValue,stringValue: stringValue,uint32Value: uint32Value,enumValue: enumValue,sfixed32Value: sfixed32Value,sfixed64Value: sfixed64Value,sint32Value: sint32Value,sint64Value: sint64Value,repeatedStringValue: repeatedStringValue,oneofString: oneofString,nonConventionalNameValue: nonConventionalNameValue,timestampValue: timestampValue,repeatedEnumValue: repeatedEnumValue }) - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ProtobufEmpty) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param uuid - * @return ExamplepbABitOfEverything - */ -//func (a ABitOfEverythingServiceApi) Lookup (uuid string) (ExamplepbABitOfEverything, error) { -func (a ABitOfEverythingServiceApi) Lookup (uuid string) (ExamplepbABitOfEverything, error) { - - _sling := sling.New().Get(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything/{uuid}" - path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ExamplepbABitOfEverything) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @return ProtobufEmpty - */ -//func (a ABitOfEverythingServiceApi) Timeout () (ProtobufEmpty, error) { -func (a ABitOfEverythingServiceApi) Timeout () (ProtobufEmpty, error) { - - _sling := sling.New().Get(a.basePath) - - // create path and map variables - path := "/v2/example/timeout" - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ProtobufEmpty) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * - * - * @param uuid - * @param body - * @return ProtobufEmpty - */ -//func (a ABitOfEverythingServiceApi) Update (uuid string, body ExamplepbABitOfEverything) (ProtobufEmpty, error) { -func (a ABitOfEverythingServiceApi) Update (uuid string, body ExamplepbABitOfEverything) (ProtobufEmpty, error) { - - _sling := sling.New().Put(a.basePath) - - // create path and map variables - path := "/v1/example/a_bit_of_everything/{uuid}" - path = strings.Replace(path, "{" + "uuid" + "}", fmt.Sprintf("%v", uuid), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - -// body params - _sling = _sling.BodyJSON(body) - - var successPayload = new(ProtobufEmpty) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} diff --git a/examples/clients/abe/ExamplepbABitOfEverything.go b/examples/clients/abe/ExamplepbABitOfEverything.go deleted file mode 100644 index 2892eb624d9..00000000000 --- a/examples/clients/abe/ExamplepbABitOfEverything.go +++ /dev/null @@ -1,36 +0,0 @@ -package abe - -import ( - "time" -) - -type ExamplepbABitOfEverything struct { - SingleNested ABitOfEverythingNested `json:"single_nested,omitempty"` - Uuid string `json:"uuid,omitempty"` - Nested []ABitOfEverythingNested `json:"nested,omitempty"` - FloatValue float32 `json:"float_value,omitempty"` - DoubleValue float64 `json:"double_value,omitempty"` - Int64Value string `json:"int64_value,omitempty"` - Uint64Value string `json:"uint64_value,omitempty"` - Int32Value int32 `json:"int32_value,omitempty"` - Fixed64Value string `json:"fixed64_value,omitempty"` - Fixed32Value int64 `json:"fixed32_value,omitempty"` - BoolValue bool `json:"bool_value,omitempty"` - StringValue string `json:"string_value,omitempty"` - Uint32Value int64 `json:"uint32_value,omitempty"` - EnumValue ExamplepbNumericEnum `json:"enum_value,omitempty"` - Sfixed32Value int32 `json:"sfixed32_value,omitempty"` - Sfixed64Value string `json:"sfixed64_value,omitempty"` - Sint32Value int32 `json:"sint32_value,omitempty"` - Sint64Value string `json:"sint64_value,omitempty"` - RepeatedStringValue []string `json:"repeated_string_value,omitempty"` - OneofEmpty ProtobufEmpty `json:"oneof_empty,omitempty"` - OneofString string `json:"oneof_string,omitempty"` - MapValue map[string]ExamplepbNumericEnum `json:"map_value,omitempty"` - MappedStringValue map[string]string `json:"mapped_string_value,omitempty"` - MappedNestedValue map[string]ABitOfEverythingNested `json:"mapped_nested_value,omitempty"` - NonConventionalNameValue string `json:"nonConventionalNameValue,omitempty"` - TimestampValue time.Time `json:"timestamp_value,omitempty"` - RepeatedEnumValue []ExamplepbNumericEnum `json:"repeated_enum_value,omitempty"` - -} diff --git a/examples/clients/abe/ExamplepbNumericEnum.go b/examples/clients/abe/ExamplepbNumericEnum.go deleted file mode 100644 index 51cffc77f69..00000000000 --- a/examples/clients/abe/ExamplepbNumericEnum.go +++ /dev/null @@ -1,8 +0,0 @@ -package abe - -import ( -) - -type ExamplepbNumericEnum struct { - -} diff --git a/examples/clients/abe/NestedDeepEnum.go b/examples/clients/abe/NestedDeepEnum.go deleted file mode 100644 index b48e231216c..00000000000 --- a/examples/clients/abe/NestedDeepEnum.go +++ /dev/null @@ -1,8 +0,0 @@ -package abe - -import ( -) - -type NestedDeepEnum struct { - -} diff --git a/examples/clients/abe/ProtobufEmpty.go b/examples/clients/abe/ProtobufEmpty.go deleted file mode 100644 index ac37afeb862..00000000000 --- a/examples/clients/abe/ProtobufEmpty.go +++ /dev/null @@ -1,8 +0,0 @@ -package abe - -import ( -) - -type ProtobufEmpty struct { - -} diff --git a/examples/clients/abe/SubStringMessage.go b/examples/clients/abe/SubStringMessage.go deleted file mode 100644 index f278dbf258b..00000000000 --- a/examples/clients/abe/SubStringMessage.go +++ /dev/null @@ -1,9 +0,0 @@ -package abe - -import ( -) - -type SubStringMessage struct { - Value string `json:"value,omitempty"` - -} diff --git a/examples/clients/abe/a_bit_of_everything_nested.go b/examples/clients/abe/a_bit_of_everything_nested.go new file mode 100644 index 00000000000..909f478b7dc --- /dev/null +++ b/examples/clients/abe/a_bit_of_everything_nested.go @@ -0,0 +1,22 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +// Nested is nested type. +type ABitOfEverythingNested struct { + + // name is nested field. + Name string `json:"name,omitempty"` + + Amount int64 `json:"amount,omitempty"` + + Ok NestedDeepEnum `json:"ok,omitempty"` +} diff --git a/examples/clients/abe/a_bit_of_everything_service_api.go b/examples/clients/abe/a_bit_of_everything_service_api.go new file mode 100644 index 00000000000..669a12aed76 --- /dev/null +++ b/examples/clients/abe/a_bit_of_everything_service_api.go @@ -0,0 +1,784 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +import ( + "net/url" + "strings" + "time" + "encoding/json" + "fmt" +) + +type ABitOfEverythingServiceApi struct { + Configuration *Configuration +} + +func NewABitOfEverythingServiceApi() *ABitOfEverythingServiceApi { + configuration := NewConfiguration() + return &ABitOfEverythingServiceApi{ + Configuration: configuration, + } +} + +func NewABitOfEverythingServiceApiWithBasePath(basePath string) *ABitOfEverythingServiceApi { + configuration := NewConfiguration() + configuration.BasePath = basePath + + return &ABitOfEverythingServiceApi{ + Configuration: configuration, + } +} + +/** + * + * + * @param floatValue + * @param doubleValue + * @param int64Value + * @param uint64Value + * @param int32Value + * @param fixed64Value + * @param fixed32Value + * @param boolValue + * @param stringValue + * @param uint32Value + * @param sfixed32Value + * @param sfixed64Value + * @param sint32Value + * @param sint64Value + * @param nonConventionalNameValue + * @return *ExamplepbABitOfEverything + */ +func (a ABitOfEverythingServiceApi) Create(floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string) (*ExamplepbABitOfEverything, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Post") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/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}" + localVarPath = strings.Replace(localVarPath, "{"+"float_value"+"}", fmt.Sprintf("%v", floatValue), -1) + localVarPath = strings.Replace(localVarPath, "{"+"double_value"+"}", fmt.Sprintf("%v", doubleValue), -1) + localVarPath = strings.Replace(localVarPath, "{"+"int64_value"+"}", fmt.Sprintf("%v", int64Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"uint64_value"+"}", fmt.Sprintf("%v", uint64Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"int32_value"+"}", fmt.Sprintf("%v", int32Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"fixed64_value"+"}", fmt.Sprintf("%v", fixed64Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"fixed32_value"+"}", fmt.Sprintf("%v", fixed32Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"bool_value"+"}", fmt.Sprintf("%v", boolValue), -1) + localVarPath = strings.Replace(localVarPath, "{"+"string_value"+"}", fmt.Sprintf("%v", stringValue), -1) + localVarPath = strings.Replace(localVarPath, "{"+"uint32_value"+"}", fmt.Sprintf("%v", uint32Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"sfixed32_value"+"}", fmt.Sprintf("%v", sfixed32Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"sfixed64_value"+"}", fmt.Sprintf("%v", sfixed64Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"sint32_value"+"}", fmt.Sprintf("%v", sint32Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"sint64_value"+"}", fmt.Sprintf("%v", sint64Value), -1) + localVarPath = strings.Replace(localVarPath, "{"+"nonConventionalNameValue"+"}", fmt.Sprintf("%v", nonConventionalNameValue), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + var successPayload = new(ExamplepbABitOfEverything) + 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: "Create", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param body + * @return *ExamplepbABitOfEverything + */ +func (a ABitOfEverythingServiceApi) CreateBody(body ExamplepbABitOfEverything) (*ExamplepbABitOfEverything, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Post") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &body + var successPayload = new(ExamplepbABitOfEverything) + 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: "CreateBody", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param singleNestedName + * @param body + * @return *ExamplepbABitOfEverything + */ +func (a ABitOfEverythingServiceApi) DeepPathEcho(singleNestedName string, body ExamplepbABitOfEverything) (*ExamplepbABitOfEverything, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Post") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/{single_nested.name}" + localVarPath = strings.Replace(localVarPath, "{"+"single_nested.name"+"}", fmt.Sprintf("%v", singleNestedName), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &body + var successPayload = new(ExamplepbABitOfEverything) + 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: "DeepPathEcho", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param uuid + * @return *ProtobufEmpty + */ +func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Delete") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/{uuid}" + localVarPath = strings.Replace(localVarPath, "{"+"uuid"+"}", fmt.Sprintf("%v", uuid), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + var successPayload = new(ProtobufEmpty) + 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: "Delete", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param value + * @return *SubStringMessage + */ +func (a ABitOfEverythingServiceApi) Echo(value string) (*SubStringMessage, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Get") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/echo/{value}" + localVarPath = strings.Replace(localVarPath, "{"+"value"+"}", fmt.Sprintf("%v", value), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + 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", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param value + * @return *SubStringMessage + */ +func (a ABitOfEverythingServiceApi) Echo_1(value string) (*SubStringMessage, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Get") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v2/example/echo" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + 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", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + 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()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param body + * @return *SubStringMessage + */ +func (a ABitOfEverythingServiceApi) Echo_2(body string) (*SubStringMessage, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Post") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v2/example/echo" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + 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()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param uuid + * @param singleNestedName name is nested field. + * @param singleNestedAmount + * @param singleNestedOk - FALSE: FALSE is false. - TRUE: TRUE is true. + * @param floatValue + * @param doubleValue + * @param int64Value + * @param uint64Value + * @param int32Value + * @param fixed64Value + * @param fixed32Value + * @param boolValue + * @param stringValue + * @param uint32Value TODO(yugui) add bytes_value. + * @param enumValue - ZERO: ZERO means 0 - ONE: ONE means 1 + * @param sfixed32Value + * @param sfixed64Value + * @param sint32Value + * @param sint64Value + * @param repeatedStringValue + * @param oneofString + * @param nonConventionalNameValue + * @param timestampValue + * @param repeatedEnumValue repeated enum value. it is comma-separated in query. - ZERO: ZERO means 0 - ONE: ONE means 1 + * @return *ProtobufEmpty + */ +func (a ABitOfEverythingServiceApi) GetQuery(uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, enumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (*ProtobufEmpty, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Get") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/query/{uuid}" + localVarPath = strings.Replace(localVarPath, "{"+"uuid"+"}", fmt.Sprintf("%v", uuid), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + localVarQueryParams.Add("single_nested.name", a.Configuration.APIClient.ParameterToString(singleNestedName, "")) + localVarQueryParams.Add("single_nested.amount", a.Configuration.APIClient.ParameterToString(singleNestedAmount, "")) + localVarQueryParams.Add("single_nested.ok", a.Configuration.APIClient.ParameterToString(singleNestedOk, "")) + localVarQueryParams.Add("float_value", a.Configuration.APIClient.ParameterToString(floatValue, "")) + localVarQueryParams.Add("double_value", a.Configuration.APIClient.ParameterToString(doubleValue, "")) + localVarQueryParams.Add("int64_value", a.Configuration.APIClient.ParameterToString(int64Value, "")) + localVarQueryParams.Add("uint64_value", a.Configuration.APIClient.ParameterToString(uint64Value, "")) + localVarQueryParams.Add("int32_value", a.Configuration.APIClient.ParameterToString(int32Value, "")) + localVarQueryParams.Add("fixed64_value", a.Configuration.APIClient.ParameterToString(fixed64Value, "")) + localVarQueryParams.Add("fixed32_value", a.Configuration.APIClient.ParameterToString(fixed32Value, "")) + localVarQueryParams.Add("bool_value", a.Configuration.APIClient.ParameterToString(boolValue, "")) + localVarQueryParams.Add("string_value", a.Configuration.APIClient.ParameterToString(stringValue, "")) + localVarQueryParams.Add("uint32_value", a.Configuration.APIClient.ParameterToString(uint32Value, "")) + localVarQueryParams.Add("enum_value", a.Configuration.APIClient.ParameterToString(enumValue, "")) + localVarQueryParams.Add("sfixed32_value", a.Configuration.APIClient.ParameterToString(sfixed32Value, "")) + localVarQueryParams.Add("sfixed64_value", a.Configuration.APIClient.ParameterToString(sfixed64Value, "")) + localVarQueryParams.Add("sint32_value", a.Configuration.APIClient.ParameterToString(sint32Value, "")) + localVarQueryParams.Add("sint64_value", a.Configuration.APIClient.ParameterToString(sint64Value, "")) + var repeatedStringValueCollectionFormat = "csv" + localVarQueryParams.Add("repeated_string_value", a.Configuration.APIClient.ParameterToString(repeatedStringValue, repeatedStringValueCollectionFormat)) + + localVarQueryParams.Add("oneof_string", a.Configuration.APIClient.ParameterToString(oneofString, "")) + localVarQueryParams.Add("nonConventionalNameValue", a.Configuration.APIClient.ParameterToString(nonConventionalNameValue, "")) + localVarQueryParams.Add("timestamp_value", a.Configuration.APIClient.ParameterToString(timestampValue, "")) + var repeatedEnumValueCollectionFormat = "csv" + localVarQueryParams.Add("repeated_enum_value", a.Configuration.APIClient.ParameterToString(repeatedEnumValue, repeatedEnumValueCollectionFormat)) + + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + var successPayload = new(ProtobufEmpty) + 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: "GetQuery", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param uuid + * @return *ExamplepbABitOfEverything + */ +func (a ABitOfEverythingServiceApi) Lookup(uuid string) (*ExamplepbABitOfEverything, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Get") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/{uuid}" + localVarPath = strings.Replace(localVarPath, "{"+"uuid"+"}", fmt.Sprintf("%v", uuid), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + var successPayload = new(ExamplepbABitOfEverything) + 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: "Lookup", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @return *ProtobufEmpty + */ +func (a ABitOfEverythingServiceApi) Timeout() (*ProtobufEmpty, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Get") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v2/example/timeout" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + var successPayload = new(ProtobufEmpty) + 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: "Timeout", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * + * + * @param uuid + * @param body + * @return *ProtobufEmpty + */ +func (a ABitOfEverythingServiceApi) Update(uuid string, body ExamplepbABitOfEverything) (*ProtobufEmpty, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Put") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/{uuid}" + localVarPath = strings.Replace(localVarPath, "{"+"uuid"+"}", fmt.Sprintf("%v", uuid), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &body + var successPayload = new(ProtobufEmpty) + 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: "Update", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + diff --git a/examples/clients/abe/api_client.go b/examples/clients/abe/api_client.go new file mode 100644 index 00000000000..2825dd48e13 --- /dev/null +++ b/examples/clients/abe/api_client.go @@ -0,0 +1,164 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +import ( + "bytes" + "fmt" + "path/filepath" + "reflect" + "strings" + "net/url" + "io/ioutil" + "github.com/go-resty/resty" +) + +type APIClient struct { + config *Configuration +} + +func (c *APIClient) SelectHeaderContentType(contentTypes []string) string { + + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +func (c *APIClient) SelectHeaderAccept(accepts []string) string { + + if len(accepts) == 0 { + return "" + } + if contains(accepts, "application/json") { + return "application/json" + } + return strings.Join(accepts, ",") +} + +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.ToLower(a) == strings.ToLower(needle) { + return true + } + } + return false +} + +func (c *APIClient) CallAPI(path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams map[string]string, + fileName string, + fileBytes []byte) (*resty.Response, error) { + + rClient := c.prepareClient() + request := c.prepareRequest(rClient, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + + switch strings.ToUpper(method) { + case "GET": + response, err := request.Get(path) + return response, err + case "POST": + response, err := request.Post(path) + return response, err + case "PUT": + response, err := request.Put(path) + return response, err + case "PATCH": + response, err := request.Patch(path) + return response, err + case "DELETE": + response, err := request.Delete(path) + return response, err + } + + return nil, fmt.Errorf("invalid method %v", method) +} + +func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string { + delimiter := "" + switch collectionFormat { + case "pipes": + delimiter = "|" + case "ssv": + delimiter = " " + case "tsv": + delimiter = "\t" + case "csv": + delimiter = "," + } + + if reflect.TypeOf(obj).Kind() == reflect.Slice { + return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") + } + + return fmt.Sprintf("%v", obj) +} + +func (c *APIClient) prepareClient() *resty.Client { + + rClient := resty.New() + + rClient.SetDebug(c.config.Debug) + if c.config.Transport != nil { + rClient.SetTransport(c.config.Transport) + } + + if c.config.Timeout != nil { + rClient.SetTimeout(*c.config.Timeout) + } + rClient.SetLogger(ioutil.Discard) + return rClient +} + +func (c *APIClient) prepareRequest( + rClient *resty.Client, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams map[string]string, + fileName string, + fileBytes []byte) *resty.Request { + + + request := rClient.R() + request.SetBody(postBody) + + if c.config.UserAgent != "" { + request.SetHeader("User-Agent", c.config.UserAgent) + } + + // add header parameter, if any + if len(headerParams) > 0 { + request.SetHeaders(headerParams) + } + + // add query parameter, if any + if len(queryParams) > 0 { + request.SetMultiValueQueryParams(queryParams) + } + + // add form parameter, if any + if len(formParams) > 0 { + request.SetFormData(formParams) + } + + if len(fileBytes) > 0 && fileName != "" { + _, fileNm := filepath.Split(fileName) + request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) + } + return request +} diff --git a/examples/clients/abe/api_response.go b/examples/clients/abe/api_response.go new file mode 100644 index 00000000000..8c14424b574 --- /dev/null +++ b/examples/clients/abe/api_response.go @@ -0,0 +1,44 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +import ( + "net/http" +) + +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the swagger operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/examples/clients/abe/configuration.go b/examples/clients/abe/configuration.go new file mode 100644 index 00000000000..5cacaadcb9d --- /dev/null +++ b/examples/clients/abe/configuration.go @@ -0,0 +1,67 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +import ( + "encoding/base64" + "net/http" + "time" +) + + +type Configuration struct { + Username string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` + APIKeyPrefix map[string]string `json:"APIKeyPrefix,omitempty"` + APIKey map[string]string `json:"APIKey,omitempty"` + Debug bool `json:"debug,omitempty"` + DebugFile string `json:"debugFile,omitempty"` + OAuthToken string `json:"oAuthToken,omitempty"` + BasePath string `json:"basePath,omitempty"` + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + AccessToken string `json:"accessToken,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + APIClient *APIClient + Transport *http.Transport + Timeout *time.Duration `json:"timeout,omitempty"` +} + +func NewConfiguration() *Configuration { + cfg := &Configuration{ + BasePath: "http://localhost", + DefaultHeader: make(map[string]string), + APIKey: make(map[string]string), + APIKeyPrefix: make(map[string]string), + UserAgent: "Swagger-Codegen/1.0.0/go", + APIClient: &APIClient{}, + } + + cfg.APIClient.config = cfg + return cfg +} + +func (c *Configuration) GetBasicAuthEncodedString() string { + return base64.StdEncoding.EncodeToString([]byte(c.Username + ":" + c.Password)) +} + +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +func (c *Configuration) GetAPIKeyWithPrefix(APIKeyIdentifier string) string { + if c.APIKeyPrefix[APIKeyIdentifier] != "" { + return c.APIKeyPrefix[APIKeyIdentifier] + " " + c.APIKey[APIKeyIdentifier] + } + + return c.APIKey[APIKeyIdentifier] +} diff --git a/examples/clients/abe/examplepb_a_bit_of_everything.go b/examples/clients/abe/examplepb_a_bit_of_everything.go new file mode 100644 index 00000000000..338ac379878 --- /dev/null +++ b/examples/clients/abe/examplepb_a_bit_of_everything.go @@ -0,0 +1,72 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +import ( + "time" +) + +type ExamplepbABitOfEverything struct { + + SingleNested ABitOfEverythingNested `json:"single_nested,omitempty"` + + Uuid string `json:"uuid,omitempty"` + + Nested []ABitOfEverythingNested `json:"nested,omitempty"` + + FloatValue float32 `json:"float_value,omitempty"` + + DoubleValue float64 `json:"double_value,omitempty"` + + Int64Value string `json:"int64_value,omitempty"` + + Uint64Value string `json:"uint64_value,omitempty"` + + Int32Value int32 `json:"int32_value,omitempty"` + + Fixed64Value string `json:"fixed64_value,omitempty"` + + Fixed32Value int64 `json:"fixed32_value,omitempty"` + + BoolValue bool `json:"bool_value,omitempty"` + + StringValue string `json:"string_value,omitempty"` + + Uint32Value int64 `json:"uint32_value,omitempty"` + + EnumValue ExamplepbNumericEnum `json:"enum_value,omitempty"` + + Sfixed32Value int32 `json:"sfixed32_value,omitempty"` + + Sfixed64Value string `json:"sfixed64_value,omitempty"` + + Sint32Value int32 `json:"sint32_value,omitempty"` + + Sint64Value string `json:"sint64_value,omitempty"` + + RepeatedStringValue []string `json:"repeated_string_value,omitempty"` + + OneofEmpty ProtobufEmpty `json:"oneof_empty,omitempty"` + + OneofString string `json:"oneof_string,omitempty"` + + MapValue map[string]ExamplepbNumericEnum `json:"map_value,omitempty"` + + MappedStringValue map[string]string `json:"mapped_string_value,omitempty"` + + MappedNestedValue map[string]ABitOfEverythingNested `json:"mapped_nested_value,omitempty"` + + NonConventionalNameValue string `json:"nonConventionalNameValue,omitempty"` + + TimestampValue time.Time `json:"timestamp_value,omitempty"` + + RepeatedEnumValue []ExamplepbNumericEnum `json:"repeated_enum_value,omitempty"` +} diff --git a/examples/clients/abe/examplepb_numeric_enum.go b/examples/clients/abe/examplepb_numeric_enum.go new file mode 100644 index 00000000000..bfb776292b3 --- /dev/null +++ b/examples/clients/abe/examplepb_numeric_enum.go @@ -0,0 +1,15 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +// NumericEnum is one or zero. - ZERO: ZERO means 0 - ONE: ONE means 1 +type ExamplepbNumericEnum struct { +} diff --git a/examples/clients/abe/nested_deep_enum.go b/examples/clients/abe/nested_deep_enum.go new file mode 100644 index 00000000000..50bf6235a29 --- /dev/null +++ b/examples/clients/abe/nested_deep_enum.go @@ -0,0 +1,15 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +// DeepEnum is one or zero. - FALSE: FALSE is false. - TRUE: TRUE is true. +type NestedDeepEnum struct { +} diff --git a/examples/clients/abe/protobuf_empty.go b/examples/clients/abe/protobuf_empty.go new file mode 100644 index 00000000000..0cf664849d2 --- /dev/null +++ b/examples/clients/abe/protobuf_empty.go @@ -0,0 +1,15 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +// service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } The JSON representation for `Empty` is empty JSON object `{}`. +type ProtobufEmpty struct { +} diff --git a/examples/clients/abe/sub_string_message.go b/examples/clients/abe/sub_string_message.go new file mode 100644 index 00000000000..0331c7abb94 --- /dev/null +++ b/examples/clients/abe/sub_string_message.go @@ -0,0 +1,16 @@ +/* + * examples/examplepb/a_bit_of_everything.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package abe + +type SubStringMessage struct { + + Value string `json:"value,omitempty"` +} diff --git a/examples/clients/echo/.gitignore b/examples/clients/echo/.gitignore new file mode 100644 index 00000000000..2f88269126d --- /dev/null +++ b/examples/clients/echo/.gitignore @@ -0,0 +1 @@ +/docs diff --git a/examples/clients/echo/.swagger-codegen-ignore b/examples/clients/echo/.swagger-codegen-ignore new file mode 100644 index 00000000000..6c7b69a0156 --- /dev/null +++ b/examples/clients/echo/.swagger-codegen-ignore @@ -0,0 +1 @@ +.gitignore diff --git a/examples/clients/echo/EchoServiceApi.go b/examples/clients/echo/EchoServiceApi.go deleted file mode 100644 index fe6d7341d3d..00000000000 --- a/examples/clients/echo/EchoServiceApi.go +++ /dev/null @@ -1,206 +0,0 @@ -package echo - -import ( - "strings" - "fmt" - "encoding/json" - "errors" - "github.com/dghubble/sling" -) - -type EchoServiceApi struct { - basePath string -} - -func NewEchoServiceApi() *EchoServiceApi{ - return &EchoServiceApi { - basePath: "http://localhost", - } -} - -func NewEchoServiceApiWithBasePath(basePath string) *EchoServiceApi{ - return &EchoServiceApi { - basePath: basePath, - } -} - -/** - * Echo method receives a simple message and returns it. - * The message posted as the id parameter will also be\nreturned. - * @param id - * @return ExamplepbSimpleMessage - */ -//func (a EchoServiceApi) Echo (id string) (ExamplepbSimpleMessage, error) { -func (a EchoServiceApi) Echo (id string) (ExamplepbSimpleMessage, error) { - - _sling := sling.New().Post(a.basePath) - - // create path and map variables - path := "/v1/example/echo/{id}" - path = strings.Replace(path, "{" + "id" + "}", fmt.Sprintf("%v", id), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ExamplepbSimpleMessage) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * EchoBody method receives a simple message and returns it. - * - * @param body - * @return ExamplepbSimpleMessage - */ -//func (a EchoServiceApi) EchoBody (body ExamplepbSimpleMessage) (ExamplepbSimpleMessage, error) { -func (a EchoServiceApi) EchoBody (body ExamplepbSimpleMessage) (ExamplepbSimpleMessage, error) { - - _sling := sling.New().Post(a.basePath) - - // create path and map variables - path := "/v1/example/echo_body" - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - -// body params - _sling = _sling.BodyJSON(body) - - var successPayload = new(ExamplepbSimpleMessage) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} -/** - * Echo method receives a simple message and returns it. - * The message posted as the id parameter will also be\nreturned. - * @param id - * @param num - * @return ExamplepbSimpleMessage - */ -//func (a EchoServiceApi) Echo_1 (id string, num string) (ExamplepbSimpleMessage, error) { -func (a EchoServiceApi) Echo_1 (id string, num string) (ExamplepbSimpleMessage, error) { - - _sling := sling.New().Get(a.basePath) - - // create path and map variables - path := "/v1/example/echo/{id}/{num}" - path = strings.Replace(path, "{" + "id" + "}", fmt.Sprintf("%v", id), -1) - path = strings.Replace(path, "{" + "num" + "}", fmt.Sprintf("%v", num), -1) - - _sling = _sling.Path(path) - - // accept header - accepts := []string { "application/json" } - for key := range accepts { - _sling = _sling.Set("Accept", accepts[key]) - break // only use the first Accept - } - - - var successPayload = new(ExamplepbSimpleMessage) - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return *successPayload, err -} diff --git a/examples/clients/echo/ExamplepbSimpleMessage.go b/examples/clients/echo/ExamplepbSimpleMessage.go deleted file mode 100644 index 3b1fe9bc344..00000000000 --- a/examples/clients/echo/ExamplepbSimpleMessage.go +++ /dev/null @@ -1,10 +0,0 @@ -package echo - -import ( -) - -type ExamplepbSimpleMessage struct { - Id string `json:"id,omitempty"` - Num string `json:"num,omitempty"` - -} diff --git a/examples/clients/echo/api_client.go b/examples/clients/echo/api_client.go new file mode 100644 index 00000000000..7a517148026 --- /dev/null +++ b/examples/clients/echo/api_client.go @@ -0,0 +1,164 @@ +/* + * Echo Service + * + * Echo Service API consists of a single service which returns a message. + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package echo + +import ( + "bytes" + "fmt" + "path/filepath" + "reflect" + "strings" + "net/url" + "io/ioutil" + "github.com/go-resty/resty" +) + +type APIClient struct { + config *Configuration +} + +func (c *APIClient) SelectHeaderContentType(contentTypes []string) string { + + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +func (c *APIClient) SelectHeaderAccept(accepts []string) string { + + if len(accepts) == 0 { + return "" + } + if contains(accepts, "application/json") { + return "application/json" + } + return strings.Join(accepts, ",") +} + +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.ToLower(a) == strings.ToLower(needle) { + return true + } + } + return false +} + +func (c *APIClient) CallAPI(path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams map[string]string, + fileName string, + fileBytes []byte) (*resty.Response, error) { + + rClient := c.prepareClient() + request := c.prepareRequest(rClient, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + + switch strings.ToUpper(method) { + case "GET": + response, err := request.Get(path) + return response, err + case "POST": + response, err := request.Post(path) + return response, err + case "PUT": + response, err := request.Put(path) + return response, err + case "PATCH": + response, err := request.Patch(path) + return response, err + case "DELETE": + response, err := request.Delete(path) + return response, err + } + + return nil, fmt.Errorf("invalid method %v", method) +} + +func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string { + delimiter := "" + switch collectionFormat { + case "pipes": + delimiter = "|" + case "ssv": + delimiter = " " + case "tsv": + delimiter = "\t" + case "csv": + delimiter = "," + } + + if reflect.TypeOf(obj).Kind() == reflect.Slice { + return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") + } + + return fmt.Sprintf("%v", obj) +} + +func (c *APIClient) prepareClient() *resty.Client { + + rClient := resty.New() + + rClient.SetDebug(c.config.Debug) + if c.config.Transport != nil { + rClient.SetTransport(c.config.Transport) + } + + if c.config.Timeout != nil { + rClient.SetTimeout(*c.config.Timeout) + } + rClient.SetLogger(ioutil.Discard) + return rClient +} + +func (c *APIClient) prepareRequest( + rClient *resty.Client, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams map[string]string, + fileName string, + fileBytes []byte) *resty.Request { + + + request := rClient.R() + request.SetBody(postBody) + + if c.config.UserAgent != "" { + request.SetHeader("User-Agent", c.config.UserAgent) + } + + // add header parameter, if any + if len(headerParams) > 0 { + request.SetHeaders(headerParams) + } + + // add query parameter, if any + if len(queryParams) > 0 { + request.SetMultiValueQueryParams(queryParams) + } + + // add form parameter, if any + if len(formParams) > 0 { + request.SetFormData(formParams) + } + + if len(fileBytes) > 0 && fileName != "" { + _, fileNm := filepath.Split(fileName) + request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) + } + return request +} diff --git a/examples/clients/echo/api_response.go b/examples/clients/echo/api_response.go new file mode 100644 index 00000000000..8b0d07c4a13 --- /dev/null +++ b/examples/clients/echo/api_response.go @@ -0,0 +1,44 @@ +/* + * Echo Service + * + * Echo Service API consists of a single service which returns a message. + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package echo + +import ( + "net/http" +) + +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the swagger operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/examples/clients/echo/configuration.go b/examples/clients/echo/configuration.go new file mode 100644 index 00000000000..9a75a30aeec --- /dev/null +++ b/examples/clients/echo/configuration.go @@ -0,0 +1,67 @@ +/* + * Echo Service + * + * Echo Service API consists of a single service which returns a message. + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package echo + +import ( + "encoding/base64" + "net/http" + "time" +) + + +type Configuration struct { + Username string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` + APIKeyPrefix map[string]string `json:"APIKeyPrefix,omitempty"` + APIKey map[string]string `json:"APIKey,omitempty"` + Debug bool `json:"debug,omitempty"` + DebugFile string `json:"debugFile,omitempty"` + OAuthToken string `json:"oAuthToken,omitempty"` + BasePath string `json:"basePath,omitempty"` + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + AccessToken string `json:"accessToken,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + APIClient *APIClient + Transport *http.Transport + Timeout *time.Duration `json:"timeout,omitempty"` +} + +func NewConfiguration() *Configuration { + cfg := &Configuration{ + BasePath: "http://localhost", + DefaultHeader: make(map[string]string), + APIKey: make(map[string]string), + APIKeyPrefix: make(map[string]string), + UserAgent: "Swagger-Codegen/1.0.0/go", + APIClient: &APIClient{}, + } + + cfg.APIClient.config = cfg + return cfg +} + +func (c *Configuration) GetBasicAuthEncodedString() string { + return base64.StdEncoding.EncodeToString([]byte(c.Username + ":" + c.Password)) +} + +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +func (c *Configuration) GetAPIKeyWithPrefix(APIKeyIdentifier string) string { + if c.APIKeyPrefix[APIKeyIdentifier] != "" { + return c.APIKeyPrefix[APIKeyIdentifier] + " " + c.APIKey[APIKeyIdentifier] + } + + return c.APIKey[APIKeyIdentifier] +} diff --git a/examples/clients/echo/echo_service_api.go b/examples/clients/echo/echo_service_api.go new file mode 100644 index 00000000000..a37a837adb2 --- /dev/null +++ b/examples/clients/echo/echo_service_api.go @@ -0,0 +1,224 @@ +/* + * Echo Service + * + * Echo Service API consists of a single service which returns a message. + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package echo + +import ( + "net/url" + "strings" + "encoding/json" + "fmt" +) + +type EchoServiceApi struct { + Configuration *Configuration +} + +func NewEchoServiceApi() *EchoServiceApi { + configuration := NewConfiguration() + return &EchoServiceApi{ + Configuration: configuration, + } +} + +func NewEchoServiceApiWithBasePath(basePath string) *EchoServiceApi { + configuration := NewConfiguration() + configuration.BasePath = basePath + + return &EchoServiceApi{ + Configuration: configuration, + } +} + +/** + * Echo method receives a simple message and returns it. + * The message posted as the id parameter will also be returned. + * + * @param id + * @return *ExamplepbSimpleMessage + */ +func (a EchoServiceApi) Echo(id string) (*ExamplepbSimpleMessage, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Post") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/echo/{id}" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", fmt.Sprintf("%v", id), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + 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", Method: localVarHttpMethod, RequestURL: localVarURL.String()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * EchoBody method receives a simple message and returns it. + * + * @param body + * @return *ExamplepbSimpleMessage + */ +func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleMessage, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Post") + // create path and map variables + localVarPath := a.Configuration.BasePath + "/v1/example/echo_body" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + 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()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + +/** + * Echo method receives a simple message and returns it. + * The message posted as the id parameter will also be returned. + * + * @param id + * @param num + * @return *ExamplepbSimpleMessage + */ +func (a EchoServiceApi) Echo_1(id string, num string) (*ExamplepbSimpleMessage, *APIResponse, error) { + + var localVarHttpMethod = strings.ToUpper("Get") + // 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) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := make(map[string]string) + var localVarPostBody interface{} + var localVarFileName string + var localVarFileBytes []byte + // add default headers if any + for key := range a.Configuration.DefaultHeader { + localVarHeaderParams[key] = a.Configuration.DefaultHeader[key] + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{ "application/json", } + + // set Content-Type header + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + } + + // set Accept header + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + 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()} + if localVarHttpResponse != nil { + localVarAPIResponse.Response = localVarHttpResponse.RawResponse + localVarAPIResponse.Payload = localVarHttpResponse.Body() + } + + if err != nil { + return successPayload, localVarAPIResponse, err + } + err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload) + return successPayload, localVarAPIResponse, err +} + diff --git a/examples/clients/echo/examplepb_simple_message.go b/examples/clients/echo/examplepb_simple_message.go new file mode 100644 index 00000000000..98eb8325083 --- /dev/null +++ b/examples/clients/echo/examplepb_simple_message.go @@ -0,0 +1,20 @@ +/* + * Echo Service + * + * Echo Service API consists of a single service which returns a message. + * + * OpenAPI spec version: version not set + * + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package echo + +// SimpleMessage represents a simple message sent to the Echo service. +type ExamplepbSimpleMessage struct { + + // Id represents the message identifier. + Id string `json:"id,omitempty"` + + Num string `json:"num,omitempty"` +}