-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9234 from swagger-api/bugfix/go-enum-conflict
[go] suffix enum name with classname to avoid conflict
- Loading branch information
Showing
18 changed files
with
225 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/client/petstore-security-test/go/.swagger-codegen/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.3.0-SNAPSHOT | ||
2.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
swagger: "2.0" | ||
info: | ||
description: "This spec is mainly for testing Petstore server and contains fake\ | ||
\ endpoints, models. Please do not use this for any other purpose. Special characters:\ | ||
\ \" \\ */ ' \" =end -- \r\n \n \r" | ||
version: "1.0.0 */ ' \" =end -- \\r\\n \\n \\r" | ||
title: "Swagger Petstore */ ' \" =end -- \\r\\n \\n \\r" | ||
termsOfService: "http://swagger.io/terms/ */ ' \" =end -- \\r\\n \\n \\r" | ||
contact: | ||
email: "[email protected] */ ' \" =end -- \\r\\n \\n \\r" | ||
license: | ||
name: "Apache-2.0 */ ' \" =end -- \\r\\n \\n \\r" | ||
url: "http://www.apache.org/licenses/LICENSE-2.0.html */ ' \" =end -- \\r\\n \\\ | ||
n \\r" | ||
host: "petstore.swagger.io */ ' \" =end -- \\r\\n \\n \\r" | ||
basePath: "/v2 */ ' \" =end -- \\r\\n \\n \\r" | ||
tags: | ||
- name: "fake" | ||
description: "Everything about your Pets */ ' \" =end -- \\r\\n \\n \\r" | ||
externalDocs: | ||
description: "Find out more */ ' \" =end -- \\r\\n \\n \\r" | ||
url: "http://swagger.io" | ||
paths: | ||
/fake: | ||
put: | ||
tags: | ||
- "fake" | ||
summary: "To test code injection */ ' \" =end -- \\r\\n \\n \\r" | ||
operationId: "testCodeInject */ ' \" =end -- \\r\\n \\n \\r" | ||
consumes: | ||
- "application/json" | ||
- "*/ ' \" =end -- \r\n \n \r" | ||
produces: | ||
- "application/json" | ||
- "*/ ' \" =end -- \r\n \n \r" | ||
parameters: | ||
- name: "test code inject */ ' \" =end -- \\r\\n \\n \\r" | ||
in: "formData" | ||
description: "To test code injection */ ' \" =end -- \\r\\n \\n \\r" | ||
required: false | ||
type: "string" | ||
x-exportParamName: "TestCodeInjectEndRnNR" | ||
responses: | ||
400: | ||
description: "To test code injection */ ' \" =end -- \\r\\n \\n \\r" | ||
securityDefinitions: | ||
petstore_auth: | ||
type: "oauth2" | ||
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" | ||
flow: "implicit" | ||
scopes: | ||
write:pets: "modify pets in your account */ ' \" =end -- \\r\\n \\n \\r" | ||
read:pets: "read your pets */ ' \" =end -- \\r\\n \\n \\r" | ||
api_key: | ||
type: "apiKey" | ||
name: "api_key */ ' \" =end -- \\r\\n \\n \\r" | ||
in: "header" | ||
definitions: | ||
Return: | ||
properties: | ||
return: | ||
type: "integer" | ||
format: "int32" | ||
description: "property description */ ' \" =end -- \\r\\n \\n \\r" | ||
description: "Model for testing reserved words */ ' \" =end -- \\r\\n \\n \\r" | ||
xml: | ||
name: "Return" | ||
externalDocs: | ||
description: "Find out more about Swagger */ ' \" =end -- \\r\\n \\n \\r" | ||
url: "http://swagger.io" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r | ||
* | ||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- | ||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- | ||
* | ||
* API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r | ||
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r | ||
|
@@ -14,40 +14,37 @@ import ( | |
"bytes" | ||
"encoding/json" | ||
"encoding/xml" | ||
"errors" | ||
"fmt" | ||
"errors" | ||
"io" | ||
"mime/multipart" | ||
"golang.org/x/oauth2" | ||
"golang.org/x/net/context" | ||
"net/http" | ||
"net/url" | ||
"time" | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
"time" | ||
"unicode/utf8" | ||
|
||
"context" | ||
|
||
"golang.org/x/oauth2" | ||
"strconv" | ||
) | ||
|
||
var ( | ||
jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") | ||
xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") | ||
xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") | ||
) | ||
|
||
// APIClient manages communication with the Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r API v1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r | ||
// 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 | ||
cfg *Configuration | ||
common service // Reuse a single struct instead of allocating one for each service on the heap. | ||
|
||
FakeApi *FakeApiService | ||
// API Services | ||
FakeApi *FakeApiService | ||
} | ||
|
||
type service struct { | ||
|
@@ -75,6 +72,7 @@ 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 { | ||
|
@@ -145,18 +143,18 @@ func parameterToString(obj interface{}, collectionFormat string) string { | |
return fmt.Sprintf("%v", obj) | ||
} | ||
|
||
// callAPI do the request. | ||
// callAPI do the request. | ||
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { | ||
return c.cfg.HTTPClient.Do(request) | ||
return c.cfg.HTTPClient.Do(request) | ||
} | ||
|
||
// Change base path to allow switching to mocks | ||
func (c *APIClient) ChangeBasePath(path string) { | ||
func (c *APIClient) ChangeBasePath (path string) { | ||
c.cfg.BasePath = path | ||
} | ||
|
||
// prepareRequest build the request | ||
func (c *APIClient) prepareRequest( | ||
func (c *APIClient) prepareRequest ( | ||
ctx context.Context, | ||
path string, method string, | ||
postBody interface{}, | ||
|
@@ -216,7 +214,7 @@ func (c *APIClient) prepareRequest( | |
// 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() | ||
|
@@ -262,9 +260,10 @@ func (c *APIClient) prepareRequest( | |
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 | ||
|
@@ -290,17 +289,18 @@ func (c *APIClient) prepareRequest( | |
|
||
// AccessToken Authentication | ||
if auth, ok := ctx.Value(ContextAccessToken).(string); ok { | ||
localVarRequest.Header.Add("Authorization", "Bearer "+auth) | ||
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) | ||
|
@@ -319,7 +319,7 @@ func addFile(w *multipart.Writer, fieldName, path string) error { | |
} | ||
|
||
// Prevent trying to import "fmt" | ||
func reportError(format string, a ...interface{}) error { | ||
func reportError(format string, a ...interface{}) (error) { | ||
return fmt.Errorf(format, a...) | ||
} | ||
|
||
|
@@ -356,7 +356,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e | |
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" | ||
|
@@ -373,6 +373,7 @@ func detectContentType(body interface{}) string { | |
return contentType | ||
} | ||
|
||
|
||
// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go | ||
type cacheControl map[string]string | ||
|
||
|
@@ -395,15 +396,15 @@ func parseCacheControl(headers http.Header) cacheControl { | |
} | ||
|
||
// CacheExpires helper function to determine remaining time before repeating a request. | ||
func CacheExpires(r *http.Response) time.Time { | ||
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 { | ||
|
@@ -422,6 +423,7 @@ func CacheExpires(r *http.Response) time.Time { | |
return expires | ||
} | ||
|
||
func strlen(s string) int { | ||
func strlen(s string) (int) { | ||
return utf8.RuneCountInString(s) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.