Skip to content

Commit

Permalink
address a couple of compiler warnings and replace deprecated syntax (#…
Browse files Browse the repository at this point in the history
…240)

Co-authored-by: Jens Zettelmeyer <[email protected]>
  • Loading branch information
zettelmj and Jens Zettelmeyer authored Sep 24, 2023
1 parent 4405871 commit 7d622ca
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object ClientGeneratorUtils {
val builder = it.toParameterSpecBuilder()
if (it is RequestParameter) {
if (it.defaultValue != null) OasDefault.from(it.typeInfo, it.type, it.defaultValue)
?.let { builder.defaultValue(it.getDefault()) }
?.let { t -> builder.defaultValue(t.getDefault()) }
else if (!it.isRequired) builder.defaultValue("null")
annotateRequestParameterWith?.invoke(it)?.let { annotationSpec ->
builder.addAnnotation(annotationSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ object MicronautImports {
val AUTHENTICATION = ClassName(Packages.MICRONAUT_AUTHENTICATION, "Authentication")
val SECURITY_RULE = Pair(Packages.MICRONAUT_RULE, "SecurityRule")

val SECURITY_RULE_IS_AUTHENTICATED = "SecurityRule.IS_AUTHENTICATED"
val SECURITY_RULE_IS_ANONYMOUS = "SecurityRule.IS_ANONYMOUS"
const val SECURITY_RULE_IS_AUTHENTICATED = "SecurityRule.IS_AUTHENTICATED"
const val SECURITY_RULE_IS_ANONYMOUS = "SecurityRule.IS_ANONYMOUS"

val CONTROLLER = ClassName(Packages.MICRONAUT_HTTP_ANNOTATION, "Controller")
val BODY = ClassName(Packages.MICRONAUT_HTTP_ANNOTATION, "Body")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class MicronautAuthenticationTest {
fun `ensure that global authentication set to any authentication will add the required parameter`(testCase: Pair<String, String>) {
val controllers = setupTest(testCase.first)
val functionAnnotations = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.annotations } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.annotations } }

val functionParameters = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.parameters } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.parameters } }

assertThat(functionAnnotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == testCase.second }
}

Expand All @@ -78,13 +78,13 @@ class MicronautAuthenticationTest {
fun `ensure that no authentication defined will add no parameter`() {
val controllers = setupTest("global_authentication_none.yml")
val functionAnnotations = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.annotations } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.annotations } }

val functionParameters = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.parameters } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.parameters } }

assertThat(functionAnnotations).noneSatisfy { annotation ->
assertThat(annotation.className.simpleName).isEqualTo("Secured")
assertThat(annotation.typeName.toString()).isEqualTo("Secured")
}

