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

The getter 'MediaType' isn't defined for the class #692

Open
sbatezat opened this issue Jul 4, 2024 · 4 comments
Open

The getter 'MediaType' isn't defined for the class #692

sbatezat opened this issue Jul 4, 2024 · 4 comments

Comments

@sbatezat
Copy link

sbatezat commented Jul 4, 2024

Describe the bug
Bumping retrofit_generator from 8.1.0 to 8.1.1 leads to a generation error.

The getter 'MediaType' isn't defined for the class
Try correcting the name to the name of an existing getter, or defining a getter or field named 'MediaType'.
        contentType: MediaType.parse('application/json'),

To Reproduce
Steps to reproduce the behavior:

  @POST("/my/endpoint")
  Future<MyDto> post(
    @Part(name: "data", contentType: "application/json") MyDto data, {
    @Part() File? file,
  });

Expected behavior
Generator succeed

@dzsonni
Copy link
Contributor

dzsonni commented Jul 11, 2024

@sbatezat will take a look at it in a few hours

@trevorwang
Copy link
Owner

@sbatezat Import MediaType manually as a workaround

@sbatezat
Copy link
Author

Thanks, it's working by importing manually http_parser.

import 'package:http_parser/http_parser.dart';

It's a workaround, as you said, so I keep this issue open waiting for a robust fix!

@dzsonni
Copy link
Contributor

dzsonni commented Jul 16, 2024

@sbatezat The problem here is that MediaType is not imported by default if you are not using it in the template for the api, since we can't add imports in part files, the only solution I see is to expose http_parser's MediaType through
export 'package:http_parser/http_parser.dart' show MediaType in http.dart, as that is always imported in template files. Is this acceptable? It would mean an extra dependency.
I don't see any other way we could guarantee the import, but I am not an ace when it comes to working with code_gen

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

No branches or pull requests

3 participants