Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GO][Client] return GenericOpenAPIError instead of error in Execute() #8137

Merged
merged 14 commits into from
Dec 17, 2020
Merged

[GO][Client] return GenericOpenAPIError instead of error in Execute() #8137

merged 14 commits into from
Dec 17, 2020

Conversation

code-lucidal58
Copy link
Contributor

@code-lucidal58 code-lucidal58 commented Dec 9, 2020

fix #8136

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @bkabrda (2019/07)

@code-lucidal58
Copy link
Contributor Author

Code snippet used to test the generated client code

result, _, err := r.Execute()
if err.Error() != "" {
	return fmt.Errorf("error occurred while updating object: %s Response: %s", err.Error(), string(err.Body()))
}

Output:

Error: error occurred while updating VnicEthIf object: 400 Bad Request Response: <response body as it is >

Earlier Output:

Error: error occurred while updating VnicEthIf object: 400 Bad Request Response: 

When printing the error err only because error does not support .Body(), GenerateOpenAPIError does.

@@ -3,6 +3,7 @@ package {{packageName}}

{{#operations}}
import (
"bytes"
Copy link
Member

@wing328 wing328 Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@code-lucidal58 what about using tabs instead of 4-spaces for this line and some other lines below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use tabs. And looks fine in Atom and Intellij. Not sure why it looks different here. Let me try again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@wing328
Copy link
Member

wing328 commented Dec 9, 2020

Looks like there are syntax errors causing build failure:

# _/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/go/go-petstore
go-petstore/api_another_fake.go:95:2: syntax error: non-declaration statement outside function body
FAIL	_/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/go [build failed]
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (go-test) on project GoPetstore: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]

@code-lucidal58
Copy link
Contributor Author

All errors fixed @wing328

@code-lucidal58
Copy link
Contributor Author

Not able to figure out why the circleci build fails.

@wing328 wing328 added this to the 5.0.0 milestone Dec 13, 2020
@wing328
Copy link
Member

wing328 commented Dec 13, 2020

I think you will need to update the test as well. Here is the error reported by the CI:

Download https://repo1.maven.org/maven2/org/junit/platform/junit-platform-engine/1.4.0/junit-platform-engine-1.4.0.jar
Download https://repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.4.0/junit-jupiter-api-5.4.0.jar
Download https://repo1.maven.org/maven2/org/junit/platform/junit-platform-commons/1.4.0/junit-platform-commons-1.4.0.jar
:processResources UP-TO-DATE
:classes
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:test

BUILD SUCCESSFUL

Total time: 22.356 secs
# _/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/go/mock
mock/mock_api_pet.go:20:29: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:28:32: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:36:39: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:44:37: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:52:33: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:60:32: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:68:40: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:76:33: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
mock/mock_api_pet.go:84:49: cannot use m (type *MockPetApi) as type petstore.PetApi in field value:
	*MockPetApi does not implement petstore.PetApi (wrong type for AddPetExecute method)
		have AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, error)
		want AddPetExecute(petstore.ApiAddPetRequest) (*http.Response, petstore.GenericOpenAPIError)
FAIL	_/home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/go [build failed]
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (go-test) on project GoPetstore: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :GoPetstore
2020-12-13 15:52:05.344:INFO::main: Logging initialized @106ms

@wing328
Copy link
Member

wing328 commented Dec 14, 2020

All tests passed. If no further feedback/question from anyone, I'll merge it on coming Wed.

wing328 added a commit that referenced this pull request Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GO][BUG] *_api.go CRUD function return error instead of GenericOpenAPIError
2 participants