Skip to content

Commit

Permalink
Merge pull request #10429 from kevinawoo/fix/go-decoding
Browse files Browse the repository at this point in the history
fix(go): return decoding errors
  • Loading branch information
HugoMario authored Oct 15, 2020
2 parents 755481e + b09ab1c commit d448c55
Show file tree
Hide file tree
Showing 25 changed files with 197 additions and 239 deletions.
8 changes: 3 additions & 5 deletions modules/swagger-codegen/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
type {{classname}}Service service
{{#operation}}

/*
/*
{{{classname}}}Service{{#summary}} {{.}}{{/summary}}{{#notes}}
{{notes}}{{/notes}}
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
Expand Down Expand Up @@ -235,9 +235,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
}
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
}
{{/returnType}}

Expand All @@ -263,4 +261,4 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}

return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, nil
}
{{/operation}}{{/operations}}
{{/operation}}{{/operations}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.4.16-SNAPSHOT
6 changes: 3 additions & 3 deletions samples/client/petstore-security-test/go/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ paths:
required: false
type: "string"
x-exportParamName: "TestCodeInjectEndRnNR"
x-optionalDataType: "String"
responses:
400:
"400":
description: "To test code injection */ ' \" =end -- \\r\\n \\n \\r"
securityDefinitions:
petstore_auth:
Expand All @@ -63,10 +64,9 @@ definitions:
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"

description: "Model for testing reserved words */ ' \" =end -- \\r\\n \\n \\r"
externalDocs:
description: "Find out more about Swagger */ ' \" =end -- \\r\\n \\n \\r"
url: "http://swagger.io"
10 changes: 6 additions & 4 deletions samples/client/petstore-security-test/go/api_fake.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
*
Expand Down Expand Up @@ -26,20 +27,20 @@ var (

type FakeApiService service

/*
/*
FakeApiService To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param optional nil or *TestCodeInjectEndRnNROpts - Optional Parameters:
* @param optional nil or *FakeApiTestCodeInjectEndRnNROpts - Optional Parameters:
* @param "TestCodeInjectEndRnNR" (optional.String) - To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
*/

type TestCodeInjectEndRnNROpts struct {
type FakeApiTestCodeInjectEndRnNROpts struct {
TestCodeInjectEndRnNR optional.String
}

func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOptionals *TestCodeInjectEndRnNROpts) (*http.Response, error) {
func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOptionals *FakeApiTestCodeInjectEndRnNROpts) (*http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Put")
localVarPostBody interface{}
Expand Down Expand Up @@ -103,3 +104,4 @@ func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOpti

return localVarHttpResponse, nil
}

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

var (
jsonCheck = regexp.MustCompile("(?i:[application|text]/json)")
xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)")
jsonCheck = regexp.MustCompile("(?i:(?:application|text)/json)")
xmlCheck = regexp.MustCompile("(?i:(?:application|text)/xml)")
)

// APIClient manages communication with the Swagger Petstore *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r API v1.0.0 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore-security-test/go/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.
**optional** | ***TestCodeInjectEndRnNROpts** | optional parameters | nil if no parameters
**optional** | ***FakeApiTestCodeInjectEndRnNROpts** | optional parameters | nil if no parameters

### Optional Parameters
Optional parameters are passed through a pointer to a TestCodeInjectEndRnNROpts struct
Optional parameters are passed through a pointer to a FakeApiTestCodeInjectEndRnNROpts struct

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**testCodeInjectEndRnNR** | **optional.**| To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r |
**testCodeInjectEndRnNR** | **optional.String**| To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r |

### Return type

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.6-SNAPSHOT
2.4.16-SNAPSHOT
4 changes: 2 additions & 2 deletions samples/client/petstore/go/go-petstore-withXml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ Class | Method | HTTP request | Description
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [Capitalization](docs/Capitalization.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
- [Dog](docs/Dog.md)
- [EnumArrays](docs/EnumArrays.md)
- [EnumClass](docs/EnumClass.md)
- [EnumTest](docs/EnumTest.md)
Expand All @@ -91,8 +93,6 @@ Class | Method | HTTP request | Description
- [SpecialModelName](docs/SpecialModelName.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)
- [Cat](docs/Cat.md)
- [Dog](docs/Dog.md)


## Documentation For Authorization
Expand Down
Loading

0 comments on commit d448c55

Please sign in to comment.