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

openapi_generator conflicts with mockito:mockBuilder #136

Open
AngeloAvv opened this issue Mar 1, 2024 · 3 comments
Open

openapi_generator conflicts with mockito:mockBuilder #136

AngeloAvv opened this issue Mar 1, 2024 · 3 comments
Labels
bug Something isn't working generator help wanted Extra attention is needed

Comments

@AngeloAvv
Copy link

AngeloAvv commented Mar 1, 2024

Description of the bug

If you empty your openapi generated folder and you have tests that rely on those generated files, mockito:mockBuilder won't be able to find these files during the first generation.

This typically occurs if you have a CI/CD flow with GitHub Actions/Gitlab Runner/Azure DevOps and so on.

Edge cases:

  • If I run flutter pub get after the first round of failure and then I run the build runner a second time, the error won't occur anymore.
  • If u run flutter pub get after removing the test folder, the error doesn't occur. I also tried configuring a build.yaml file telling the openapi_generator to run before mockito:mockBuilder but it doesn't solve the problem.

Since I'm using FVM and I noticed there's a potential fix while updating the dependencies, I also tried to test this scenario against this PR without success.

I can't do these workarounds in my pipeline because they output a result code that makes my run fail.

Steps to reproduce

  1. Clone the project (in this case you have the folder empty excepts for the pubspec.yaml)
  2. Run flutter pub get
  3. Run build runner
[INFO] Generating build script completed, took 159ms
[INFO] Precompiling build script... completed, took 4.4s
[INFO] Building new asset graph completed, took 969ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 4ms
[INFO] Generating SDK summary completed, took 2.2s
[INFO] openapi_generator on lib/app.dart:

:::::::::::::::::::::::::::::::::::::::::::
::      Openapi generator for dart       ::
:::::::::::::::::::::::::::::::::::::::::::

[WARNING] openapi_generator on lib/app.dart:
loadSpec - /home/angeloavv/FlutterProjects/blablabla/.dart_tool/openapi-generator-cache.json
[WARNING] openapi_generator on lib/app.dart:
loadSpec - openapi/blablabla.json
[INFO] openapi_generator on lib/app.dart:Loaded cached and current spec files.
[INFO] openapi_generator on lib/app.dart:Dirty Spec found. Running generation.
[INFO] openapi_generator on lib/app.dart:Running following command to generate openapi client - [ generate -o=submodules/openapi -i=openapi/blablabla.json -g=dart-dio ]
[INFO] openapi_generator on lib/app.dart:Openapi generator completed successfully.
[INFO] openapi_generator on lib/app.dart:Installing dependencies with generated source. flutter pub get
[INFO] openapi_generator on lib/app.dart:Install completed successfully.
[INFO] openapi_generator on lib/app.dart:Running source code generation.
[INFO] openapi_generator on lib/app.dart:flutter pub run build_runner build --delete-conflicting-outputs
[WARNING] No actions completed for 15.0s, waiting on:
  - openapi_generator on lib/app.dart

[INFO] openapi_generator on lib/app.dart:Codegen completed successfully.
[INFO] openapi_generator on lib/app.dart:Sources generated successfully.
[WARNING] openapi_generator on lib/app.dart:
loadSpec - openapi/blablabla.json
[INFO] openapi_generator on lib/app.dart:Successfully cached spec changes.
[INFO] openapi_generator on lib/app.dart:Successfully formatted code.
[INFO] openapi_generator on lib/app.dart:Found generated timestamp. Updating with 2024-03-01T09:44:37.654917
[SEVERE] mockito:mockBuilder on test/services/network/test_model_service/test_model_service_test.dart:

Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension
[SEVERE] mockito:mockBuilder on test/services/sync_merge/news_item_event_types/news_item_event_types_service_test.dart:

Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension
[SEVERE] mockito:mockBuilder on test/services/sync_merge/news_item_log_events/news_item_log_events_service_test.dart:

Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension
[SEVERE] mockito:mockBuilder on test/services/sync_merge/news_items/news_items_service_test.dart:

Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension
[SEVERE] mockito:mockBuilder on test/services/sync_merge/news_item_network/news_item_network_service_test.dart:

Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension
[WARNING] auto_route_generator on lib/pages/article/article_page.dart:

WARNING => Because [ArticlePage] has required parameters (source) that can not be parsed from path,
@PathParam() and @QueryParam() annotations will be ignored.

[INFO] Running build completed, took 32.2s
[INFO] Caching finalized dependency graph completed, took 162ms
[SEVERE] Failed after 32.3s

Expected behavior

[INFO] Generating build script completed, took 161ms
[WARNING] Throwing away cached asset graph because the build phases have changed. This most commonly would happen as a result of adding a new dependency or updating your dependencies.
[WARNING] Throwing away cached asset graph because the language version of some package(s) changed. This would most commonly happen when updating dependencies or changing your min sdk constraint.
[INFO] Cleaning up outputs from previous builds. completed, took 22ms
[INFO] Generating build script completed, took 50ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[INFO] Precompiling build script... completed, took 4.9s
[INFO] Building new asset graph completed, took 990ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 0ms
[INFO] openapi_generator on lib/app.dart:

:::::::::::::::::::::::::::::::::::::::::::
::      Openapi generator for dart       ::
:::::::::::::::::::::::::::::::::::::::::::

[WARNING] openapi_generator on lib/app.dart:
loadSpec - /home/angeloavv/FlutterProjects/blablabla/.dart_tool/openapi-generator-cache.json
[WARNING] openapi_generator on lib/app.dart:
loadSpec - openapi/blablabla.json
[INFO] openapi_generator on lib/app.dart:Loaded cached and current spec files.
[INFO] openapi_generator on lib/app.dart:No diff between versions, not running generator.
[INFO] openapi_generator on lib/app.dart:Successfully formatted code.
[INFO] openapi_generator on lib/app.dart:Found generated timestamp. Updating with 2024-03-01T09:42:36.749179
[WARNING] auto_route_generator on lib/pages/article/article_page.dart:

WARNING => Because [ArticlePage] has required parameters (source) that can not be parsed from path,
@PathParam() and @QueryParam() annotations will be ignored.

[INFO] Running build completed, took 15.4s
[INFO] Caching finalized dependency graph completed, took 171ms
[INFO] Succeeded after 15.6s with 598 outputs (3691 actions)

Logs

No response

Screenshots

No response

Platform

Linux

Library version

5.0.2

Flutter version

3.19.1

Flutter channel

stable

Additional context

No response

@AngeloAvv AngeloAvv added the bug Something isn't working label Mar 1, 2024
@DevFreeze
Copy link

I have exactly the same problem at the moment

@gibahjoe
Copy link
Owner

Hi, I’ve been able to recreate this issue, and it’s currently under investigation. The closest I’ve been able to get is to reorder the builders so that this library runs before the mockito builder. However, it seems like the solution will be manual, likely involving editing the build.yaml file. Once I’ve had success, I’ll be sure to provide feedback.

@gibahjoe
Copy link
Owner

gibahjoe commented Dec 9, 2024

I’ve been struggling to resolve this issue because Mockito expects the classes to be available when the build_runner is executed. Even attempting to set the build order didn’t resolve the problem.

An ugly workaround for the pipeline:

If you encounter failures in the pipeline, you can set that step to retry on the first failure. This way, the first run generates the APIs, while the second run generates the mocks.

I’m leaving this open and pinning it in case anyone wants to give it a try.

@gibahjoe gibahjoe added help wanted Extra attention is needed generator labels Dec 9, 2024
@gibahjoe gibahjoe pinned this issue Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working generator help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants