Skip to content

SK-2679: Add typed context accessors for Conditional Data Access (Map support)#302

Open
samsternberg wants to merge 4 commits intomainfrom
feature/SK-2679-conditional-data-access-ctx-map-support-v2
Open

SK-2679: Add typed context accessors for Conditional Data Access (Map support)#302
samsternberg wants to merge 4 commits intomainfrom
feature/SK-2679-conditional-data-access-ctx-map-support-v2

Conversation

@samsternberg
Copy link
Copy Markdown
Collaborator

Summary

  • Adds getContext() (String), getContextAsObject(), and getContextAsMap() typed accessors to Credentials, replacing the untyped Object getContext() from SK-2777
  • Removes @SuppressWarnings("unchecked") from Utils.generateBearerToken by using the new typed accessors — cast safety is now enforced in Credentials next to the typed setContext overloads
  • Extends CredentialsTests to assert getContextAsObject() / getContextAsMap() behaviour

Replaces #293 (closed due to conflicts with SK-2777).

Test plan

  • mvn test passes locally
  • Existing map context tests (testValidMapContextInCredentials, testEmptyMapContextInCredentials, testInvalidMapKeyInContextCredentials, testMapContextWithNestedObjects, testMapContextWithMixedValueTypes) still pass
  • New assertions in testValidMapContextInCredentials verify typed accessor returns

🤖 Generated with Claude Code

- Add typed getContext() (String), getContextAsObject(), getContextAsMap()
  to Credentials; @SuppressWarnings scoped to Credentials where the
  invariant is guaranteed by the typed setContext overloads
- Remove unchecked cast and @SuppressWarnings from Utils.generateBearerToken
  by using the new typed accessors
- Assert getContextAsObject/getContextAsMap behaviour in CredentialsTests

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions
Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

- Extract validateCtxMapKeys() from validateCredentials into a public
  helper on Validations so builders can call it directly
- Add throws SkyflowException + validateCtxMapKeys() to setCtx(Map)
  in BearerToken and SignedDataTokens builders for early validation
- Add nested map, credentials-string, and invalid-key tests for both
  BearerToken and SignedDataTokens builders

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions
Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

…check

getContext() now returns String (null for Map), so validateCredentials
was silently skipping Map context validation. Switch to getContextAsObject()
to restore instanceof Map branching.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Gitleaks Findings: No secrets detected. Safe to proceed!

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

@github-actions
Copy link
Copy Markdown

Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions
Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

@samsternberg
Copy link
Copy Markdown
Collaborator Author

⚠️ Heads up on scope overlap with SK-2777

While rebasing this PR we discovered that SK-2777 (PR #301, "Update Fern client re-initialisation") already shipped the core Map context feature on main — even though SK-2777's ticket scope is purely about Fern client initialisation performance. Specifically, #301 landed:

  • setContext(Map<String, Object>) on Credentials
  • setCtx(Map<String, Object>) on BearerToken and SignedDataTokens builders
  • Map key validation inside validateCredentials
  • Error messages (InvalidContextType, InvalidContextMapKey), CONTEXT_KEY_REGEX constant
  • README docs, sample files, and existing Map context tests

What this PR (SK-2679) adds on top of that:

  • Typed accessors on Credentials: getContext() returns String (not Object), plus getContextAsObject() and getContextAsMap()
  • Early validation — setCtx(Map) on both builders now validates keys at call time, not just at validateCredentials
  • validateCtxMapKeys() extracted as a public helper on Validations so builders can call it
  • @SuppressWarnings removed from Utils.generateBearerToken via the new typed accessors
  • Additional tests covering nested maps, invalid key variants, and typed accessor behaviour

Action needed: Someone should confirm whether SK-2777 intentionally included the Map context changes or if they were accidentally bundled in. If intentional, SK-2679 can be scoped down to just the type-safety improvements in this PR. If accidental, the team should be aware that the feature is already live on main (as of the 2.0.4 release).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants