MockResponse
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}].jsonExamples:
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.jsonResponse 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)"