OpenAPITools / OpenAPITools/openapi-generator
[BUG] [BASH] Bash generator does not propagate curl exit code to clients
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
Curl exit code is not propagated to cli callers when body content provided with - argument
I use the example code from BASH pet store where I specify --fail flag in curl and do the request that triggers 400 error on the server
./petstore-cli --host http://localhost:8081 --fail --content-type json addPet --body="{\"wrong\":\"hello\", \"notId\":\"1\"}"
curl: (22) The requested URL returned error: 400
I check exit code
echo $?
22
This is expected behaviour. But when I provide request body using here doc
./petstore-cli --host http://localhost:8081 --fail --content-type json addPet -<<JSON
{"wrong": "1", "notId":"name"}
JSON
curl: (22) The requested URL returned error: 400
The exit code will be success, despite the fact the request failed
echo $?
0
I expect the error code to be returned because the request failed
The root cause
The problem is client.mustache contains code that does not return curl exit code when used with body_content_temp_file
There is a place where curl exit code is ignored, which blocks users from relying on cli exit code
if [[ -n $body_content_temp_file ]]; then
if [[ "$print_curl" = true ]]; then
echo "cat ${body_content_temp_file} | curl ${basic_auth_option} ${curl_arguments} ${headers_curl} -X ${method} \"${host}${path}\" -d @-"
else
eval "cat ${body_content_temp_file} | curl ${basic_auth_option} ${curl_arguments} ${headers_curl} -X ${method} \"${host}${path}\" -d @-"
fi
rm "${body_content_temp_file}"
in order to propagate the exit code we need to do something like that
retval=$?
rm "${body_content_temp_file}"
return $retval
It can be reproduced in pet store tests
- specify --fail parameter in curl
- Make a request that triggers error on the server side
- Use here doc for providing the body
- Expect exit code to be not 0
@test "addPet from parameters" {
run --2 bash $PETSTORE_CLI --fail --content-type json addPet -<<JSON
{"wrong": "1", "notId":"name"}
JSON
Actual result exit code 0
Expected result: code should not be 22
openapi-generator version
7.15.0
OpenAPI declaration file content or url
Steps to reproduce
- Provide request with incorrect body using here doc
- Expect CLI exit code not to be 0
Suggest a fix
add exit code
retval=$?
rm "${body_content_temp_file}"
return $retval
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in client.mustache at the body_content_temp_file branch, then inspect the petstore Bash test for the here-doc addPet request. Reproduce the --fail case against the petstore server and verify that the generated CLI returns curl's nonzero exit code while still removing the temporary body file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100