NetworkMock UI
The devview-networkmock module provides the registered Compose UI for network mocking, backed by devview-networkmock-core. The operation list owns a quick-choice sheet. Response inspection and sequence editing use separate full-screen destinations owned by the module, not public screen composables.
Screens
Main screen — operation list
The main screen shows a global mock toggle at the top, followed by a scrollable tab row with one tab per OpenAPI spec (e.g. "My Backend"). Each tab lists every operation declared in that spec with its current mock state — there is no environment axis, so a spec spanning multiple API versions shows all of its operations side by side in one tab.
- Global toggle: enables or disables all mocking globally. When off, all requests go to the real network regardless of per-endpoint settings. Shows a count of mocked operations (e.g. "3 of 47 mocked") computed across every spec, not just the visible tab.
- Search & filter bar: the shared pinned search field expands a bounded, scrollable panel with Sort by, State, Version, Method, and Tag groups. The badge counts active non-search selections, including a non-default sort. Filters combine with AND; multi-select chips within one group combine with OR. Search and every selection are independent per API group and survive navigation and screen recreation through navigation-owned saved state, without changing persisted mock settings. Clear filters resets that group’s selections and sort but keeps its search; an empty result offers Clear search and filters to reset both.
- Search field: filters the visible operations in the current tab by name, path, or operationId, live as you type.
- Mock-state filter: per-group "Mocked"/"Network" chips. Mocked includes response mocks, failures, and sequences; no selection shows both.
- Version filter: "All" or one version per API group (see Version Tags). Hidden when there are no versioned operations or retained version selection. Selections absent after a spec reload remain visible so they can be cleared.
- Method filter: a per-tab row of chips, one per distinct
Operation.methodpresent among that tab's operations, orderedGET/POST/PUT/PATCH/DELETE/HEAD/OPTIONS. Multi-select — no chip selected shows every method; selecting one or more narrows the list to operations using any of the selected methods. - Tag filter: a per-tab row of chips, one per distinct
Operation.tagpresent among that tab's operations (see Tags), alphabetically ordered. Multi-select, same semantics as the method filter. Hidden when a spec has no tagged operations and no retained tag selection; selections absent after a reload remain available to clear. - Endpoint rows: a leading colour rail (the state chip's colour, transparent when not mocked) followed by the endpoint name, a colour-coded HTTP method badge, the path (wraps instead of truncating — never cut off), and the current state (quiet Network text / a semantic status chip with a bare code, e.g. "404"). There is no separate version badge —
Operation.versionis parsed from the path shown right next to it, so it would only repeat what's already visible. Tap a row to open its operation sheet. - Reset all to network: confirmed toolbar action that atomically resets persisted and pre-registered operations, including untouched endpoints. The global toggle is unchanged.
- Reload specs: toolbar action that re-reads and re-parses every configured OpenAPI spec from disk, picking up edits to a spec file without restarting the app. Operations added, removed, or renamed in the spec appear immediately; per-operation mock selections are untouched. See Caching & Reload.
- Sort: selected chips inside the filter panel, not a separate toolbar menu. Choose Default (spec document order), Path (A-Z), Method (
HttpMethod.DefaultMethodsorder), Tag (first declared tag, untagged first), or Mocked first (Mock, Failure, and Sequence before Network, stable within each group). Sort is saved per API group alongside its filters.
Operation sheet
Tapping an endpoint opens a wrap-content sheet. The header shows the operation name, method and wrapping path. A compact summary below it identifies the persisted configuration; it does not imply mocking is enabled globally. Controls stay above the scrolling choices when there is enough height. In a short viewport, the controls scroll too so choices remain reachable. Focusing response search brings matching choices into view above the keyboard, including when a failure-rate note separates the search field from the choices.
- Configured behaviour: Actual network, Single response, Simulated failure or a sequence summary. A sequence shows its next step and coloured response, with Edit and Restart alongside the heading when they fit. Long names and media types wrap; narrow layouts put actions on another row. The last step repeats. An unavailable next step is labelled unavailable rather than showing an invalid position.
- Use actual network: a direct radio choice bypasses this operation's mock. Selecting it replaces any saved response, failure or sequence.
- Responses / Failures: browsing tabs do not change configuration. Response variants retain status-family grouping and the list's semantic colour badges. Search responses matches status code, name, example or media type without changing the saved choice. A radio marks only a selected standalone response, not the next response of a sequence. Media types distinguish otherwise identical variants; generated bodies have a quiet "Generated" label.
- Details: the labelled trailing button opens that variant without activating it. The sheet finishes closing before navigation begins.
- Failures: Timeout and Connection refused appear in the Failures tab, using the same choice-row spacing and semantic badges. The read-only spec failure rate affects mocked responses and sequences, not actual network or explicit failures; edit the spec to change it.
- Sequences: Build sequence or Edit opens the full-screen builder. Restart atomically resets the latest persisted sequence to step 1, preserving its response list. A successful restart returns to the list.
Selecting actual network, a response or a failure saves the choice before closing the sheet. Browsing and inspection have no apply step and do not replace the configuration.
Response detail
The full-screen NetworkMockDestination.ResponseDetail(operation, statusCode, mediaType, exampleName) identifies one exact response variant. Compare with appears only when another variant exists. Valid JSON is pretty-printed for inspection; malformed JSON and non-JSON bodies remain unchanged. Text is selectable and Copy body copies the original body, not its display formatting.
Comparisons use an inline or side-by-side LCS diff, collapsing long unchanged runs. Logical lines stay unwrapped, with horizontal scrolling per pane and lazy vertical rows. Comparisons exceeding 1,000,000 LCS cells use stacked previews to bound memory. Light and dark diff colours follow the host surface luminance.
Use this response saves the variant and returns to the list; it becomes disabled In use when already selected. Back also returns to the list, without reopening the sheet. Inspection and copying do not change the served body or selection. A removed or unreadable variant shows an error with Reload instead of silently displaying another response.
Sequence builder
The full-screen NetworkMockDestination.SequenceBuilder(operation) owns an ordered draft. Pick at least two responses; repeated variants are allowed and the last step repeats. Existing sequences seed the draft once. Each occurrence has a stable identity, so Move up, Move down and Remove act on the intended step even when variants repeat.
Save sequence (n) is disabled below two steps, with an Add N more steps helper. Saving resets the position to step 1 and returns to the list. Cancel or Back discards unapplied edits and returns to the list. If a draft references a variant no longer available, editing and saving freeze until Reload resolves it; the draft is not silently truncated.
Saving and session lifetime
The registered module has one ordered mutation consumer shared by its list, sheet and detail entries. A pending save disables conflicting writes, navigation, dismissal and reload. A failed save retains its exact selection or draft and exposes Retry and Cancel. Retry repeats that command before later queued writes; Cancel abandons a failed command, not an already-running transaction. The screen closes only after its originating command succeeds, once.
Temporarily hiding the overlay and recreating the host for a configuration change retain pending writes, errors and entry drafts. Filtering a module out of DevView.modules returns to Home and discards its navigation entries and drafts, but does not unregister its mutation consumer. Removing its rememberModules registration ends that session. Process-death recovery of pending writes is not guaranteed.
Built-in screens and ViewModels are internal. Register NetworkMock with rememberModules and present DevView; its registered UI owns save recovery. Use the core configuration and state repositories for runtime integrations, not a standalone screen or ViewModel.
List search, filters and sort remain client-side saved UI state, separate from persisted mock settings. Request coordination and failure behaviour are described in NetworkMock Core and NetworkMock Ktor.
Theming
Status-family colors (2xx green, 4xx/5xx red, etc.) are a fixed, hand-tuned palette per
theme, not derived from MaterialTheme.colorScheme — see the
Theming guide for how to provide and
override them.
Registration
val modules = rememberModules {
module(NetworkMock(
resourceLoader = NetworkMockResourceLoader { path -> Res.readBytes(path) },
specPaths = listOf("files/networkmocks/specs/my-backend.json")
))
}
specPaths lists every OpenAPI spec file to load — one per API group. There is no default; pass every spec your app should mock.
Related Modules
- NetworkMock Core: Shared config and state.
- NetworkMock Ktor: Ktor client plugin.
- NetworkMock Workflows: Step-by-step integration guide.