What is the proper way to annotate variable with KDoc?

1.2k views Asked by At

I'm tried to annotate like @property but it is not right. Dokka does not recognise it

For example enum:

enum class Vegetables(val id: Int) {
    POTATO(1),
    CARROT(2),
    CUCUMBER(3)
}
1

There are 1 answers

1
Joffrey On BEST ANSWER

You can take a look at the Kotlin documentation about how to put doc comments in the code.

You can place documentation wherever the thing you want to document is.

/**
 * Here goes your main Vegetables type doc.
 *
 * You can refer to the [id] constructor argument like this.
 */
enum class Vegetables(
    /**
     * Here goes the doc for your id constructor argument and property.
     */
    val id: Int
) {
    /**
     * Here goes the doc for POTATO.
     */
    POTATO(1),
    /**
     * Here goes the doc for CARROT.
     */
    CARROT(2),
    /**
     * Here goes the doc for CUCUMBER.
     */
    CUCUMBER(3)
}

Alternatively, you can also document properties from the class doc:

/**
 * Here goes your main Vegetables type doc.
 *
 * You can refer to the [id] constructor argument like this.
 *
 * @property id You can also document the id property this way
 */
enum class Vegetables(val id: Int) {
    // ...
}