Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thomasgi1 opened this issue Feb 1, 2024 · 4 comments · May be fixed by #139
Open
Labels
bug Something isn't working

Comments

@thomasgi1
Copy link

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

@thomasgi1 thomasgi1 added the bug Something isn't working label Feb 1, 2024
@aoisupersix aoisupersix linked a pull request Mar 17, 2024 that will close this issue
@aoisupersix
Copy link

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
Copy link

ntoljic commented Apr 4, 2024

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
Copy link

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
Copy link

ntoljic commented Apr 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants