gibahjoe / openapi-generator-dart

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

Generator Should always run if alwaysRun flag is set #95

Closed Nexushunter closed 1 year ago

Nexushunter commented 1 year ago

Description of the bug

The current implementation forces either an update to the outputDirectory or delete the current outputDirectory. This prevents incremental updates an retaining the current testing being given to the generated clients / servers.

Steps to reproduce

make a change to the open api spec. ie add a content type to the response. run dart run build_runner build --delete-conflicting-outputs

Expected behavior

Regenerates new changes in outputDirectory

Logs

dart run build_runner build --delete-conflicting-outputs
[INFO] Generating build script completed, took 227ms
[INFO] Reading cached asset graph completed, took 39ms
[INFO] Checking for updates since last build completed, took 324ms
[INFO] Running build completed, took 10ms
[INFO] Caching finalized dependency graph completed, took 22ms
[INFO] Succeeded after 37ms with 0 outputs (0 actions)

Screenshots

No response

Platform

Linux

Library version

4.11.0

Flutter version

3.0.5 - Dart

Flutter channel

stable

Additional context

No response

gibahjoe commented 1 year ago

Hi, can you please explain the issue? What behavior are you expecting? Are you saying the output directory is not updated when you run the generator?

Nexushunter commented 1 year ago

👋🏻 Hi! Yep that is correct. When I making a change to the OAS spec and rerun the generator the output directory doesn't get updated as I would expect it to even when the alwaysRun flag is set.

As a work around I either need to update the path for the output directory or I can remove the .dart_tool directory (this has an additional burden of having to constantly redownload the dependencies). Both of these cause the generator to update the output directory as expected.

The note about the process being skipped if the output directory exists sticks out as a cause of the issue. The generation should still run in the event that the directory exists.

image

gibahjoe commented 1 year ago

For the generator to run again, you need to make a change to the file that has your @openapi annotation. This is because the generator uses build runner and build runner only runs on files that have changed.

Something I do is just add a full stop behind the pubDescription or pubAuthor for instance.

So, in your case, make a change to the tagmine_api.dart file before running build runner command.

Let me know if this helps or if I have addressed your issue.

Nexushunter commented 1 year ago

🤔 I would expect it to run in cases where the oas spec changes too.

Would you object to that being a new feature? I can look into implementing it.

Nexushunter commented 1 year ago

Here's my proposal:

Description

Currently the openapi-generator doesn't rerun when the oas spec changes. This prevents incremental changes to the oas spec, making it a requirement to make hacky changes. To alleviate this storing a copy of the oas spec in the build directory allowing for changes to be diffed. Another option is to use git. It should also not require flutter and should allow for dart only if the pubspec doesn't include the flutter SDK as a dependency.

Acceptance Criteria

gibahjoe commented 1 year ago

Of course. This will be a very welcome update. Thank you. Send a PR when done.

gibahjoe commented 1 year ago

4.12.0 has been pushed. Thanks once again