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

Format application/network interceptor names for WebActionMetadata #853

Merged
merged 1 commit into from Mar 14, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+11 −8
Diff settings

Always

Just for now

@@ -7,6 +7,7 @@ import misk.web.NetworkInterceptor
import misk.web.PathPattern
import misk.web.RequestContentType
import misk.web.ResponseContentType
import misk.web.formatter.ClassNameFormatter
import misk.web.jetty.WebActionsServlet
import misk.web.mediatype.MediaRange
import misk.web.mediatype.MediaTypes
@@ -72,8 +73,8 @@ internal fun WebActionMetadata(
parameterTypes = parameterTypes.map { it.toString() },
returnType = returnType.toString(),
pathPattern = pathPattern.toString(),
applicationInterceptors = applicationInterceptors.map { it::class.qualifiedName.toString() },
networkInterceptors = networkInterceptors.map { it::class.qualifiedName.toString() },
applicationInterceptors = applicationInterceptors.map { ClassNameFormatter.format(it::class) },
networkInterceptors = networkInterceptors.map { ClassNameFormatter.format(it::class) },
dispatchMechanism = dispatchMechanism,
allowedServices = allowedServices,
allowedRoles = allowedRoles
@@ -4,10 +4,12 @@ import javax.inject.Inject
import kotlin.reflect.KClass

class ClassNameFormatter @Inject constructor() {
fun <T : Any> format(kclass: KClass<T>): String {
return when (kclass.qualifiedName) {
null -> kclass.toString().split("class ").last()
else -> kclass.qualifiedName.toString()
companion object {

This comment has been minimized.

Copy link
@adrw

adrw Mar 14, 2019

Member

Good call 👍

fun <T : Any> format(kclass: KClass<T>): String {
return when (kclass.qualifiedName) {
null -> kclass.toString().split("class ").last()
else -> kclass.qualifiedName.toString()
}
}
}
}
@@ -21,7 +21,7 @@ class ClassNameFormatterTest {
}

@Test fun validQualifiedName() {
val formatted = ClassNameFormatter().format(ValidQualifiedNameClass::class)
val formatted = ClassNameFormatter.format(ValidQualifiedNameClass::class)
isValid(formatted)
assertEquals(formatted, ValidQualifiedNameClass::class.qualifiedName.toString())
}
@@ -30,7 +30,7 @@ class ClassNameFormatterTest {
val noQualifiedNameClass = NoQualifiedNameFactory().create()
assertNull(noQualifiedNameClass::class.qualifiedName)

val formatted = ClassNameFormatter().format(noQualifiedNameClass::class)
val formatted = ClassNameFormatter.format(noQualifiedNameClass::class)
isValid(formatted)
assertEquals(formatted, noQualifiedNameClass::class.toString().split("class ").last())
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.