EndpointMockState

@Serializable
sealed interface EndpointMockState

Represents the mocking state for a single API endpoint.

Each endpoint is either passing traffic through to the actual network or returning a specific mock response. The two variants are represented as distinct types, eliminating any ambiguous state combinations that existed in the previous boolean-flag approach.

Variants

VariantBehaviordisplayName
NetworkAll requests pass through to the actual network (default)"Network"
MockRequests return the mock response loaded from Mock.responseFileMock.responseFile without .json

Usage Example

// Configure endpoint to use a mock response
val state = EndpointMockState.Mock(responseFile = "getUser-200.json")

// Configure endpoint to use the actual network
val state = EndpointMockState.Network

Checking the state

when (state) {
is EndpointMockState.Network -> { /* use real network */}
is EndpointMockState.Mock -> { /* load mock from state.responseFile */}
}

Response File Naming Convention

The Mock.responseFile should match one of the available response files for the endpoint, following the naming convention:

  • {endpointId}-{statusCode}.json

  • {endpointId}-{statusCode}-{suffix}.json

Example files for a getUser endpoint:

  • getUser-200.json

  • getUser-404-simple.json

  • getUser-404-detailed.json

  • getUser-500.json

See also

Inheritors

Types

Link copied to clipboard
@Serializable
@SerialName(value = "mock")
data class Mock(val responseFile: String) : EndpointMockState

The endpoint will return a mock response loaded from responseFile.

Link copied to clipboard
@Serializable
@SerialName(value = "network")
data object Network : EndpointMockState

The endpoint will pass all requests through to the actual network.

Properties

Link copied to clipboard
abstract val displayName: String

A human-readable display name for this state, suitable for use in UI labels.