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

Introduce changes necessary for Dart 3.0.0/Flutter 3.10.0 #15516

Merged
merged 5 commits into from
Jun 20, 2023

Conversation

noordawod
Copy link
Contributor

@noordawod noordawod commented May 15, 2023

Recent versions of the Dart SDK have tightened the rules for which objects can be sent across isolates (see https://api.dart.dev/stable/3.0.0/dart-isolate/SendPort/send.html and dart-lang/sdk@67683c39).

Bottom line: It's not possible to send an arbitrary class instance across isolates anymore, this may cause a crash when deserializeAsync is called from an isolate different from the isolate used to call the API operation: flutter/flutter#126520

This pr introduces the following changes:

  1. Add a new function decodeAsync to decode a JSON, suitable to be called from an isolate.
  2. Expose ApiClient._deserialize (as ApiClient.fromJson) so that users can call it after decoding the JSON on an isolate.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh bin/configs/dart-*
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date
    
    Commit all changed files.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)

@ahmednfwela
Copy link
Contributor

ahmednfwela commented May 15, 2023

Can this wait until #14346 and #15485 land ?

because after these 2 PRs we will have an infrastructure to test this code similar to this https://github.com/OpenAPITools/openapi-generator/tree/master/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests

@noordawod
Copy link
Contributor Author

For sure, @ahmednfwela. Got an eta?

@ahmednfwela
Copy link
Contributor

it's currently blocked by #10189 waiting for a fix soon

@konnic
Copy link

konnic commented May 22, 2023

@noordawod thanks for opening the PR!

After upgrading to Flutter 3.10.1 I discovered that I'm blocked by the dart2 generator, because my generated Dart API client pub depends on intl: "^0.17.0", while the Flutter SDK now depends on intl: "0.18.0". So if I'm not mistaken this should be adjusted in the pubspec.mustache:19 file?

This was also reported in this issue: #15510

When running flutter pub get this is my output:

Resolving dependencies...
Because myapp depends on core_api from path which depends on intl ^0.17.0, intl ^0.17.0 is required.
So, because myapp depends on intl ^0.18.0, version solving failed.
exit code 1

@noordawod
Copy link
Contributor Author

noordawod commented May 24, 2023

@noordawod thanks for opening the PR!

After upgrading to Flutter 3.10.1 I discovered that I'm blocked by the dart2 generator, because my generated Dart API client pub depends on intl: "^0.17.0", while the Flutter SDK now depends on intl: "0.18.0". So if I'm not mistaken this should be adjusted in the pubspec.mustache:19 file?

This was also reported in this issue: #15510

When running flutter pub get this is my output:

Resolving dependencies...
Because myapp depends on core_api from path which depends on intl ^0.17.0, intl ^0.17.0 is required.
So, because myapp depends on intl ^0.18.0, version solving failed.
exit code 1

You could override the dependency and enforce a specific version, I do it:

dependency_overrides:
  intl: "^0.18.0"

More info: https://rdr.to/Cwq7C2il78u

UPDATE: I modified this pr and patched the pubspec Mustache template file, hopefully we'll be able to merge this pr once the prerequisites are merged.

@noordawod
Copy link
Contributor Author

Can this wait until #14346 and #15485 land ?

because after these 2 PRs we will have an infrastructure to test this code similar to this https://github.com/OpenAPITools/openapi-generator/tree/master/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests

What do you think about doing it the other way around? Merging this first and then the other 2 pr's? Seems to me that the latter two might take a while...

@ahmednfwela
Copy link
Contributor

yes we can do that but,can you create a separate issue to track the needed tests?

@noordawod
Copy link
Contributor Author

yes we can do that but,can you create a separate issue to track the needed tests?

I need help with that :| I never wrote tests… Would you like to help?

@ahmednfwela
Copy link
Contributor

it's ok after the new PR I will write the tests

@noordawod
Copy link
Contributor Author

it's ok after the new PR I will write the tests

Perfect, thank you! Then, this pr is updated with upstream and ready to merge.

@ahmednfwela
Copy link
Contributor

cc @wing328 Ready for merge
also friendly reminder that #10189 is blocking multiple PRs :)

@noordawod
Copy link
Contributor Author

Bump :)

@wing328 wing328 merged commit 3dd93be into OpenAPITools:master Jun 20, 2023
@wing328 wing328 added this to the 7.0.0 milestone Jun 20, 2023
fmoraespadtec pushed a commit to padteclab/openapi-generator that referenced this pull request Jun 26, 2023
…ls#15516)

* Expose `deserialize` function.

* Rename `json` argument.

* Generate Petstore code.

* Upgrade minimum version of `intl` dependency.
@noordawod noordawod deleted the feature/flutter-3-10-0 branch June 29, 2023 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants