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

Export MediaType from http_parser #2205

Merged
merged 9 commits into from
May 22, 2024

Conversation

Reprevise
Copy link
Contributor

@Reprevise Reprevise commented Apr 29, 2024

Resolves #2212

New Pull Request Checklist

  • I have read the Documentation
  • I have searched for a similar pull request in the project and found none
  • I have updated this branch with the latest main branch to avoid conflicts (via merge from master or rebase)
  • I have added the required tests to prove the fix/feature I'm adding
  • I have updated the documentation (if necessary)
  • I have run the tests without failures
  • I have updated the CHANGELOG.md in the corresponding package

Additional context and info (if any)

This PR exports MediaType from the http_parser package so that way users don't have to import a (probably) transitive dependency.

@Reprevise Reprevise requested a review from a team as a code owner April 29, 2024 21:29
@ueman
Copy link
Contributor

ueman commented Apr 30, 2024

What would be the use case here? Can you give an example?

I'm tempted to decline this PR, since exporting other libraries is rather bad form. Especially if it's just exporting one class of it. If you need http_parser code, you should depend on it. For dio, it's pretty much an implementation detail, and exporting it makes it no longer an implementation detail, and thus harder for us to evolve related things.

@kuhnroyal
Copy link
Member

Yea, I don't think we use this class as parameter anywhere. If you want to use this for parsing mime/media types you should import this in your package.

@ueman ueman closed this Apr 30, 2024
@AlexV525
Copy link
Member

Well, we accept MediaType as content-type in the multipart file.

MediaType? contentType,

But I agree that users should import the package explicitly.

@Reprevise
Copy link
Contributor Author

I 100% disagree. Why should users have to add a dependency which is an implementation detail of dio just to use the API? Exporting types from other packages is a very normal thing to do and is common in popular packages.

@AlexV525
Copy link
Member

I'm trying to find best practices for re-exporting packages from the package but failed to find something. Given that we have previous arguments about "best practice", I'm reopening this for further discussions.

@AlexV525 AlexV525 reopened this May 18, 2024
dio/lib/dio.dart Outdated Show resolved Hide resolved
@kuhnroyal
Copy link
Member

Well, let's do it.

@ueman
Copy link
Contributor

ueman commented May 19, 2024

Should we document somewhere that we're re-exporting these classes, in case people will run into name conflicts? Is it even possible to run into problems?

@kuhnroyal
Copy link
Member

What if we use a type alias with a Dio prefix and re-export that? It will still accept the original MediaType type so it should not break anything.

@AlexV525
Copy link
Member

What if we use a type alias with a Dio prefix and re-export that? It will still accept the original MediaType type so it should not break anything.

That would be a great idea. @Reprevise Could you make that attempt?

@Reprevise
Copy link
Contributor Author

I could do:

typedef DioMediaType = MediaType;

Though I prefer the exporting approach so that users would just get an unnecessary_import lint and its easier to migrate than having to change MediaType to DioMediaType.

@kuhnroyal
Copy link
Member

They should not get any warning, the MediaType should still be an accepted argument.

@Reprevise
Copy link
Contributor Author

They should not get any warning, the MediaType should still be an accepted argument.

Not saying they should get a warning, but I just mean if they want to get rid of the http_parser import and the explicit dependency of it in pubspec.yaml.

@kuhnroyal
Copy link
Member

Those who care about removing the explicit dependency are free to change from MediaType to DioMediaType.
Everyone else is not effected.
And we prevent compiler warnings for duplicate types/exports.

@Reprevise
Copy link
Contributor Author

I have updated to use the type alias. The reason I had the constructors take DioMediaType is to make it less confusing for newer users. Users who see MediaType will try and use it and it won't be available to them without first depending on http_parser whereas if they use DioMediaType it will instantly be available.

@kuhnroyal
Copy link
Member

For me it looks good, can you maybe add a test which ensure that we can still pass the MediaType as argument? Or is that overkill?

@Reprevise
Copy link
Contributor Author

One thing that I didn't consider is that when hovering over the constructor, it doesn't actually say the alias, it just says the type.
image
So even though I changed the constructor to take a DioMediaType, you'd only know that if you go to the actual declaration.

dio/CHANGELOG.md Outdated Show resolved Hide resolved
dio/lib/src/multipart_file.dart Show resolved Hide resolved
Co-authored-by: Alex Li <github@alexv525.com>
Signed-off-by: Benjamin <bschoe322@gmail.com>
@AlexV525
Copy link
Member

@Reprevise Could you solve the format issue?

@Reprevise
Copy link
Contributor Author

@Reprevise Could you solve the format issue?

What format issue?

@AlexV525
Copy link
Member

@Reprevise Could you solve the format issue?

What format issue?

https://github.com/cfug/dio/actions/runs/9175832587/job/25229693166?pr=2205

Copy link
Contributor

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
plugins/http2_adapter/lib/src/connection_manager_imp.dart 🟠 60.47% 🟢 79.84% 🟢 19.37%
Overall Coverage 🟢 80.58% 🟢 81.41% 🟢 0.83%

Minimum allowed coverage is 0%, this run produced 81.41%

@AlexV525 AlexV525 merged commit f87a095 into cfug:main May 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I can't use MediaType when I create MultipartFile
4 participants