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
21.82k stars 6.58k forks source link

[REQ] Remove files no-longer in FILES #15669

Open fauxbytes opened 1 year ago

fauxbytes commented 1 year ago

Hi. More a question at this point than a FR: when an api change translates to a removal of a file entry from .openapi/FILES, is there a way to make the generator remove that file?

If not, shouldn't there be? Or instead, a clarifying note on the matter on the docs ("files showing as removed from FILES - aren't. If you want them gone, remove manually")?

wing328 commented 1 year ago

I think ideally it should by enabling an option (e.g. --remove-outdated-files) to clean up outdated files that are no longer in FILES.

Would you like to contribute a PR or sponsor this feature request?

joshraker commented 5 months ago

I was having the same issue and would like to implement it in the generator but, in the meantime, I was able to work around this by saving and comparing the .openapi-generator/FILES before and after generating:

# If FILES doesn't exist, i.e. the generator hasn't run, touch the temporary file to ensure it exists
cp .openapi-generator/FILES FILES.tmp || touch FILES.tmp

# Generate client...

# Remove the files that generating the client removed from the FILES list
comm -2 -3 FILES.tmp .openapi-generator/FILES | xargs rm
rm FILES.tmp