Introspections

Utility object for annotation-based introspection, providing methods to process annotations for descriptions, ignore markers, and name overrides.

This object provides a configurable mechanism for recognizing annotations from multiple frameworks (kt-schema, Jackson, LangChain4j, Koog, kotlinx.serialization, etc.) Configuration is loaded from kt-schema.properties on the classpath.

Annotation name matching

Every configured annotation name is a glob pattern (* matches any run of characters, ? a single character; a plain literal name is just a pattern that matches itself), compiled via the shared me.kpavlov.kt.schema.generator.core.globToRegex matcher — the same one used by KSP's include/exclude package filters. Patterns are matched in two ways depending on their format:

  • Simple names (no dots): Matched case-insensitively against the annotation's simple name. Example: "Description" matches @Description, @description, @DESCRIPTION; "Json*" matches @JsonIgnore, @JsonIgnoreType, @JsonProperty, etc.

  • Fully qualified names (contains dots): Matched case-sensitively against the annotation's qualified name. Example: "kotlinx.serialization.SerialName" matches only @kotlinx.serialization.SerialName, not a different @SerialName from another package.

Configuration

The annotation detection behavior is controlled by properties in kt-schema.properties:

  • introspector.annotations.description.names: Comma-separated list of annotation names to recognize as description providers (e.g., "Description,LLMDescription,P")

  • introspector.annotations.description.attributes: Comma-separated list of annotation parameter names that contain description text (e.g., "value,description")

  • introspector.annotations.ignore.names: Comma-separated list of annotation names to recognize as ignore markers (e.g., "SchemaIgnore,JsonIgnoreType,JsonIgnore")

  • introspector.annotations.name.names: Comma-separated list of annotation names to recognize as name-override providers (e.g., "kotlinx.serialization.SerialName")

  • introspector.annotations.name.attributes: Comma-separated list of annotation parameter names that contain name-override text (e.g., "value")

Customizing Configuration

To add support for custom annotations, create kt-schema.properties in your project's src/main/resources/ directory (or src/commonMain/resources/ for multiplatform projects):

introspector.annotations.description.names=Description,MyCustomDescription
introspector.annotations.description.attributes=value,description,text

Your project's properties file will take precedence over the library's default configuration.

See also

Functions

Link copied to clipboard
fun getDefaultValueFromAnnotation(simpleName: String, qualifiedName: String?, annotationArguments: List<Pair<String, Any?>>): String?

Extracts the default-value text from an annotation if it matches a recognized default-value annotation (e.g., @JsonProperty(defaultValue = "...")).

Link copied to clipboard
fun getDescriptionFromAnnotation(simpleName: String, qualifiedName: String?, annotationArguments: List<Pair<String, Any?>>): String?

Extracts the description text from an annotation if it matches a recognized description annotation.

Link copied to clipboard
fun getNameOverride(simpleName: String, qualifiedName: String?, annotationArguments: List<Pair<String, Any?>>): String?

Extracts the name-override value from an annotation if it matches a recognized name-override annotation (e.g., @SerialName).

Link copied to clipboard
fun isEnumDefaultAnnotation(simpleName: String, qualifiedName: String? = null): Boolean

Checks whether the given annotation is recognized as an enum-default-value marker (e.g. Jackson's @JsonEnumDefaultValue), placed on a single enum constant to mark it as that enum type's default value.

Link copied to clipboard
fun isIgnoreAnnotation(simpleName: String, qualifiedName: String? = null): Boolean

Checks whether the given annotation is recognized as an ignore marker.

Link copied to clipboard
fun isNullableAnnotation(simpleName: String, qualifiedName: String? = null): Boolean

Checks whether the given annotation is recognized as a nullable marker (e.g. @Nullable).

Link copied to clipboard

Checks whether simpleName (a type's simple class name) matches a configured nullable-type-name glob pattern (e.g. *Opt).

Link copied to clipboard
fun isOptionalAnnotation(simpleName: String, qualifiedName: String? = null): Boolean

Checks whether the given annotation is recognized as an optional marker.

Link copied to clipboard

Checks whether simpleName (a type's simple class name) matches a configured optional-type-name glob pattern (e.g. *Opt).