Package-level declarations

Types

Link copied to clipboard
data object Auto

Marker used by generates auto to request Fiktion's automatic generation.

Link copied to clipboard
class CannotGenerateException(message: String, cause: Throwable? = null) : RuntimeException

Thrown when Fiktion cannot generate a value for the requested target.

Link copied to clipboard
data object Default

Marker used by generates default to request a constructor default value.

Link copied to clipboard
@RequiresOptIn(message = "This Fiktion API is experimental and may change before 1.0.", level = RequiresOptIn.Level.WARNING)
annotation class ExperimentalFiktionApi

Marks APIs that are expected to evolve before Fiktion reaches 1.0.

Link copied to clipboard
interface FakeContext

Runtime context passed to custom generators.

Link copied to clipboard

Runtime nullability information for a generated property.

Link copied to clipboard
data class FakePath(val segments: List<FakeProperty>)

Runtime path to a generated value.

Link copied to clipboard
data class FakeProperty(val owner: FakeType, val name: String, val type: FakeType, val nullability: FakeNullability)

Runtime description of a generated property.

Link copied to clipboard
class FakeSpec<Root>

Per-call configuration for generating a Root value.

Link copied to clipboard
data class FakeType(val id: String, val displayName: String)

Runtime description of a generated type.

Link copied to clipboard
sealed interface Fiktion

Configured fake data generator.

Link copied to clipboard
interface FiktionAddon

Extension point that contributes reusable Fiktion rules.

Link copied to clipboard

Builder exposed to add-ons for contributing reusable low-precedence rules.

Link copied to clipboard
class FiktionArrayMetadata<T>(val type: KType, val elementType: KType, constructor: (List<Any?>) -> T) : FiktionTypeMetadata<T>

Runtime construction metadata for an array type that Fiktion can generate automatically.

Link copied to clipboard

Builder exposed when creating isolated Fiktion instances.

Link copied to clipboard

Typed key for configuring built-in and add-on generators.

Link copied to clipboard
data class FiktionConfigSetting<Scope, Value : Any>(val key: FiktionConfig<Scope, Value>, val value: Value)

Typed generator configuration value.

Link copied to clipboard

Thrown when Fiktion configuration or DSL input is invalid.

Link copied to clipboard

Builder exposed when updating the global Fiktion configuration.

Link copied to clipboard
class FiktionEnumMetadata<T : Enum<T>>(val type: KType, val entries: List<T>) : FiktionTypeMetadata<T>

Runtime construction metadata for an enum type.

Link copied to clipboard
sealed interface FiktionObjectArgument

Constructor argument produced while generating an object.

Link copied to clipboard

Constructor argument marker that asks generated metadata to use the property's default value.

Link copied to clipboard
class FiktionObjectMetadata<T>(val type: KType, val properties: List<FiktionObjectProperty>, constructor: (List<FiktionObjectArgument>) -> T) : FiktionTypeMetadata<T>

Runtime construction metadata for a type that Fiktion can generate automatically.

Link copied to clipboard
data class FiktionObjectProperty(val name: String, val type: KType, val hasDefault: Boolean = false)

Runtime construction metadata for one generated object property.

Link copied to clipboard
data class FiktionObjectValue(val value: Any?) : FiktionObjectArgument

Constructor argument containing a generated value.

Link copied to clipboard
sealed class FiktionRuleBuilder

Shared rule registration surface exposed by Fiktion builders.

Link copied to clipboard
class FiktionSealedMetadata<T>(val type: KType, val subtypes: List<KType>) : FiktionTypeMetadata<T>

Runtime construction metadata for a sealed type.

Link copied to clipboard
sealed interface FiktionSnapshot

Restorable snapshot of the global Fiktion configuration.

Link copied to clipboard
sealed interface FiktionTypeMetadata<T>

Runtime metadata for a type that Fiktion can generate automatically.

Link copied to clipboard
class FiktionValueMetadata<T>(val type: KType, val underlyingType: KType, val propertyName: String, constructor: (value: Any?) -> T) : FiktionTypeMetadata<T>

Runtime construction metadata for a value-like type backed by one generated value.

Link copied to clipboard
sealed interface GenerationSpec<out T>

Configured generation rule for values of T.

Link copied to clipboard
typealias Generator<T> = FakeContext.() -> T

Custom value generator executed with a FakeContext.

Link copied to clipboard
value class Probability(val value: Double)

Probability value represented as a number from 0.0 to 1.0.

Link copied to clipboard
class PropertyPath<Root, out Value>

Type-safe path from Root to a nested Value property.

Link copied to clipboard
sealed interface RuleNameTarget

Target selected by a property-name rule before its value type is known.

Link copied to clipboard
sealed interface RuleTarget<T>

Target selected by a rule declaration.

Link copied to clipboard

Context for generating a value from the requested type's type arguments.

Link copied to clipboard

Generator used by type-family rules.

Link copied to clipboard
sealed interface TypeFamilyRuleTarget<T>

Target selected by a type-family rule declaration.

Link copied to clipboard
sealed interface UniqueElementStrategy

Strategy for generating distinct values for set-like collections.

