Skip to content

Commit

Permalink
[WIP] Escape import with underscore in go-experimental client (#3659)
Browse files Browse the repository at this point in the history
* escape import with underscore in go client

* update ioutil

* Fix collectionFormat=multi request bug in go experimental
  • Loading branch information
wing328 authored Aug 26, 2019
1 parent 7e772e1 commit 7afd350
Show file tree
Hide file tree
Showing 53 changed files with 606 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package {{packageName}}

{{#operations}}
import (
"context"
"io/ioutil"
"net/http"
"net/url"
_context "context"
_ioutil "io/ioutil"
_nethttp "net/http"
_neturl "net/url"
{{#imports}} "{{import}}"
{{/imports}}
)

// Linger please
var (
_ context.Context
_ _context.Context
)

type {{classname}}Service service
Expand All @@ -24,7 +24,7 @@ type {{classname}}Service service
{{#notes}}
{{notes}}
{{/notes}}
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
{{#allParams}}
{{#required}}
* @param {{paramName}}{{#description}} {{{.}}}{{/description}}
Expand Down Expand Up @@ -63,9 +63,9 @@ type {{{nickname}}}Opts struct {
}

{{/hasOptionalParams}}
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
func (a *{{{classname}}}Service) {{{nickname}}}(ctx _context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*_nethttp.Response, error) {
var (
localVarHttpMethod = http.Method{{httpMethod}}
localVarHttpMethod = _nethttp.Method{{httpMethod}}
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
Expand All @@ -77,11 +77,11 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}

// create path and map variables
localVarPath := a.client.cfg.BasePath + "{{{path}}}"{{#pathParams}}
localVarPath = strings.Replace(localVarPath, "{"+"{{baseName}}"+"}", url.QueryEscape(fmt.Sprintf("%v", {{paramName}})), -1){{/pathParams}}
localVarPath = strings.Replace(localVarPath, "{"+"{{baseName}}"+"}", _neturl.QueryEscape(fmt.Sprintf("%v", {{paramName}})), -1){{/pathParams}}

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
{{#allParams}}
{{#required}}
{{#minItems}}
Expand Down Expand Up @@ -132,11 +132,37 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
{{#hasQueryParams}}
{{#queryParams}}
{{#required}}
{{#isCollectionFormatMulti}}
t:={{paramName}}
if reflect.TypeOf(t).Kind() == reflect.Slice {
s := reflect.ValueOf(t)
for i := 0; i < s.Len(); i++ {
localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
}
} else {
localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
}
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
localVarQueryParams.Add("{{baseName}}", parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
{{/isCollectionFormatMulti}}
{{/required}}
{{^required}}
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
{{#isCollectionFormatMulti}}
t:=localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value()
if reflect.TypeOf(t).Kind() == reflect.Slice {
s := reflect.ValueOf(t)
for i := 0; i < s.Len(); i++ {
localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
}
} else {
localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
}
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
localVarQueryParams.Add("{{baseName}}", parameterToString(localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value(), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
{{/isCollectionFormatMulti}}
}
{{/required}}
{{/queryParams}}
Expand Down Expand Up @@ -192,7 +218,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
}
{{/required}}
if localVarFile != nil {
fbs, _ := ioutil.ReadAll(localVarFile)
fbs, _ := _ioutil.ReadAll(localVarFile)
localVarFileBytes = fbs
localVarFileName = localVarFile.Name()
localVarFile.Close()
Expand Down Expand Up @@ -277,7 +303,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
}

localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
localVarBody, err := _ioutil.ReadAll(localVarHttpResponse.Body)
localVarHttpResponse.Body.Close()
if err != nil {
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0-SNAPSHOT
4.1.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**TestGroupParameters**](docs/FakeApi.md#testgroupparameters) | **Delete** /fake | Fake endpoint to test group parameters (optional)
*FakeApi* | [**TestInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **Post** /fake/inline-additionalProperties | test inline additionalProperties
*FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **Get** /fake/jsonFormData | test json serialization of form data
*FakeApi* | [**TestQueryParameterCollectionFormat**](docs/FakeApi.md#testqueryparametercollectionformat) | **Put** /fake/test-query-paramters |
*FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **Patch** /fake_classname_test | To test class name in snake case
*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **Post** /pet | Add a new pet to the store
*PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **Delete** /pet/{petId} | Deletes a pet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,59 @@ paths:
tags:
- fake
x-codegen-request-body-name: body
/fake/test-query-paramters:
put:
description: To test the collection format in query parameters
operationId: testQueryParameterCollectionFormat
parameters:
- explode: false
in: query
name: pipe
required: true
schema:
items:
type: string
type: array
style: form
- in: query
name: ioutil
required: true
schema:
items:
type: string
type: array
- in: query
name: http
required: true
schema:
items:
type: string
type: array
style: spaceDelimited
- explode: false
in: query
name: url
required: true
schema:
items:
type: string
type: array
style: form
- explode: true
in: query
name: context
required: true
schema:
items:
type: string
type: array
style: form
responses:
200:
content: {}
description: Success
tags:
- fake
/fake/{petId}/uploadImageWithRequiredFile:
post:
operationId: uploadFileWithRequiredFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
package petstore

import (
"context"
"io/ioutil"
"net/http"
"net/url"
_context "context"
_ioutil "io/ioutil"
_nethttp "net/http"
_neturl "net/url"
)

// Linger please
var (
_ context.Context
_ _context.Context
)

type AnotherFakeApiService service

/*
AnotherFakeApiService To test special tags
To test special tags and operation ID starting with number
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param body client model
@return Client
*/
func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx context.Context, body Client) (Client, *http.Response, error) {
func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx _context.Context, body Client) (Client, *_nethttp.Response, error) {
var (
localVarHttpMethod = http.MethodPatch
localVarHttpMethod = _nethttp.MethodPatch
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
Expand All @@ -44,8 +44,8 @@ func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx context.Context, body
localVarPath := a.client.cfg.BasePath + "/another-fake/dummy"

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}

// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json"}
Expand Down Expand Up @@ -76,7 +76,7 @@ func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx context.Context, body
return localVarReturnValue, localVarHttpResponse, err
}

localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
localVarBody, err := _ioutil.ReadAll(localVarHttpResponse.Body)
localVarHttpResponse.Body.Close()
if err != nil {
return localVarReturnValue, localVarHttpResponse, err
Expand Down
Loading

0 comments on commit 7afd350

Please sign in to comment.