assertThat(functionParameters).noneSatisfy { parameter ->
Expand All @@ -100,7 +100,7 @@ class MicronautAuthenticationTest {
val prohibitedController = (controllers.find { it.name == "ProhibitedController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(prohibitedController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_ANONYMOUS" }
}

Expand All @@ -111,7 +111,7 @@ class MicronautAuthenticationTest {
val requiredController = (controllers.find { it.name == "RequiredController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(requiredController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_AUTHENTICATED" }
}

Expand All @@ -124,7 +124,7 @@ class MicronautAuthenticationTest {
val optionalController = (controllers.find { it.name == "OptionalController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(optionalController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_AUTHENTICATED, SecurityRule.IS_ANONYMOUS" }
}

Expand All @@ -137,7 +137,7 @@ class MicronautAuthenticationTest {
val noneController = (controllers.find { it.name == "NoneController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(noneController.annotations).noneSatisfy { annotation ->
assertThat(annotation.className.simpleName).isEqualTo("Secured")
assertThat(annotation.typeName.toString()).isEqualTo("Secured")
}

assertThat(noneController.parameters).noneSatisfy { parameter ->
Expand All @@ -147,7 +147,7 @@ class MicronautAuthenticationTest {
val defaultController = (controllers.find { it.name == "DefaultController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(defaultController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_AUTHENTICATED" }
}

Expand All @@ -164,7 +164,7 @@ class MicronautAuthenticationTest {
val prohibitedController = (controllers.find { it.name == "ProhibitedController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(prohibitedController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_ANONYMOUS" }
}

Expand All @@ -175,7 +175,7 @@ class MicronautAuthenticationTest {
val requiredController = (controllers.find { it.name == "RequiredController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(requiredController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_AUTHENTICATED" }
}

Expand All @@ -187,7 +187,7 @@ class MicronautAuthenticationTest {
val optionalController = (controllers.find { it.name == "OptionalController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(optionalController.annotations).anySatisfy { annotation ->
assertThat(annotation.className.canonicalName).isEqualTo("io.micronaut.security.annotation.Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.`annotation`.Secured")
assertThat(annotation.members).anyMatch { it.toString() == "SecurityRule.IS_AUTHENTICATED, SecurityRule.IS_ANONYMOUS" }
}

Expand All @@ -200,7 +200,7 @@ class MicronautAuthenticationTest {
val noneController = (controllers.find { it.name == "NoneController" }!!.members.single() as TypeSpec).funSpecs.single()

assertThat(noneController.annotations).noneSatisfy { annotation ->
assertThat(annotation.className.simpleName).isEqualTo("Secured")
assertThat(annotation.typeName.toString()).isEqualTo("io.micronaut.security.annotation, Secured")
}

assertThat(noneController.parameters).noneSatisfy { parameter ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class MicronautControllerGeneratorTest {
fun `ensure controller has correct annotations`() {
setupGithubApiTestEnv()
val controllerAnnotations =
generated.flatMap { it.members.flatMap { (it as TypeSpec).annotations.map { it.typeName.toString() } } }
generated.flatMap { it.members.flatMap { ts -> (ts as TypeSpec).annotations.map { t -> t.typeName.toString() } } }
.distinct()

assertThat(controllerAnnotations).containsOnly(
Expand All @@ -139,9 +139,10 @@ class MicronautControllerGeneratorTest {
.flatMap { it.funSpecs }
.flatMap { it.parameters }
.flatMap { it.annotations }
.map { it.className.canonicalName }
.map { it.typeName.toString() }
.filter { ".validation." in it }
.distinct()
assertThat(parameterValidationAnnotations).isNotEmpty
assertThat(parameterValidationAnnotations).allMatch { it.startsWith(desiredPackagePrefix) }
}

Expand All @@ -164,11 +165,11 @@ class MicronautControllerGeneratorTest {
val linkedFunctionNames = controllers.files
.filter { it.name == "OrganisationsContributorsController" }
.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.map { it.name } }
.flatMap { (it as TypeSpec).funSpecs.map { t -> t.name } }
val ownedFunctionNames = controllers.files
.filter { it.name == "RepositoriesPullRequestsController" }
.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.map { it.name } }
.flatMap { (it as TypeSpec).funSpecs.map { t -> t.name } }
assertThat(linkedFunctionNames).containsExactlyInAnyOrder(
"get",
"getById",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SpringAuthenticationTest {
val controllers = setupTest("global_authentication_required.yml")

val functionParameters = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.parameters } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.parameters } }

assertThat(functionParameters).anySatisfy { parameter ->
assertThat(parameter.name).isEqualTo("authentication")
Expand All @@ -63,7 +63,7 @@ class SpringAuthenticationTest {
val controllers = setupTest("global_authentication_optional.yml")

val functionParameters = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.parameters } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.parameters } }

assertThat(functionParameters).anySatisfy { parameter ->
assertThat(parameter.name).isEqualTo("authentication")
Expand All @@ -77,7 +77,7 @@ class SpringAuthenticationTest {
val controllers = setupTest(testCasePath)

val functionParameters = controllers.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.flatMap { it.parameters } }
.flatMap { (it as TypeSpec).funSpecs.flatMap { t -> t.parameters } }

assertThat(functionParameters).noneSatisfy { parameter ->
assertThat(parameter.name).isEqualTo("authentication")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SpringControllerGeneratorTest {
fun `ensure controller has correct annotations`() {
setupGithubApiTestEnv()
val controllerAnnotations =
generated.flatMap { it.members.flatMap { (it as TypeSpec).annotations.map { it.typeName.toString() } } }
generated.flatMap { it.members.flatMap { ts -> (ts as TypeSpec).annotations.map { t -> t.typeName.toString() } } }
.distinct()

assertThat(controllerAnnotations).containsOnly(
Expand All @@ -137,9 +137,11 @@ class SpringControllerGeneratorTest {
.flatMap { it.funSpecs }
.flatMap { it.parameters }
.flatMap { it.annotations }
.map { it.className.canonicalName }
.map { it.typeName.toString() }
.filter { ".validation." in it }
.distinct()

assertThat(parameterValidationAnnotations).isNotEmpty
assertThat(parameterValidationAnnotations).allMatch { it.startsWith(desiredPackagePrefix) }
}

Expand All @@ -162,11 +164,11 @@ class SpringControllerGeneratorTest {
val linkedFunctionNames = controllers.files
.filter { it.name == "OrganisationsContributorsController" }
.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.map { it.name } }
.flatMap { (it as TypeSpec).funSpecs.map { t -> t.name } }
val ownedFunctionNames = controllers.files
.filter { it.name == "RepositoriesPullRequestsController" }
.flatMap { it.members }
.flatMap { (it as TypeSpec).funSpecs.map { it.name } }
.flatMap { (it as TypeSpec).funSpecs.map { t -> t.name } }
assertThat(linkedFunctionNames).containsExactlyInAnyOrder(
"get",
"getById",
Expand Down

0 comments on commit 7d622ca

Please sign in to comment.