OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.06k stars 6.62k forks source link

[BUG][TS-fetch] On macOS, the `FILES` file contains `.openapi-generator-ignore` in its list of files while on Linux this same `FILES` file doesn't contain `.openapi-generator-ignore` in its list of file #20218

Open jivanic-demystdata opened 2 days ago

jivanic-demystdata commented 2 days ago

Bug Report Checklist

Description

When we generate locally, on our macs, our TS SDK, the FILES file contains .openapi-generator-ignore in its list of files, while when we do the same thing in CI, on a Linux machine, the same file doesn't contain .openapi-generator-ignore in its list of files

openapi-generator version

7.10.0 (not yet released)

OpenAPI declaration file content or url

private. Can't share

Generation Details
java -jar openapi-generator-cli.jar generate \
  -i http://localhost:34567/docs/openapi/mydoc.json \
  -o "$1" \
  -g typescript-fetch \
  --additional-properties=disallowAdditionalPropertiesIfNotPresent=false,withInterfaces=false,supportsES6=true,stringEnums=true,npmName=myclient
wing328 commented 2 days ago

I just did a quick test with linux (ubuntu) and FILES contains .openapi-generator-list. First few lines shown below:

.gitignore
.openapi-generator-ignore
.php-cs-fixer.dist.php
.travis.yml
README.md
composer.json
docs/Api/PetApi.md
jivanic-demystdata commented 2 days ago

Well, the same command executed locally and in the CI doesn't give the same result

We use a CI step to validate that the committed TS SDK is up-to-date (we commit the generated code) To validate this in the CI, we delete the generated code, re-generate it and compare the newly generated with the code present in git

The command to compare the re-generated code with the code in git:

if [[ `git status --porcelain generated` ]]; then
  git diff generated | cat
  echo ""
  echo "⚠️ The REST API has changed ⚠️"
  echo "You need to regenerate the TS SDK"
  echo "Please run './scripts/generate_ts_sdk.sh' and commit the changes"
  echo ""
  exit 1
fi

Result:

diff --git a/generated/ts_sdk/.openapi-generator/FILES b/generated/ts_sdk/.openapi-generator/FILES
--
  | index 95d308b..fc35184 100644
  | a/generated/ts_sdk/.openapi-generator/FILES | 0s
  | b/generated/ts_sdk/.openapi-generator/FILES | 1s
  | @@ -1,6 +1,5 @@
  | .gitignore
  | .npmignore
  | -.openapi-generator-ignore
  | README.md
  | package.json
  | src/apis/DefaultApi.ts
  |  
  | ⚠️ The REST API has changed ⚠️
  | You need to regenerate the TS SDK
  | Please run './scripts/generate_ts_sdk.sh' and commit the changes

I had to add this in my script to make it pass:

        # Add a new line with `.openapi-generator-ignore` after the `.npmignore` line in the `.openapi-generator/FILES`
        # because of: https://github.com/OpenAPITools/openapi-generator/issues/20218
        # command comes from: https://www.baeldung.com/linux/insert-line-specific-line-number#using-a-combination-of-head-and-tail
        { head -n 2 .openapi-generator/FILES; echo ".openapi-generator-ignore"; tail -n +3 .openapi-generator/FILES; } > TMP
        mv TMP .openapi-generator/FILES
wing328 commented 2 days ago

are you able to repeat the same issue in a local linux box?

NoemieTav commented 18 hours ago

We have the same issue. We don't have macOS, and locally, we don't have .openapi-generator-ignore in FILES but in the CI we do.

We use the docker locally and the .jar from maven in the CI.

When using the .jar from maven on my computer, I have .openapi-generator-ignore in FILES.