Skip to content

Commit

Permalink
[go-experimental][go][client] Remove unreachable code in go client AP…
Browse files Browse the repository at this point in the history
…I methods (OpenAPITools#5611)

* [go-experimental][go][client] Remove unreachable code in go client API methods

* Properly regenerate all samples
  • Loading branch information
Slavek Kabrda authored and michaelpro1 committed May 7, 2020
1 parent 700e7a4 commit d8e16ef
Show file tree
Hide file tree
Showing 34 changed files with 20 additions and 818 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
public class CodegenResponse implements IJsonSchemaValidationProperties {
public final List<CodegenProperty> headers = new ArrayList<CodegenProperty>();
public String code;
public boolean is1xx;
public boolean is2xx;
public boolean is3xx;
public boolean is4xx;
public boolean is5xx;
public String message;
public boolean hasMore;
public List<Map<String, Object>> examples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,13 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
r.code = "0";
} else {
r.code = responseCode;
switch(r.code.charAt(0)) {
case '1': r.is1xx = true; break;
case '2': r.is2xx = true; break;
case '3': r.is3xx = true; break;
case '4': r.is4xx = true; break;
case '5': r.is5xx = true; break;
}
}
Schema responseSchema;
if (this.openAPI != null && this.openAPI.getComponents() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ func (r api{{operationId}}Request) Execute() ({{#returnType}}{{{.}}}, {{/returnT
}
{{#responses}}
{{#dataType}}
{{^is1xx}}
{{^is2xx}}
{{^wildcard}}
if localVarHTTPResponse.StatusCode == {{{code}}} {
{{/wildcard}}
Expand All @@ -302,6 +304,8 @@ func (r api{{operationId}}Request) Execute() ({{#returnType}}{{{.}}}, {{/returnT
{{^wildcard}}
}
{{/wildcard}}
{{/is2xx}}
{{/is1xx}}
{{/dataType}}
{{/responses}}
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHTTPResponse, newErr
Expand Down
4 changes: 4 additions & 0 deletions modules/openapi-generator/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx _context.Context{{#hasParams
}
{{#responses}}
{{#dataType}}
{{^is1xx}}
{{^is2xx}}
{{^wildcard}}
if localVarHTTPResponse.StatusCode == {{{code}}} {
{{/wildcard}}
Expand All @@ -336,6 +338,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx _context.Context{{#hasParams
{{^wildcard}}
}
{{/wildcard}}
{{/is2xx}}
{{/is1xx}}
{{/dataType}}
{{/responses}}
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHTTPResponse, newErr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,6 @@ func (r apiCall123TestSpecialTagsRequest) Execute() (Client, *_nethttp.Response,
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v Client
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down
45 changes: 0 additions & 45 deletions samples/client/petstore/go-experimental/go-petstore/api_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,6 @@ func (r apiFakeOuterBooleanSerializeRequest) Execute() (bool, *_nethttp.Response
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v bool
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -329,15 +320,6 @@ func (r apiFakeOuterCompositeSerializeRequest) Execute() (OuterComposite, *_neth
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v OuterComposite
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -442,15 +424,6 @@ func (r apiFakeOuterNumberSerializeRequest) Execute() (float32, *_nethttp.Respon
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v float32
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -555,15 +528,6 @@ func (r apiFakeOuterStringSerializeRequest) Execute() (string, *_nethttp.Respons
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v string
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -880,15 +844,6 @@ func (r apiTestClientModelRequest) Execute() (Client, *_nethttp.Response, error)
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v Client
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ func (r apiTestClassnameRequest) Execute() (Client, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v Client
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down
48 changes: 0 additions & 48 deletions samples/client/petstore/go-experimental/go-petstore/api_pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,6 @@ func (r apiFindPetsByStatusRequest) Execute() ([]Pet, *_nethttp.Response, error)
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v []Pet
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -434,16 +424,6 @@ func (r apiFindPetsByTagsRequest) Execute() ([]Pet, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v []Pet
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -559,16 +539,6 @@ func (r apiGetPetByIdRequest) Execute() (Pet, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v Pet
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -902,15 +872,6 @@ func (r apiUploadFileRequest) Execute() (ApiResponse, *_nethttp.Response, error)
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v ApiResponse
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -1038,15 +999,6 @@ func (r apiUploadFileWithRequiredFileRequest) Execute() (ApiResponse, *_nethttp.
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v ApiResponse
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down
29 changes: 0 additions & 29 deletions samples/client/petstore/go-experimental/go-petstore/api_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,6 @@ func (r apiGetInventoryRequest) Execute() (map[string]int32, *_nethttp.Response,
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v map[string]int32
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -329,16 +320,6 @@ func (r apiGetOrderByIdRequest) Execute() (Order, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v Order
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -446,16 +427,6 @@ func (r apiPlaceOrderRequest) Execute() (Order, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v Order
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down
20 changes: 0 additions & 20 deletions samples/client/petstore/go-experimental/go-petstore/api_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,6 @@ func (r apiGetUserByNameRequest) Execute() (User, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v User
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down Expand Up @@ -625,16 +615,6 @@ func (r apiLoginUserRequest) Execute() (string, *_nethttp.Response, error) {
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v string
err = r.apiService.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d8e16ef

Please sign in to comment.