MockResponse

@Serializable
data class MockResponse(val statusCode: Int, val fileName: String, val displayName: String, val content: String)

Represents a loaded mock response that can be returned by the network mock plugin.

This data class encapsulates a mock API response loaded from a JSON file in the composeResources/files/networkmocks/responses/ directory. It contains the response status code, metadata for display, and the actual response content.

File Naming Convention

Response files follow a strict naming convention to enable automatic discovery:

  • Format: {endpointId}-{statusCode}[-{suffix}].json

  • Examples:

  • getUser-200.json → status 200, display name "Success (200)"

  • getUser-404-simple.json → status 404, display name "Not Found - Simple (404)"

  • getUser-500.json → status 500, display name "Server Error (500)"

  • get-user-200.json → status 200, hyphenated endpoint ID supported

File Location

Files should be organized by endpoint ID:

composeResources/files/networkmocks/responses/
├── getUser/
│ ├── getUser-200.json
│ ├── getUser-404-simple.json
│ └── getUser-500.json
└── createUser/
├── createUser-201.json
└── createUser-400.json

Response Content Format

The content is the raw JSON response body as a String. For MVP, response files contain only the response body (no metadata):

{
"id": "user-123",
"name": "John Doe",
"email": "john.doe@example.com"
}

Usage Example

val repository = MockConfigRepository("files/networkmocks/mocks.json")
val response = repository.loadMockResponse(
endpointId = "getUser",
fileName = "getUser-200.json"
)

response?.let {
println("Status: ${it.statusCode}")
println("Display: ${it.displayName}")
println("Content: ${it.content}")
}

Display Name Generation

The display name is automatically generated from the file name:

  • getUser-200.json → "Success (200)"

  • getUser-404-simple.json → "Not Found - Simple (404)"

  • getUser-404-detailed.json → "Not Found - Detailed (404)"

  • getUser-500.json → "Server Error (500)"

See also

Constructors

Link copied to clipboard
constructor(statusCode: Int, fileName: String, displayName: String, content: String)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The raw JSON response body as a String

Link copied to clipboard

Human-readable name for UI display (e.g., "Success (200)")

Link copied to clipboard

The original file name (e.g., "getUser-200.json")

Link copied to clipboard

HTTP status code extracted from the file name