dnault / therapi-runtime-javadoc

Read Javadoc comments at run time.
Apache License 2.0
117 stars 19 forks source link

JavaDoc of Kotlin enum constants not picked up #72

Closed bkahlert closed 1 year ago

bkahlert commented 1 year ago

I'm using this annotation processor to bake in JavaDoc that get's picked up by an OpenAPI generation component. When I tried to add the enum constant JavaDocs to the OpenAPI document I can into the following problem:

The JavaDoc of enum constants doesn't seem to get processes / discovered when those are in Kotlin code. Though the class level JavaDoc get's processed.

Dependencies:

    annotationProcessor("com.github.therapi:therapi-runtime-javadoc-scribe:0.15.0")
    kapt("com.github.therapi:therapi-runtime-javadoc-scribe:0.15.0")

Kotlin enum

/**
 * My enum title
 *
 * My enum description
 */
enum class MyEnum {
    /**
     * Foo title
     *
     * Foo description
     */
    Foo,

    /**
     * Bar title
     *
     * Bar description
     */
    Bar
}

This creates the following json MyEnum__Javadoc.json:

{"doc":" My enum title\n\n My enum description\n","fields":[],"enumConstants":[],"methods":[],"constructors":[]}

Now when I use the following Java enum, the enum constants get processed as expected:

/**
 * My enum title
 * <p>
 * My enum description
 */
public enum MyJavaEnum {
    /**
     * Foo title
     * <p>
     * Foo description
     */
    Foo,

    /**
     * Bar title
     * <p>
     * Bar description
     */
    Bar
}

MyJavaEnum__Javadoc.json:

{"doc":" My enum title\n <p>\n My enum description\n","fields":[],"enumConstants":[{"name":"Foo","doc":" Foo title\n <p>\n Foo description\n"},{"name":"Bar","doc":" Bar title\n <p>\n Bar description\n"}],"methods":[],"constructors":[]}

Do you have any advice?

dnault commented 1 year ago

Hi Björn. I did a little experiment, and learned that kapt tells the annotation processor about enum constants, but not the associated doc comments. This makes the scribe think the enum constants are undocumented, so it omits them from the JSON.

I suspect the fix for this issue would be in kapt. Getting the Kotlin team to look into it might be an uphill battle, since kapt is in maintenance mode and the future of annotation processing in Kotlin is KSP.

If someone knows a clever way to get enum constant doc comments from kapt, I can take another look. Until then, I'm afraid this is a "won't fix".