Properties

Link copied to clipboard
val auto: Auto

Requests Fiktion's automatic generation in rule declarations.

Link copied to clipboard

Requests a constructor default value in rule declarations.

Link copied to clipboard

Targets elements generated for the current collection root.

Targets elements generated for the collection selected by this target.

Link copied to clipboard

Targets keys generated for the current map root.

Targets keys generated for the map selected by this target.

Link copied to clipboard

Converts this floating-point percentage to a Probability.

Converts this integer percentage to a Probability.

Link copied to clipboard

Targets values generated for the current map root.

Targets values generated for the map selected by this target.

Functions

Link copied to clipboard
fun FakeContext.childContext(index: Int, seedIndex: Int = index): FakeContext

Creates a child fake context with separate seed and public index values.

Link copied to clipboard

Appends next to this property path.

Creates a nested property path using /.

Link copied to clipboard
inline fun <T> fake(seed: Long? = null, noinline configure: FakeSpec<T>.() -> Unit = {}): T

Generates fake data for T using the global Fiktion configuration.

fun <T> fake(type: KType, seed: Long? = null, configure: FakeSpec<T>.() -> Unit = {}): T

Generates fake data for T using the global Fiktion configuration and explicit type.

Link copied to clipboard
inline fun <T> Fiktion.fake(seed: Long? = null, noinline configure: FakeSpec<T>.() -> Unit = {}): T

Generates fake data for T using this Fiktion instance.

fun <T> Fiktion.fake(type: KType, seed: Long? = null, configure: FakeSpec<T>.() -> Unit = {}): T

Generates fake data for T using this Fiktion instance and explicit type.

Link copied to clipboard
inline fun <T> generatedArray(elements: List<Any?>): Array<T>

Creates a typed array from compiler-generated array metadata.

Link copied to clipboard

Returns whether the generated constructor argument at index asks Kotlin to use the property's default value.

Link copied to clipboard

Returns the generated constructor argument value at index.

Link copied to clipboard
infix inline fun <T> RuleNameTarget.generates(value: T): GenerationSpec<T>

Generates value for this name target and infers the target value type from value.

infix fun <T> RuleTarget<T>.generates(value: T): GenerationSpec<T>

Generates value for this rule target.

infix fun <T> RuleTarget<T>.generates(auto: Auto): GenerationSpec<T>

Uses Fiktion's automatic generation for this rule target.

infix fun <T> RuleTarget<T>.generates(default: Default): GenerationSpec<T>

Uses the constructor default value for this rule target.

Uses Fiktion's automatic generation for this type-family target.

Link copied to clipboard
infix inline fun <T> RuleNameTarget.generatesBy(noinline generator: Generator<T>): GenerationSpec<T>

Generates values for this name target and infers the target value type from generator.

infix fun <T> RuleTarget<T>.generatesBy(generator: Generator<T>): GenerationSpec<T>

Generates values for this rule target by invoking generator.

Generates values for this type-family target by invoking generator.

Link copied to clipboard
@JvmName(name = "generatesByteIn")
infix fun RuleTarget<Byte>.generatesIn(range: IntRange): GenerationSpec<Byte>

Generates byte values within range.

Generates character values within range.

@JvmName(name = "generatesDoubleIn")
infix fun RuleTarget<Double>.generatesIn(range: ClosedFloatingPointRange<Double>): GenerationSpec<Double>

Generates double values within range.

@JvmName(name = "generatesFloatIn")
infix fun RuleTarget<Float>.generatesIn(range: ClosedFloatingPointRange<Float>): GenerationSpec<Float>

Generates float values within range.

Generates integer values within range.

Generates long values within range.

@JvmName(name = "generatesShortIn")
infix fun RuleTarget<Short>.generatesIn(range: IntRange): GenerationSpec<Short>

Generates short values within range.

@JvmName(name = "generatesUByteIn")
infix fun RuleTarget<UByte>.generatesIn(range: UIntRange): GenerationSpec<UByte>

Generates unsigned byte values within range.

Generates unsigned integer values within range.

Generates unsigned long values within range.

@JvmName(name = "generatesUShortIn")
infix fun RuleTarget<UShort>.generatesIn(range: UIntRange): GenerationSpec<UShort>

Generates unsigned short values within range.

Link copied to clipboard

Generates one value from values.

Link copied to clipboard
fun <T> generateUniqueElements(size: Int, strategy: UniqueElementStrategy, element: (Int) -> T): List<T>

Generates candidate elements for a set-like collection according to strategy.

Link copied to clipboard

Creates a typed generator configuration value for this key.

Creates a typed generator configuration value whose closed range is fixed to value.

operator fun <T> RuleTarget<T>.invoke(configure: RuleTarget<T>.() -> Unit): RuleTarget<T>

Groups declarations for this rule target.

Link copied to clipboard
infix fun <T, Value : Any> RuleTarget<T>.using(value: FiktionConfigSetting<in T, Value>)
fun <T, Value : Any> RuleTarget<T>.using(key: FiktionConfig<in T, Value>, value: Value)

Configures built-in or add-on generator behavior for this rule target.