Skip to content

Commit 275f9e6

Browse files
committed
GH-147 Adjust scripting API to the new inheritance model
1 parent 7026668 commit 275f9e6

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

openapi-annotation-processor/src/test/compile/openapi.groovy

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.javalin.openapi.experimental.ExperimentalCompileOpenApiConfiguration
55
import io.javalin.openapi.experimental.OpenApiAnnotationProcessorConfiguration
66
import io.javalin.openapi.experimental.OpenApiAnnotationProcessorConfigurer
77
import io.javalin.openapi.experimental.SimpleType
8-
import org.jetbrains.annotations.Nullable
98

109
import javax.lang.model.element.Element
1110
import javax.lang.model.element.TypeElement
@@ -22,13 +21,18 @@ class OpenApiConfiguration implements OpenApiAnnotationProcessorConfigurer {
2221

2322
// Used by UserCasesTest
2423
configuration.propertyInSchemeFilter = { AnnotationProcessorContext ctx, ClassDefinition type, Element property ->
25-
@Nullable TypeElement specificRecord = ctx.forTypeElement('io.javalin.openapi.processor.UserCasesTest.SpecificRecord')
24+
TypeElement specificRecord = ctx.forTypeElement('io.javalin.openapi.processor.UserCasesTest.SpecificRecord')
25+
TypeElement specificRecordBase = ctx.forTypeElement('io.javalin.openapi.processor.UserCasesTest.SpecificRecordBase')
2626

27-
if (specificRecord != null && ctx.isAssignable(type.mirror, specificRecord.asType())) {
28-
return !ctx.hasElement(specificRecord, property)
27+
if (ctx.isAssignable(type.mirror, specificRecord.asType()) && ctx.hasElement(specificRecord, property)) {
28+
return false // exclude
2929
}
3030

31-
return true
31+
if (ctx.isAssignable(type.mirror, specificRecordBase.asType()) && ctx.hasElement(specificRecordBase, property)) {
32+
return false // exclude
33+
}
34+
35+
return true // include
3236
}
3337

3438
// Used by CustomTypeMappingsTest

openapi-annotation-processor/src/test/kotlin/io/javalin/openapi/processor/UserCasesTest.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ internal class UserCasesTest : OpenApiAnnotationProcessorSpecification() {
5757
}
5858

5959
open class SpecificRecordBase {
60-
fun getRecordBase(): String = "RecordBase" // it'll be excluded, because annotation processor only takes declared properties from the main class
60+
fun getRecordBase(): String = "RecordBase" // it'll be excluded
6161
}
6262

63-
@OpenApiByFields
6463
class EmailRequest(val email: String) : SpecificRecordBase(), SpecificRecord {
6564
override fun getRecord(): String = "Record" // it will be excluded by `compile/openapi.groovy` script
6665
}
@@ -72,12 +71,10 @@ internal class UserCasesTest : OpenApiAnnotationProcessorSpecification() {
7271
)
7372
@Test
7473
fun gh108() = withOpenApi("gh-108") {
75-
println(it)
76-
7774
assertThatJson(it)
7875
.inPath("$.components.schemas.EmailRequest")
7976
.isObject
80-
.containsEntry("required", json("['getEmail']"))
77+
.containsEntry("required", json("['email']"))
8178
}
8279

8380
}

openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/AnnotationProcessorContext.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class AnnotationProcessorContext(
5252

5353
fun hasElement(type: TypeElement, element: Element): Boolean =
5454
when (element) {
55-
is ExecutableElement -> type.enclosedElements.filterIsInstance<ExecutableElement>().any { env.elementUtils.overrides(element, it, type) }
55+
is ExecutableElement -> env.elementUtils.getAllMembers(type).let { members ->
56+
members.contains(element) || members.filterIsInstance<ExecutableElement>().any { env.elementUtils.overrides(element, it, type) }
57+
}
5658
else -> false
5759
}
5860

0 commit comments

Comments
 (0)