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

@Location annotation for typealias #539

Closed
aviadmini opened this issue Aug 25, 2018 · 3 comments
Closed

@Location annotation for typealias #539

aviadmini opened this issue Aug 25, 2018 · 3 comments
Labels

Comments

@aviadmini
Copy link

I have a multiplatform project that makes use of common module in which my classes for API request/response are located. This is why I can't use @Location on the class itself (because common module can't have ktor jvm dependency)
I tried to create a typealias and apply @Location annotation to it but it gives compiler error because annotation doesn't target typealiases

I am not sure if this can be solved by just adding @Target(AnnotationTarget.TYPEALIAS) or needs some deeper integration but I'm sure this is a great feature to support

@spand
Copy link
Contributor

spand commented Aug 30, 2018

As a workaround you can make your own LocationRouteService (that you instantiate from your own locations feature) that looks for a different annotation.

We have something like this where Path is our own location annotation:

class CustomLocationRouteService : LocationRouteService {
    inline fun <reified T : Annotation> KAnnotatedElement.annotation(): T? {
        return annotations.singleOrNull { it.annotationClass == T::class } as T?
    }

    override fun findRoute(klass: kotlin.reflect.KClass<*>): String? {
        return klass.annotation<Path>()?.path
    }
}

object CustomLocationsFeature : ApplicationFeature<Application, Locations, Locations> {
    override val key: AttributeKey<Locations> = Locations.key

    override fun install(pipeline: Application,
                         configure: io.ktor.locations.Locations.() -> Unit): Locations {
        return Locations(pipeline, CustomLocationRouteService()).apply(configure)
    }
}

@stale
Copy link

stale bot commented Sep 24, 2019

This issue has been automatically marked as stale because it has not had recent activity.

@stale stale bot added the stale label Sep 24, 2019
@oleg-larshin
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

@e5l e5l removed the stale label Apr 5, 2021
@Stexxe Stexxe closed this as completed Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants