Skip to content

SDKS-5184: Update sample app to showcase JSON config#212

Draft
vibhorgoswami wants to merge 1 commit into
developfrom
SDKS-5184
Draft

SDKS-5184: Update sample app to showcase JSON config#212
vibhorgoswami wants to merge 1 commit into
developfrom
SDKS-5184

Conversation

@vibhorgoswami

@vibhorgoswami vibhorgoswami commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

JIRA Ticket

SDKS-5184

Description

This PR provides an option to load json files of configuration.
image

Summary by CodeRabbit

  • New Features

    • Added three new configuration files to sample app for DaVinci, Journey, and OpenID authentication flows with customizable OIDC parameters
  • Refactor

    • Updated configuration loading system to dynamically discover and apply asset-based configuration presets
    • Improved configuration state management

@vibhorgoswami vibhorgoswami requested a review from spetrov June 19, 2026 22:59
@vibhorgoswami vibhorgoswami self-assigned this Jun 19, 2026
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Three new JSON asset configuration files (Journey, DaVinci, OpenID) are added to the sample app's assets directory. EnvViewModel is updated to scan and parse these asset files at init time via a new loadAssetConfigs() function, prepending results to Compose state-backed preset lists. All JSON serialization/deserialization is migrated from org.json to kotlinx.serialization.

Changes

Asset Preset Loading and JSON Migration

Layer / File(s) Summary
New JSON asset config files
samples/pingsampleapp/src/main/assets/DaVinciJsonConfig.json, samples/pingsampleapp/src/main/assets/journeyJsonConfig.json, samples/pingsampleapp/src/main/assets/openIdJsonConfig.json
Adds three asset config files covering DaVinci (OIDC-only), Journey (journey + OIDC), and OpenID (OIDC + explicit endpoints) flows, each with timeout, log level, and full connection/auth parameters.
AssetConfigType, AssetConfigs, loadAssetConfigs() + import migration
samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt
Introduces the AssetConfigType enum, AssetConfigs data class, and loadAssetConfigs() which enumerates assets/*.json, parses with kotlinx.serialization, and infers config type from JSON structure. Imports swap org.json for kotlinx.serialization.json.
Compose state preset lists and init wiring
samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt
Built-in preset lists become private; the four public preset properties are converted to mutableStateOf vars with private set. Init calls loadAssetConfigs() on IO and prepends results to each state list on Main.
DataStore JSON serialization migration
samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt
Custom-config save/restore for journey, OIDC, and device-auth DataStore entries is rewritten using buildJsonArray/buildJsonObject and Json.parseToJsonElement; parse failures return emptyList().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ForgeRock/ping-android-sdk#181: Directly related — also refactors EnvViewModel.kt preset/config state initialization and the SDK/preset flow in the same sample app.
  • ForgeRock/ping-android-sdk#203: Related — also modifies journey/DaVinci/Web config preset handling in EnvViewModel.kt, adding duplication actions that persist custom configs.

Suggested reviewers

  • spetrov
  • witrisna
  • rodrigoareis

Poem

🐇 Hopping through the assets with a JSON delight,
Three config files planted, each one perfectly right.
I swapped out org.json for kotlinx with glee,
Now presets load from files, as smooth as can be.
The Compose state lists shimmer, fresh data in tow —
This rabbit's proud codebase is putting on a show! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: updating a sample app to showcase JSON configuration functionality.
Description check ✅ Passed The description includes the required JIRA ticket link and provides a brief explanation of the change, though it could be more detailed about implementation specifics.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SDKS-5184

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt`:
- Around line 183-186: The userinfoEndpoint field is being parsed with an
incorrect JSON key name that has a capital I in "userInfoEndpoint", but the
actual key in the openIdJsonConfig.json file uses lowercase i as
"userinfoEndpoint". Change the JSON key parameter in the line assigning
userinfoEndpoint from "userInfoEndpoint" to "userinfoEndpoint" to match the
actual configuration file key and ensure the value is correctly populated
instead of defaulting to an empty string.
- Around line 135-137: The loadAssetConfigs() method opens file streams via
context.assets.open(fileName).bufferedReader() without closing them, causing
resource leaks in the loop. Wrap the bufferedReader().readText() call with the
Kotlin .use { } function to ensure the stream is automatically closed after
reading, preventing file descriptor leaks on each iteration of the loop.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4eb46e48-cd4a-4f03-9ff2-1f5dd43e1cba

📥 Commits

Reviewing files that changed from the base of the PR and between ed0f5d6 and 9cb0cc0.

📒 Files selected for processing (4)
  • samples/pingsampleapp/src/main/assets/DaVinciJsonConfig.json
  • samples/pingsampleapp/src/main/assets/journeyJsonConfig.json
  • samples/pingsampleapp/src/main/assets/openIdJsonConfig.json
  • samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt

Comment on lines +135 to +137
val root = Json.parseToJsonElement(
context.assets.open(fileName).bufferedReader().readText()
).jsonObject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt"

# Verify current asset read pattern and whether open() calls are wrapped in use {}
rg -n -C2 'assets\.open\(' "$FILE"
rg -n -C2 'bufferedReader\(\)\.readText\(\)' "$FILE"
rg -n -C2 '\.use\s*\{' "$FILE"

Repository: ForgeRock/ping-android-sdk

Length of output: 566


🏁 Script executed:

FILE="samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt"

# Check full function context around the problematic code
sed -n '120,160p' "$FILE"

Repository: ForgeRock/ping-android-sdk

Length of output: 1926


Close asset streams in loadAssetConfigs() loop.

The code at lines 135-137 opens a stream via context.assets.open(fileName).bufferedReader() but never closes it. In Kotlin, readText() does not auto-close the reader—each iteration of the loop leaks a file descriptor. Use .use { } to ensure closure.

Suggested fix
-            val root = Json.parseToJsonElement(
-                context.assets.open(fileName).bufferedReader().readText()
-            ).jsonObject
+            val root = context.assets.open(fileName).bufferedReader().use { reader ->
+                Json.parseToJsonElement(reader.readText()).jsonObject
+            }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt`
around lines 135 - 137, The loadAssetConfigs() method opens file streams via
context.assets.open(fileName).bufferedReader() without closing them, causing
resource leaks in the loop. Wrap the bufferedReader().readText() call with the
Kotlin .use { } function to ensure the stream is automatically closed after
reading, preventing file descriptor leaks on each iteration of the loop.

Comment on lines +183 to +186
authorizationEndpoint = openIdObj?.str("authorizationEndpoint") ?: "",
tokenEndpoint = openIdObj?.str("tokenEndpoint") ?: "",
userinfoEndpoint = openIdObj?.str("userInfoEndpoint") ?: "",
endSessionEndpoint = openIdObj?.str("endSessionEndpoint") ?: "",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Device-auth userinfoEndpoint is parsed with the wrong JSON key.

openIdJsonConfig.json uses userinfoEndpoint, but this parser reads userInfoEndpoint (capital I), so the value is always empty and the loaded device-auth preset is incomplete.

Suggested fix
-                    userinfoEndpoint = openIdObj?.str("userInfoEndpoint") ?: "",
+                    userinfoEndpoint = openIdObj?.str("userinfoEndpoint") ?: "",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/config/EnvViewModel.kt`
around lines 183 - 186, The userinfoEndpoint field is being parsed with an
incorrect JSON key name that has a capital I in "userInfoEndpoint", but the
actual key in the openIdJsonConfig.json file uses lowercase i as
"userinfoEndpoint". Change the JSON key parameter in the line assigning
userinfoEndpoint from "userInfoEndpoint" to "userinfoEndpoint" to match the
actual configuration file key and ensure the value is correctly populated
instead of defaulting to an empty string.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 26.05%. Comparing base (ed0f5d6) to head (9cb0cc0).

❗ There is a different number of reports uploaded between BASE (ed0f5d6) and HEAD (9cb0cc0). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (ed0f5d6) HEAD (9cb0cc0)
integration-tests 1 0
Additional details and impacted files
@@              Coverage Diff               @@
##             develop     #212       +/-   ##
==============================================
- Coverage      44.12%   26.05%   -18.08%     
+ Complexity      1393     1016      -377     
==============================================
  Files            316      309        -7     
  Lines           9756     9507      -249     
  Branches        1495     1429       -66     
==============================================
- Hits            4305     2477     -1828     
- Misses          4887     6749     +1862     
+ Partials         564      281      -283     
Flag Coverage Δ
integration-tests ?
unit-tests 26.05% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant