From 72abb20f2e76534edd9e94beb57875e9c16faae7 Mon Sep 17 00:00:00 2001 From: antihax Date: Sun, 14 Jan 2018 03:00:17 -0600 Subject: [PATCH] [Go] Fix operation files clobbering model files. [2.4.0] (#7337) * Prevent operation files clobbering model files. * Update Tests --- .../codegen/languages/AbstractGoCodegen.java | 8 +- .../codegen/languages/GoClientCodegen.java | 4 +- .../{api_client.mustache => client.mustache} | 0 ...pi_response.mustache => response.mustache} | 0 .../go/go-petstore/.swagger-codegen/VERSION | 2 +- .../petstore/go/go-petstore/api/swagger.yaml | 8 +- ...nother_fake_api.go => api_another_fake.go} | 0 .../petstore/go/go-petstore/api_client.go | 441 ------------------ .../go-petstore/{fake_api.go => api_fake.go} | 0 ...3_api.go => api_fake_classname_tags123.go} | 0 .../go/go-petstore/{pet_api.go => api_pet.go} | 0 .../{store_api.go => api_store.go} | 0 .../go-petstore/{user_api.go => api_user.go} | 0 .../client/petstore/go/go-petstore/client.go | 430 ++++++++++++++++- ...o => model_additional_properties_class.go} | 0 .../{animal.go => model_animal.go} | 0 .../{animal_farm.go => model_animal_farm.go} | 0 ...=> model_array_of_array_of_number_only.go} | 0 ..._only.go => model_array_of_number_only.go} | 0 .../{array_test.go => model_array_test.go} | 0 ...italization.go => model_capitalization.go} | 0 .../go/go-petstore/{cat.go => model_cat.go} | 0 .../{category.go => model_category.go} | 0 .../{class_model.go => model_class_model.go} | 0 .../petstore/go/go-petstore/model_client.go | 15 + .../go/go-petstore/{dog.go => model_dog.go} | 0 .../{enum_arrays.go => model_enum_arrays.go} | 0 .../{enum_class.go => model_enum_class.go} | 0 .../{enum_test.go => model_enum_test.go} | 0 .../{format_test.go => model_format_test.go} | 0 ...ad_only.go => model_has_only_read_only.go} | 0 .../go/go-petstore/{list.go => model_list.go} | 0 .../{map_test.go => model_map_test.go} | 0 ...erties_and_additional_properties_class.go} | 0 .../go/go-petstore/{name.go => model_name.go} | 0 .../{number_only.go => model_number_only.go} | 0 .../go-petstore/{order.go => model_order.go} | 0 ...uter_boolean.go => model_outer_boolean.go} | 0 ..._composite.go => model_outer_composite.go} | 0 .../{outer_enum.go => model_outer_enum.go} | 0 ...{outer_number.go => model_outer_number.go} | 0 ...{outer_string.go => model_outer_string.go} | 0 .../go/go-petstore/{pet.go => model_pet.go} | 0 ...only_first.go => model_read_only_first.go} | 0 ...el_name.go => model_special_model_name.go} | 0 .../go/go-petstore/{tag.go => model_tag.go} | 0 .../go/go-petstore/{user.go => model_user.go} | 0 .../{api_response.go => response.go} | 0 .../go-api-server/.swagger-codegen/VERSION | 2 +- .../petstore/go-api-server/api/swagger.yaml | 2 +- .../petstore/go-api-server/go/README.md | 1 - .../go/{pet_api.go => api_pet.go} | 0 .../go/{store_api.go => api_store.go} | 0 .../go/{user_api.go => api_user.go} | 0 ...{api_response.go => model_api_response.go} | 0 .../go/{category.go => model_category.go} | 0 .../go/{order.go => model_order.go} | 0 .../go-api-server/go/{pet.go => model_pet.go} | 0 .../go-api-server/go/{tag.go => model_tag.go} | 0 .../go/{user.go => model_user.go} | 0 60 files changed, 458 insertions(+), 455 deletions(-) rename modules/swagger-codegen/src/main/resources/go/{api_client.mustache => client.mustache} (100%) rename modules/swagger-codegen/src/main/resources/go/{api_response.mustache => response.mustache} (100%) rename samples/client/petstore/go/go-petstore/{another_fake_api.go => api_another_fake.go} (100%) delete mode 100644 samples/client/petstore/go/go-petstore/api_client.go rename samples/client/petstore/go/go-petstore/{fake_api.go => api_fake.go} (100%) rename samples/client/petstore/go/go-petstore/{fake_classname_tags123_api.go => api_fake_classname_tags123.go} (100%) rename samples/client/petstore/go/go-petstore/{pet_api.go => api_pet.go} (100%) rename samples/client/petstore/go/go-petstore/{store_api.go => api_store.go} (100%) rename samples/client/petstore/go/go-petstore/{user_api.go => api_user.go} (100%) rename samples/client/petstore/go/go-petstore/{additional_properties_class.go => model_additional_properties_class.go} (100%) rename samples/client/petstore/go/go-petstore/{animal.go => model_animal.go} (100%) rename samples/client/petstore/go/go-petstore/{animal_farm.go => model_animal_farm.go} (100%) rename samples/client/petstore/go/go-petstore/{array_of_array_of_number_only.go => model_array_of_array_of_number_only.go} (100%) rename samples/client/petstore/go/go-petstore/{array_of_number_only.go => model_array_of_number_only.go} (100%) rename samples/client/petstore/go/go-petstore/{array_test.go => model_array_test.go} (100%) rename samples/client/petstore/go/go-petstore/{capitalization.go => model_capitalization.go} (100%) rename samples/client/petstore/go/go-petstore/{cat.go => model_cat.go} (100%) rename samples/client/petstore/go/go-petstore/{category.go => model_category.go} (100%) rename samples/client/petstore/go/go-petstore/{class_model.go => model_class_model.go} (100%) create mode 100644 samples/client/petstore/go/go-petstore/model_client.go rename samples/client/petstore/go/go-petstore/{dog.go => model_dog.go} (100%) rename samples/client/petstore/go/go-petstore/{enum_arrays.go => model_enum_arrays.go} (100%) rename samples/client/petstore/go/go-petstore/{enum_class.go => model_enum_class.go} (100%) rename samples/client/petstore/go/go-petstore/{enum_test.go => model_enum_test.go} (100%) rename samples/client/petstore/go/go-petstore/{format_test.go => model_format_test.go} (100%) rename samples/client/petstore/go/go-petstore/{has_only_read_only.go => model_has_only_read_only.go} (100%) rename samples/client/petstore/go/go-petstore/{list.go => model_list.go} (100%) rename samples/client/petstore/go/go-petstore/{map_test.go => model_map_test.go} (100%) rename samples/client/petstore/go/go-petstore/{mixed_properties_and_additional_properties_class.go => model_mixed_properties_and_additional_properties_class.go} (100%) rename samples/client/petstore/go/go-petstore/{name.go => model_name.go} (100%) rename samples/client/petstore/go/go-petstore/{number_only.go => model_number_only.go} (100%) rename samples/client/petstore/go/go-petstore/{order.go => model_order.go} (100%) rename samples/client/petstore/go/go-petstore/{outer_boolean.go => model_outer_boolean.go} (100%) rename samples/client/petstore/go/go-petstore/{outer_composite.go => model_outer_composite.go} (100%) rename samples/client/petstore/go/go-petstore/{outer_enum.go => model_outer_enum.go} (100%) rename samples/client/petstore/go/go-petstore/{outer_number.go => model_outer_number.go} (100%) rename samples/client/petstore/go/go-petstore/{outer_string.go => model_outer_string.go} (100%) rename samples/client/petstore/go/go-petstore/{pet.go => model_pet.go} (100%) rename samples/client/petstore/go/go-petstore/{read_only_first.go => model_read_only_first.go} (100%) rename samples/client/petstore/go/go-petstore/{special_model_name.go => model_special_model_name.go} (100%) rename samples/client/petstore/go/go-petstore/{tag.go => model_tag.go} (100%) rename samples/client/petstore/go/go-petstore/{user.go => model_user.go} (100%) rename samples/client/petstore/go/go-petstore/{api_response.go => response.go} (100%) rename samples/server/petstore/go-api-server/go/{pet_api.go => api_pet.go} (100%) rename samples/server/petstore/go-api-server/go/{store_api.go => api_store.go} (100%) rename samples/server/petstore/go-api-server/go/{user_api.go => api_user.go} (100%) rename samples/server/petstore/go-api-server/go/{api_response.go => model_api_response.go} (100%) rename samples/server/petstore/go-api-server/go/{category.go => model_category.go} (100%) rename samples/server/petstore/go-api-server/go/{order.go => model_order.go} (100%) rename samples/server/petstore/go-api-server/go/{pet.go => model_pet.go} (100%) rename samples/server/petstore/go-api-server/go/{tag.go => model_tag.go} (100%) rename samples/server/petstore/go-api-server/go/{user.go => model_user.go} (100%) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractGoCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractGoCodegen.java index 73d99e60a288..0dda8be74386 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractGoCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractGoCodegen.java @@ -152,11 +152,15 @@ public String toParamName(String name) { public String toModelName(String name) { // camelize the model name // phone_number => PhoneNumber - return camelize(toModelFilename(name)); + return camelize(toModel(name)); } @Override public String toModelFilename(String name) { + return toModel("model_" + name); + } + + public String toModel(String name) { if (!StringUtils.isEmpty(modelNamePrefix)) { name = modelNamePrefix + "_" + name; } @@ -188,7 +192,7 @@ public String toApiFilename(String name) { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PetApi.go => pet_api.go - return underscore(name) + "_api"; + return "api_" + underscore(name); } /** diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index 8ee82ceb4858..74d743bcf114 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -92,8 +92,8 @@ public void processOpts() { supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go")); - supportingFiles.add(new SupportingFile("api_client.mustache", "", "api_client.go")); - supportingFiles.add(new SupportingFile("api_response.mustache", "", "api_response.go")); + supportingFiles.add(new SupportingFile("client.mustache", "", "client.go")); + supportingFiles.add(new SupportingFile("response.mustache", "", "response.go")); supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml")); } diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/client.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/go/api_client.mustache rename to modules/swagger-codegen/src/main/resources/go/client.mustache diff --git a/modules/swagger-codegen/src/main/resources/go/api_response.mustache b/modules/swagger-codegen/src/main/resources/go/response.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/go/api_response.mustache rename to modules/swagger-codegen/src/main/resources/go/response.mustache diff --git a/samples/client/petstore/go/go-petstore/.swagger-codegen/VERSION b/samples/client/petstore/go/go-petstore/.swagger-codegen/VERSION index f9f7450d1359..855ff9501eb8 100644 --- a/samples/client/petstore/go/go-petstore/.swagger-codegen/VERSION +++ b/samples/client/petstore/go/go-petstore/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/api/swagger.yaml b/samples/client/petstore/go/go-petstore/api/swagger.yaml index 7edbe6eb94ad..2875d7c7c1e3 100644 --- a/samples/client/petstore/go/go-petstore/api/swagger.yaml +++ b/samples/client/petstore/go/go-petstore/api/swagger.yaml @@ -107,11 +107,11 @@ paths: type: "array" items: type: "string" - default: "available" enum: - "available" - "pending" - "sold" + default: "available" collectionFormat: "csv" x-exportParamName: "Status" responses: @@ -634,10 +634,10 @@ paths: type: "array" items: type: "string" - default: "$" enum: - ">" - "$" + default: "$" x-exportParamName: "EnumFormStringArray" - name: "enum_form_string" in: "formData" @@ -657,10 +657,10 @@ paths: type: "array" items: type: "string" - default: "$" enum: - ">" - "$" + default: "$" x-exportParamName: "EnumHeaderStringArray" - name: "enum_header_string" in: "header" @@ -680,10 +680,10 @@ paths: type: "array" items: type: "string" - default: "$" enum: - ">" - "$" + default: "$" x-exportParamName: "EnumQueryStringArray" - name: "enum_query_string" in: "query" diff --git a/samples/client/petstore/go/go-petstore/another_fake_api.go b/samples/client/petstore/go/go-petstore/api_another_fake.go similarity index 100% rename from samples/client/petstore/go/go-petstore/another_fake_api.go rename to samples/client/petstore/go/go-petstore/api_another_fake.go diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go deleted file mode 100644 index d2f8f3092c33..000000000000 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Swagger Petstore - * - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * API version: 1.0.0 - * Contact: apiteam@swagger.io - * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ - -package petstore - -import ( - "bytes" - "encoding/json" - "encoding/xml" - "errors" - "fmt" - "io" - "mime/multipart" - "net/http" - "net/url" - "os" - "path/filepath" - "reflect" - "regexp" - "strconv" - "strings" - "time" - "unicode/utf8" - - "golang.org/x/net/context" - "golang.org/x/oauth2" -) - -var ( - jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") - xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") -) - -// APIClient manages communication with the Swagger Petstore API v1.0.0 -// In most cases there should be only one, shared, APIClient. -type APIClient struct { - cfg *Configuration - common service // Reuse a single struct instead of allocating one for each service on the heap. - - // API Services - - AnotherFakeApi *AnotherFakeApiService - - FakeApi *FakeApiService - - FakeClassnameTags123Api *FakeClassnameTags123ApiService - - PetApi *PetApiService - - StoreApi *StoreApiService - - UserApi *UserApiService -} - -type service struct { - client *APIClient -} - -// NewAPIClient creates a new API client. Requires a userAgent string describing your application. -// optionally a custom http.Client to allow for advanced features such as caching. -func NewAPIClient(cfg *Configuration) *APIClient { - if cfg.HTTPClient == nil { - cfg.HTTPClient = http.DefaultClient - } - - c := &APIClient{} - c.cfg = cfg - c.common.client = c - - // API Services - c.AnotherFakeApi = (*AnotherFakeApiService)(&c.common) - c.FakeApi = (*FakeApiService)(&c.common) - c.FakeClassnameTags123Api = (*FakeClassnameTags123ApiService)(&c.common) - c.PetApi = (*PetApiService)(&c.common) - c.StoreApi = (*StoreApiService)(&c.common) - c.UserApi = (*UserApiService)(&c.common) - - return c -} - -func atoi(in string) (int, error) { - return strconv.Atoi(in) -} - -// selectHeaderContentType select a content type from the available list. -func 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' -} - -// selectHeaderAccept join all accept types and return -func selectHeaderAccept(accepts []string) string { - if len(accepts) == 0 { - return "" - } - - if contains(accepts, "application/json") { - return "application/json" - } - - return strings.Join(accepts, ",") -} - -// contains is a case insenstive match, finding needle in a haystack -func contains(haystack []string, needle string) bool { - for _, a := range haystack { - if strings.ToLower(a) == strings.ToLower(needle) { - return true - } - } - return false -} - -// Verify optional parameters are of the correct type. -func typeCheckParameter(obj interface{}, expected string, name string) error { - // Make sure there is an object. - if obj == nil { - return nil - } - - // Check the type is as expected. - if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) - } - return nil -} - -// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. -func parameterToString(obj interface{}, collectionFormat string) string { - var delimiter string - - 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) -} - -// callAPI do the request. -func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { - return c.cfg.HTTPClient.Do(request) -} - -// Change base path to allow switching to mocks -func (c *APIClient) ChangeBasePath(path string) { - c.cfg.BasePath = path -} - -// prepareRequest build the request -func (c *APIClient) prepareRequest( - ctx context.Context, - path string, method string, - postBody interface{}, - headerParams map[string]string, - queryParams url.Values, - formParams url.Values, - fileName string, - fileBytes []byte) (localVarRequest *http.Request, err error) { - - var body *bytes.Buffer - - // Detect postBody type and post. - if postBody != nil { - contentType := headerParams["Content-Type"] - if contentType == "" { - contentType = detectContentType(postBody) - headerParams["Content-Type"] = contentType - } - - body, err = setBody(postBody, contentType) - if err != nil { - return nil, err - } - } - - // add form parameters and file if available. - if len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") { - if body != nil { - return nil, errors.New("Cannot specify postBody and multipart form at the same time.") - } - body = &bytes.Buffer{} - w := multipart.NewWriter(body) - - for k, v := range formParams { - for _, iv := range v { - if strings.HasPrefix(k, "@") { // file - err = addFile(w, k[1:], iv) - if err != nil { - return nil, err - } - } else { // form value - w.WriteField(k, iv) - } - } - } - if len(fileBytes) > 0 && fileName != "" { - w.Boundary() - //_, fileNm := filepath.Split(fileName) - part, err := w.CreateFormFile("file", filepath.Base(fileName)) - if err != nil { - return nil, err - } - _, err = part.Write(fileBytes) - if err != nil { - return nil, err - } - // Set the Boundary in the Content-Type - headerParams["Content-Type"] = w.FormDataContentType() - } - - // Set Content-Length - headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) - w.Close() - } - - // Setup path and query parameters - url, err := url.Parse(path) - if err != nil { - return nil, err - } - - // Adding Query Param - query := url.Query() - for k, v := range queryParams { - for _, iv := range v { - query.Add(k, iv) - } - } - - // Encode the parameters. - url.RawQuery = query.Encode() - - // Generate a new request - if body != nil { - localVarRequest, err = http.NewRequest(method, url.String(), body) - } else { - localVarRequest, err = http.NewRequest(method, url.String(), nil) - } - if err != nil { - return nil, err - } - - // add header parameters, if any - if len(headerParams) > 0 { - headers := http.Header{} - for h, v := range headerParams { - headers.Set(h, v) - } - localVarRequest.Header = headers - } - - // Override request host, if applicable - if c.cfg.Host != "" { - localVarRequest.Host = c.cfg.Host - } - - // Add the user agent to the request. - localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) - - if ctx != nil { - // add context to the request - localVarRequest = localVarRequest.WithContext(ctx) - - // Walk through any authentication. - - // OAuth2 authentication - if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { - // We were able to grab an oauth2 token from the context - var latestToken *oauth2.Token - if latestToken, err = tok.Token(); err != nil { - return nil, err - } - - latestToken.SetAuthHeader(localVarRequest) - } - - // Basic HTTP Authentication - if auth, ok := ctx.Value(ContextBasicAuth).(BasicAuth); ok { - localVarRequest.SetBasicAuth(auth.UserName, auth.Password) - } - - // AccessToken Authentication - if auth, ok := ctx.Value(ContextAccessToken).(string); ok { - localVarRequest.Header.Add("Authorization", "Bearer "+auth) - } - } - - for header, value := range c.cfg.DefaultHeader { - localVarRequest.Header.Add(header, value) - } - - return localVarRequest, nil -} - -// Add a file to the multipart request -func addFile(w *multipart.Writer, fieldName, path string) error { - file, err := os.Open(path) - if err != nil { - return err - } - defer file.Close() - - part, err := w.CreateFormFile(fieldName, filepath.Base(path)) - if err != nil { - return err - } - _, err = io.Copy(part, file) - - return err -} - -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// Set request body from an interface{} -func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { - if bodyBuf == nil { - bodyBuf = &bytes.Buffer{} - } - - if reader, ok := body.(io.Reader); ok { - _, err = bodyBuf.ReadFrom(reader) - } else if b, ok := body.([]byte); ok { - _, err = bodyBuf.Write(b) - } else if s, ok := body.(string); ok { - _, err = bodyBuf.WriteString(s) - } else if jsonCheck.MatchString(contentType) { - err = json.NewEncoder(bodyBuf).Encode(body) - } else if xmlCheck.MatchString(contentType) { - xml.NewEncoder(bodyBuf).Encode(body) - } - - if err != nil { - return nil, err - } - - if bodyBuf.Len() == 0 { - err = fmt.Errorf("Invalid body type %s\n", contentType) - return nil, err - } - return bodyBuf, nil -} - -// detectContentType method is used to figure out `Request.Body` content type for request header -func detectContentType(body interface{}) string { - contentType := "text/plain; charset=utf-8" - kind := reflect.TypeOf(body).Kind() - - switch kind { - case reflect.Struct, reflect.Map, reflect.Ptr: - contentType = "application/json; charset=utf-8" - case reflect.String: - contentType = "text/plain; charset=utf-8" - default: - if b, ok := body.([]byte); ok { - contentType = http.DetectContentType(b) - } else if kind == reflect.Slice { - contentType = "application/json; charset=utf-8" - } - } - - return contentType -} - -// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go -type cacheControl map[string]string - -func parseCacheControl(headers http.Header) cacheControl { - cc := cacheControl{} - ccHeader := headers.Get("Cache-Control") - for _, part := range strings.Split(ccHeader, ",") { - part = strings.Trim(part, " ") - if part == "" { - continue - } - if strings.ContainsRune(part, '=') { - keyval := strings.Split(part, "=") - cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") - } else { - cc[part] = "" - } - } - return cc -} - -// CacheExpires helper function to determine remaining time before repeating a request. -func CacheExpires(r *http.Response) time.Time { - // Figure out when the cache expires. - var expires time.Time - now, err := time.Parse(time.RFC1123, r.Header.Get("date")) - if err != nil { - return time.Now() - } - respCacheControl := parseCacheControl(r.Header) - - if maxAge, ok := respCacheControl["max-age"]; ok { - lifetime, err := time.ParseDuration(maxAge + "s") - if err != nil { - expires = now - } - expires = now.Add(lifetime) - } else { - expiresHeader := r.Header.Get("Expires") - if expiresHeader != "" { - expires, err = time.Parse(time.RFC1123, expiresHeader) - if err != nil { - expires = now - } - } - } - return expires -} - -func strlen(s string) int { - return utf8.RuneCountInString(s) -} diff --git a/samples/client/petstore/go/go-petstore/fake_api.go b/samples/client/petstore/go/go-petstore/api_fake.go similarity index 100% rename from samples/client/petstore/go/go-petstore/fake_api.go rename to samples/client/petstore/go/go-petstore/api_fake.go diff --git a/samples/client/petstore/go/go-petstore/fake_classname_tags123_api.go b/samples/client/petstore/go/go-petstore/api_fake_classname_tags123.go similarity index 100% rename from samples/client/petstore/go/go-petstore/fake_classname_tags123_api.go rename to samples/client/petstore/go/go-petstore/api_fake_classname_tags123.go diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/api_pet.go similarity index 100% rename from samples/client/petstore/go/go-petstore/pet_api.go rename to samples/client/petstore/go/go-petstore/api_pet.go diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/api_store.go similarity index 100% rename from samples/client/petstore/go/go-petstore/store_api.go rename to samples/client/petstore/go/go-petstore/api_store.go diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/api_user.go similarity index 100% rename from samples/client/petstore/go/go-petstore/user_api.go rename to samples/client/petstore/go/go-petstore/api_user.go diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index fb393f1f9cee..d2f8f3092c33 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -10,6 +10,432 @@ package petstore -type Client struct { - Client string `json:"client,omitempty"` +import ( + "bytes" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "mime/multipart" + "net/http" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/net/context" + "golang.org/x/oauth2" +) + +var ( + jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") + xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") +) + +// APIClient manages communication with the Swagger Petstore API v1.0.0 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + AnotherFakeApi *AnotherFakeApiService + + FakeApi *FakeApiService + + FakeClassnameTags123Api *FakeClassnameTags123ApiService + + PetApi *PetApiService + + StoreApi *StoreApiService + + UserApi *UserApiService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.AnotherFakeApi = (*AnotherFakeApiService)(&c.common) + c.FakeApi = (*FakeApiService)(&c.common) + c.FakeClassnameTags123Api = (*FakeClassnameTags123ApiService)(&c.common) + c.PetApi = (*PetApiService)(&c.common) + c.StoreApi = (*StoreApiService)(&c.common) + c.UserApi = (*UserApiService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func 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' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insenstive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.ToLower(a) == strings.ToLower(needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. +func parameterToString(obj interface{}, collectionFormat string) string { + var delimiter string + + 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) +} + +// callAPI do the request. +func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { + return c.cfg.HTTPClient.Do(request) +} + +// Change base path to allow switching to mocks +func (c *APIClient) ChangeBasePath(path string) { + c.cfg.BasePath = path +} + +// prepareRequest build the request +func (c *APIClient) prepareRequest( + ctx context.Context, + path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams url.Values, + fileName string, + fileBytes []byte) (localVarRequest *http.Request, err error) { + + var body *bytes.Buffer + + // Detect postBody type and post. + if postBody != nil { + contentType := headerParams["Content-Type"] + if contentType == "" { + contentType = detectContentType(postBody) + headerParams["Content-Type"] = contentType + } + + body, err = setBody(postBody, contentType) + if err != nil { + return nil, err + } + } + + // add form parameters and file if available. + if len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + if len(fileBytes) > 0 && fileName != "" { + w.Boundary() + //_, fileNm := filepath.Split(fileName) + part, err := w.CreateFormFile("file", filepath.Base(fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(fileBytes) + if err != nil { + return nil, err + } + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + } + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = query.Encode() + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers.Set(h, v) + } + localVarRequest.Header = headers + } + + // Override request host, if applicable + if c.cfg.Host != "" { + localVarRequest.Host = c.cfg.Host + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // Basic HTTP Authentication + if auth, ok := ctx.Value(ContextBasicAuth).(BasicAuth); ok { + localVarRequest.SetBasicAuth(auth.UserName, auth.Password) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + + return localVarRequest, nil +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(path) + if err != nil { + return err + } + defer file.Close() + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if jsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if xmlCheck.MatchString(contentType) { + xml.NewEncoder(bodyBuf).Encode(body) + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("Invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } + expires = now.Add(lifetime) + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) } diff --git a/samples/client/petstore/go/go-petstore/additional_properties_class.go b/samples/client/petstore/go/go-petstore/model_additional_properties_class.go similarity index 100% rename from samples/client/petstore/go/go-petstore/additional_properties_class.go rename to samples/client/petstore/go/go-petstore/model_additional_properties_class.go diff --git a/samples/client/petstore/go/go-petstore/animal.go b/samples/client/petstore/go/go-petstore/model_animal.go similarity index 100% rename from samples/client/petstore/go/go-petstore/animal.go rename to samples/client/petstore/go/go-petstore/model_animal.go diff --git a/samples/client/petstore/go/go-petstore/animal_farm.go b/samples/client/petstore/go/go-petstore/model_animal_farm.go similarity index 100% rename from samples/client/petstore/go/go-petstore/animal_farm.go rename to samples/client/petstore/go/go-petstore/model_animal_farm.go diff --git a/samples/client/petstore/go/go-petstore/array_of_array_of_number_only.go b/samples/client/petstore/go/go-petstore/model_array_of_array_of_number_only.go similarity index 100% rename from samples/client/petstore/go/go-petstore/array_of_array_of_number_only.go rename to samples/client/petstore/go/go-petstore/model_array_of_array_of_number_only.go diff --git a/samples/client/petstore/go/go-petstore/array_of_number_only.go b/samples/client/petstore/go/go-petstore/model_array_of_number_only.go similarity index 100% rename from samples/client/petstore/go/go-petstore/array_of_number_only.go rename to samples/client/petstore/go/go-petstore/model_array_of_number_only.go diff --git a/samples/client/petstore/go/go-petstore/array_test.go b/samples/client/petstore/go/go-petstore/model_array_test.go similarity index 100% rename from samples/client/petstore/go/go-petstore/array_test.go rename to samples/client/petstore/go/go-petstore/model_array_test.go diff --git a/samples/client/petstore/go/go-petstore/capitalization.go b/samples/client/petstore/go/go-petstore/model_capitalization.go similarity index 100% rename from samples/client/petstore/go/go-petstore/capitalization.go rename to samples/client/petstore/go/go-petstore/model_capitalization.go diff --git a/samples/client/petstore/go/go-petstore/cat.go b/samples/client/petstore/go/go-petstore/model_cat.go similarity index 100% rename from samples/client/petstore/go/go-petstore/cat.go rename to samples/client/petstore/go/go-petstore/model_cat.go diff --git a/samples/client/petstore/go/go-petstore/category.go b/samples/client/petstore/go/go-petstore/model_category.go similarity index 100% rename from samples/client/petstore/go/go-petstore/category.go rename to samples/client/petstore/go/go-petstore/model_category.go diff --git a/samples/client/petstore/go/go-petstore/class_model.go b/samples/client/petstore/go/go-petstore/model_class_model.go similarity index 100% rename from samples/client/petstore/go/go-petstore/class_model.go rename to samples/client/petstore/go/go-petstore/model_class_model.go diff --git a/samples/client/petstore/go/go-petstore/model_client.go b/samples/client/petstore/go/go-petstore/model_client.go new file mode 100644 index 000000000000..fb393f1f9cee --- /dev/null +++ b/samples/client/petstore/go/go-petstore/model_client.go @@ -0,0 +1,15 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstore + +type Client struct { + Client string `json:"client,omitempty"` +} diff --git a/samples/client/petstore/go/go-petstore/dog.go b/samples/client/petstore/go/go-petstore/model_dog.go similarity index 100% rename from samples/client/petstore/go/go-petstore/dog.go rename to samples/client/petstore/go/go-petstore/model_dog.go diff --git a/samples/client/petstore/go/go-petstore/enum_arrays.go b/samples/client/petstore/go/go-petstore/model_enum_arrays.go similarity index 100% rename from samples/client/petstore/go/go-petstore/enum_arrays.go rename to samples/client/petstore/go/go-petstore/model_enum_arrays.go diff --git a/samples/client/petstore/go/go-petstore/enum_class.go b/samples/client/petstore/go/go-petstore/model_enum_class.go similarity index 100% rename from samples/client/petstore/go/go-petstore/enum_class.go rename to samples/client/petstore/go/go-petstore/model_enum_class.go diff --git a/samples/client/petstore/go/go-petstore/enum_test.go b/samples/client/petstore/go/go-petstore/model_enum_test.go similarity index 100% rename from samples/client/petstore/go/go-petstore/enum_test.go rename to samples/client/petstore/go/go-petstore/model_enum_test.go diff --git a/samples/client/petstore/go/go-petstore/format_test.go b/samples/client/petstore/go/go-petstore/model_format_test.go similarity index 100% rename from samples/client/petstore/go/go-petstore/format_test.go rename to samples/client/petstore/go/go-petstore/model_format_test.go diff --git a/samples/client/petstore/go/go-petstore/has_only_read_only.go b/samples/client/petstore/go/go-petstore/model_has_only_read_only.go similarity index 100% rename from samples/client/petstore/go/go-petstore/has_only_read_only.go rename to samples/client/petstore/go/go-petstore/model_has_only_read_only.go diff --git a/samples/client/petstore/go/go-petstore/list.go b/samples/client/petstore/go/go-petstore/model_list.go similarity index 100% rename from samples/client/petstore/go/go-petstore/list.go rename to samples/client/petstore/go/go-petstore/model_list.go diff --git a/samples/client/petstore/go/go-petstore/map_test.go b/samples/client/petstore/go/go-petstore/model_map_test.go similarity index 100% rename from samples/client/petstore/go/go-petstore/map_test.go rename to samples/client/petstore/go/go-petstore/model_map_test.go diff --git a/samples/client/petstore/go/go-petstore/mixed_properties_and_additional_properties_class.go b/samples/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go similarity index 100% rename from samples/client/petstore/go/go-petstore/mixed_properties_and_additional_properties_class.go rename to samples/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go diff --git a/samples/client/petstore/go/go-petstore/name.go b/samples/client/petstore/go/go-petstore/model_name.go similarity index 100% rename from samples/client/petstore/go/go-petstore/name.go rename to samples/client/petstore/go/go-petstore/model_name.go diff --git a/samples/client/petstore/go/go-petstore/number_only.go b/samples/client/petstore/go/go-petstore/model_number_only.go similarity index 100% rename from samples/client/petstore/go/go-petstore/number_only.go rename to samples/client/petstore/go/go-petstore/model_number_only.go diff --git a/samples/client/petstore/go/go-petstore/order.go b/samples/client/petstore/go/go-petstore/model_order.go similarity index 100% rename from samples/client/petstore/go/go-petstore/order.go rename to samples/client/petstore/go/go-petstore/model_order.go diff --git a/samples/client/petstore/go/go-petstore/outer_boolean.go b/samples/client/petstore/go/go-petstore/model_outer_boolean.go similarity index 100% rename from samples/client/petstore/go/go-petstore/outer_boolean.go rename to samples/client/petstore/go/go-petstore/model_outer_boolean.go diff --git a/samples/client/petstore/go/go-petstore/outer_composite.go b/samples/client/petstore/go/go-petstore/model_outer_composite.go similarity index 100% rename from samples/client/petstore/go/go-petstore/outer_composite.go rename to samples/client/petstore/go/go-petstore/model_outer_composite.go diff --git a/samples/client/petstore/go/go-petstore/outer_enum.go b/samples/client/petstore/go/go-petstore/model_outer_enum.go similarity index 100% rename from samples/client/petstore/go/go-petstore/outer_enum.go rename to samples/client/petstore/go/go-petstore/model_outer_enum.go diff --git a/samples/client/petstore/go/go-petstore/outer_number.go b/samples/client/petstore/go/go-petstore/model_outer_number.go similarity index 100% rename from samples/client/petstore/go/go-petstore/outer_number.go rename to samples/client/petstore/go/go-petstore/model_outer_number.go diff --git a/samples/client/petstore/go/go-petstore/outer_string.go b/samples/client/petstore/go/go-petstore/model_outer_string.go similarity index 100% rename from samples/client/petstore/go/go-petstore/outer_string.go rename to samples/client/petstore/go/go-petstore/model_outer_string.go diff --git a/samples/client/petstore/go/go-petstore/pet.go b/samples/client/petstore/go/go-petstore/model_pet.go similarity index 100% rename from samples/client/petstore/go/go-petstore/pet.go rename to samples/client/petstore/go/go-petstore/model_pet.go diff --git a/samples/client/petstore/go/go-petstore/read_only_first.go b/samples/client/petstore/go/go-petstore/model_read_only_first.go similarity index 100% rename from samples/client/petstore/go/go-petstore/read_only_first.go rename to samples/client/petstore/go/go-petstore/model_read_only_first.go diff --git a/samples/client/petstore/go/go-petstore/special_model_name.go b/samples/client/petstore/go/go-petstore/model_special_model_name.go similarity index 100% rename from samples/client/petstore/go/go-petstore/special_model_name.go rename to samples/client/petstore/go/go-petstore/model_special_model_name.go diff --git a/samples/client/petstore/go/go-petstore/tag.go b/samples/client/petstore/go/go-petstore/model_tag.go similarity index 100% rename from samples/client/petstore/go/go-petstore/tag.go rename to samples/client/petstore/go/go-petstore/model_tag.go diff --git a/samples/client/petstore/go/go-petstore/user.go b/samples/client/petstore/go/go-petstore/model_user.go similarity index 100% rename from samples/client/petstore/go/go-petstore/user.go rename to samples/client/petstore/go/go-petstore/model_user.go diff --git a/samples/client/petstore/go/go-petstore/api_response.go b/samples/client/petstore/go/go-petstore/response.go similarity index 100% rename from samples/client/petstore/go/go-petstore/api_response.go rename to samples/client/petstore/go/go-petstore/response.go diff --git a/samples/server/petstore/go-api-server/.swagger-codegen/VERSION b/samples/server/petstore/go-api-server/.swagger-codegen/VERSION index f9f7450d1359..855ff9501eb8 100644 --- a/samples/server/petstore/go-api-server/.swagger-codegen/VERSION +++ b/samples/server/petstore/go-api-server/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/go-api-server/api/swagger.yaml b/samples/server/petstore/go-api-server/api/swagger.yaml index 33babbaaeca0..e7316ede7bfd 100644 --- a/samples/server/petstore/go-api-server/api/swagger.yaml +++ b/samples/server/petstore/go-api-server/api/swagger.yaml @@ -108,11 +108,11 @@ paths: type: "array" items: type: "string" - default: "available" enum: - "available" - "pending" - "sold" + default: "available" collectionFormat: "csv" x-exportParamName: "Status" responses: diff --git a/samples/server/petstore/go-api-server/go/README.md b/samples/server/petstore/go-api-server/go/README.md index 81e395ff5a97..100f25037893 100644 --- a/samples/server/petstore/go-api-server/go/README.md +++ b/samples/server/petstore/go-api-server/go/README.md @@ -13,7 +13,6 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 1.0.0 -- Build date: 2017-12-20T21:53:07.200Z ### Running the server diff --git a/samples/server/petstore/go-api-server/go/pet_api.go b/samples/server/petstore/go-api-server/go/api_pet.go similarity index 100% rename from samples/server/petstore/go-api-server/go/pet_api.go rename to samples/server/petstore/go-api-server/go/api_pet.go diff --git a/samples/server/petstore/go-api-server/go/store_api.go b/samples/server/petstore/go-api-server/go/api_store.go similarity index 100% rename from samples/server/petstore/go-api-server/go/store_api.go rename to samples/server/petstore/go-api-server/go/api_store.go diff --git a/samples/server/petstore/go-api-server/go/user_api.go b/samples/server/petstore/go-api-server/go/api_user.go similarity index 100% rename from samples/server/petstore/go-api-server/go/user_api.go rename to samples/server/petstore/go-api-server/go/api_user.go diff --git a/samples/server/petstore/go-api-server/go/api_response.go b/samples/server/petstore/go-api-server/go/model_api_response.go similarity index 100% rename from samples/server/petstore/go-api-server/go/api_response.go rename to samples/server/petstore/go-api-server/go/model_api_response.go diff --git a/samples/server/petstore/go-api-server/go/category.go b/samples/server/petstore/go-api-server/go/model_category.go similarity index 100% rename from samples/server/petstore/go-api-server/go/category.go rename to samples/server/petstore/go-api-server/go/model_category.go diff --git a/samples/server/petstore/go-api-server/go/order.go b/samples/server/petstore/go-api-server/go/model_order.go similarity index 100% rename from samples/server/petstore/go-api-server/go/order.go rename to samples/server/petstore/go-api-server/go/model_order.go diff --git a/samples/server/petstore/go-api-server/go/pet.go b/samples/server/petstore/go-api-server/go/model_pet.go similarity index 100% rename from samples/server/petstore/go-api-server/go/pet.go rename to samples/server/petstore/go-api-server/go/model_pet.go diff --git a/samples/server/petstore/go-api-server/go/tag.go b/samples/server/petstore/go-api-server/go/model_tag.go similarity index 100% rename from samples/server/petstore/go-api-server/go/tag.go rename to samples/server/petstore/go-api-server/go/model_tag.go diff --git a/samples/server/petstore/go-api-server/go/user.go b/samples/server/petstore/go-api-server/go/model_user.go similarity index 100% rename from samples/server/petstore/go-api-server/go/user.go rename to samples/server/petstore/go-api-server/go/model_user.go