[bash] Return the cURL exit status when the body is piped on stdin
Fixes #21944.
When the request body is piped on stdin (... addPet -), the generated client sends it from a temporary file. That branch then ends with rm of the file, so call_<operation> returns rm's status: the script exits 0 even when curl fails. This change saves the status right after the eval (or the --dry-run echo), removes the file, and returns the saved status. This is the fix akar-svg suggested in the issue. The key/value, form and no-body branches already end with curl, so they are unchanged.
Before and after, from the regenerated petstore sample in WSL, sending to a closed port (--host http://127.0.0.1:9):
| master | this PR | |
|---|---|---|
piped body (addPet -) | exit 0 | exit 7 |
| key/value args | exit 7 | exit 7 |
piped body with --dry-run | exit 0 | exit 0 |
No temporary files are left behind.
Tests:
BashTest.bodyFromStdinKeepsCurlExitStatusTestgeneratesclient.shand checks the status is saved before the temp file is removed. It fails on master;./mvnw -pl modules/openapi-generator -am test -Dtest='Bash*'passes.- A bats case "addPet from pipe returns the cURL exit code" in the bash sample passes with the regenerated client and fails with master's.
- I regenerated the sample with the built CLI (
batch bin/configs/bash.yaml). The only change is the two new lines in each of the 18 operations with a body.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
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*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
I built only the generator and CLI modules and regenerated only the bash config. No generator option changed, so the docs export is unaffected.
cc Bash technical committee: @frol @bkryza @kenjones-cisco
Summary by cubic
Fixes the Bash client exiting 0 even when cURL fails while sending a piped request body.
When the body is piped on stdin (... addPet -), the generated client now saves cURL’s exit status before deleting the temporary body file and returns that status, so the script fails with e.g. exit code 7 when the request fails instead of always succeeding.
- Key/value, form, and no-body branches are unchanged as they already end with cURL.
--dry-runinvocations still exit 0.- Adds generator and sample tests for the piped-body exit status.