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

Un-deprecate Ktorfit.create() #766

Open
kurthuwig opened this issue Jan 30, 2025 · 2 comments
Open

Un-deprecate Ktorfit.create() #766

kurthuwig opened this issue Jan 30, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@kurthuwig
Copy link

Is your feature request related to a problem? Please describe.

While I see the reason behind this change, I still see a valid reason to keep the create function:

Right now my code has to know that there is Ktorfit in use as I run

ktorfit.createMyApi()

If I use the generic create function, I can implement a simple wrapper, e.g. apiAccess, that allows me to write

apiAccess.create<MyApi>()

This wrapper is technology agnostic, so I can easily change between Ktorfit, Retrofit and another technology. For me Ktorfit is a technical detail that is the current solution on my app. But I prefer that it stays a technical detail and this would allow me to do so.

Describe the solution you'd like

I'd like that Ktorfit.create() is not @Deprecated.

Describe alternatives you've considered

No response

Additional context

No response

@kurthuwig kurthuwig added the enhancement New feature or request label Jan 30, 2025
@DatL4g
Copy link
Contributor

DatL4g commented Jan 31, 2025

Under the hood create<Service>() and createService() are not the same.
I understand why the create<Service>() method is discouraged.

However instead of @Deprecated we could annotate it with something like this:

@RequiresOptIn(message = "Move deprecation message here.")
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class Unstable

This would get rid of the deprecation warning but still shows that createService() should be used instead and requires a @OptIn(Unstable::class) then.

@Foso
Copy link
Owner

Foso commented Jan 31, 2025

Hi. @DatL4g is right, the functions are not the same under the hood. I prefer to keep it deprecated, because when it gets undeprecated it might encourage the usage of that function. It only still exists to simplify the migration from Ktorfit 1 to Ktorfit 2.

The problem is, that function only works because of the compiler plugin. And that plugin needs to be compatible with the Kotlin version you are currently using. So i need to release a new compiler plugin every time a new Kotlin version is released. And the API to write plugins can change with every new Kotlin version. Which is a huge maintenance pain.

The plan is to remove it with Ktorfit 3.0. Maybe i’ll take a look if i can turn it into an extension function and put it with the compiler plugin in an external project. Then people you need that functionality can fork it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants