Open thomasgi1 opened 5 months ago
I have the same issue. I've submitted a PR (#139) to allow optional updates to the annotated file.
And also, as a temporary workaround, I've created a script that removes timestamp comment using rps.
pubspec.yaml:
scripts:
gen-apiclient:
$script: dart run build_runner build --delete-conflicting-outputs --build-filter='lib/my_generator_config.dart'
$after: $remove-timestamp
remove-timestamp:
$script:
$windows: powershell -Command "(Get-Content lib\my_generator_config.dart) -notmatch '^\/\/ Openapi Generator last run' | Foreach-Object { $_ + \"`n\" } | Set-Content lib\my_generator_config.dart -NoNewline"
$default: sed -i '' '/^\/\/ Openapi Generator last run/d' lib/my_generator_config.dart
I would like to add that this also causes issues when running dart run build_runner watch
. Each time the generator runs, the timestamp is updated causing the watch
command to trigger the generation again, resulting in an infinite loop.
If you don't need to rebuild the API everytime the build runner runs, then add this to your build.yaml
:
targets:
$default:
builders:
openapi_generator:
enabled: false
if you add a new spec or need to update, just set enabled: true
.
Hope this helps!
Thank you for the hint. It seems my case is one of "you are not using it correctly".
I would still prefer that the tool would not touch my manually written files. IMO it would be better to write this comment into one of the generated files instead.
Description of the bug
Every time, when the OpenAPI generator runs, it adds following comment line to the source file containing the Openapi annotation:
Since that source file is typically under source control its automatic modification is very annoying, because a developer has either to revert the git change or commit it after each
dart run build_runner build
. The situation becomes even worse, if thedart run build_runner build
is executed each time before the normalflutter build
.Steps to reproduce
execute
dart run build_runner build
Expected behavior
The source file containing the openapi annotation is not touched.
Logs
No response
Screenshots
No response
Platform
macOS
Library version
5.0.2
Flutter version
3.16.9
Flutter channel
stable
Additional context
No response