gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
112 stars 29 forks source link

Generator adds comment into version controlled source file containing the Openapi annotation #131

Open thomasgi1 opened 5 months ago

thomasgi1 commented 5 months ago

Description of the bug

Every time, when the OpenAPI generator runs, it adds following comment line to the source file containing the Openapi annotation:

// Openapi Generator last run: : 2024-02-01T14:45:00.661335

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 the dart run build_runner build is executed each time before the normal flutter 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

aoisupersix commented 3 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
ntoljic commented 2 months ago

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.

grAPPfruit commented 2 months ago

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!

ntoljic commented 2 months ago

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.