Skip to content

Commit

Permalink
update generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
CatTail authored and frantuma committed Mar 6, 2019
1 parent 65c1438 commit f2fc97b
Show file tree
Hide file tree
Showing 52 changed files with 4,275 additions and 644 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0-SNAPSHOT
2.3.1
34 changes: 17 additions & 17 deletions samples/client/petstore-security-test/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge

## Installation
Put the package under your project folder and add the following in import:
```
"./swagger"
```golang
import "./swagger"
```

## Documentation for API Endpoints
Expand All @@ -35,12 +35,12 @@ Class | Method | HTTP request | Description
- **Type**: API key

Example
```
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```
## petstore_auth
- **Type**: OAuth
Expand All @@ -51,20 +51,20 @@ Example
- **read:pets**: read your pets *_/ ' \" =end -- \\r\\n \\n \\r

Example
```
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Or via OAuth2 module to automatically refresh tokens and perform user authentication.
```
import "golang.org/x/oauth2"
```golang
import "golang.org/x/oauth2"

/ .. Perform OAuth2 round trip request and obtain a token .. //
/* Perform OAuth2 round trip request and obtain a token */

tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

## Author
Expand Down
71 changes: 71 additions & 0 deletions samples/client/petstore-security-test/go/api/swagger.yaml
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"
56 changes: 29 additions & 27 deletions samples/client/petstore-security-test/go/api_client.go
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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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...)
}

Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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 {
Expand All @@ -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)
}

8 changes: 4 additions & 4 deletions samples/client/petstore-security-test/go/api_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (

type APIResponse struct {
*http.Response `json:"-"`
Message string `json:"message,omitempty"`
Message string `json:"message,omitempty"`
// Operation is the name of the swagger operation.
Operation string `json:"operation,omitempty"`
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"`
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"`
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.
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore-security-test/go/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ To test code injection *_/ ' \" =end -- \\r\\n \\n \\r

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**ctx** | **context.Context** | context for logging, tracing, authentication, etc.
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.
**optional** | ***TestCodeInjectEndRnNROpts** | optional parameters | nil if no parameters

### Optional Parameters
Optional parameters are passed through a map[string]interface{}.
Optional parameters are passed through a pointer to a TestCodeInjectEndRnNROpts struct

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**testCodeInjectEndRnNR** | **string**| To test code injection *_/ ' \" =end -- \\r\\n \\n \\r |
**testCodeInjectEndRnNR** | **optional.**| To test code injection *_/ ' \" =end -- \\r\\n \\n \\r |

### Return type

Expand Down
Loading

0 comments on commit f2fc97b

Please sign in to comment.