Skip to content

Multiplatform Ktor schema declarationopensavvy.spine.apiParameters

Parameters

abstract class Parameters(val data: ParameterStorage = HashMap())

Additional parameters for endpoints.

Endpoints declare mandatory parameters, such as the identifier of the resource. This abstract class allows to declare additional parameters in a type-safe manner.

Usage

In common code, declare a class that inherits from Parameters, and use it to declare the name and type of the available parameters:

class MyRequestParameters(data: ParameterStorage) : Parameters(data) {
    var param1: String? by parameter()
    var isSubscribed: Boolean by parameter("is_subscribed", default = false)
}

To create a new parameter bundle, use the helper buildParameters function:

val example = buildParameters(::MyRequestParameters) {
    param1 = "value"
    isSubscribed = true
}

The values can be accessed in a type-safe manner:

println(example.param1)

The values can also be accessed via their string representation:

println(example.data["param1"])

Inheritors

Constructors

Parameters

constructor(data: ParameterStorage = HashMap())

Types

Empty

object Empty : Parameters

The default parameter instance.

Parameter

class Parameter<T>(val name: String, val defaultValue: T?)

A declared query parameter in an API schema.

UnnamedParameter

Internal type used by the parameter declaration syntax.

Properties

data

Internal string representation of the parameters.

Functions

equals

open operator override fun equals(other: Any?): Boolean

hashCode

open override fun hashCode(): Int

toString

open override fun toString(): String