Skip to content

fix: handle nullable discriminator fields in JWKS models#514

Merged
BinoyOza-okta merged 4 commits intomasterfrom
1127600
Mar 19, 2026
Merged

fix: handle nullable discriminator fields in JWKS models#514
BinoyOza-okta merged 4 commits intomasterfrom
1127600

Conversation

@BinoyOza-okta
Copy link
Contributor

Fix: Handle Nullable Discriminator Fields in JWKS Models

Summary

This PR fixes JWKS (JSON Web Key) deserialization failures when the Okta API returns null values for fields that were incorrectly marked as required in the OpenAPI specification. The fix is template-based to ensure it persists through SDK regeneration.

Problem

Customers reported that list_applications() would fail with:

ValueError: Failed to lookup data type from the field `use` in the input.

This occurred when JWKS keys in application credentials contained null values for fields like use, kid, or kty, which are common in real Okta API responses.

Solution

Template Changes (Permanent)

  1. openapi/templates/model_generic.mustache

    • Added null discriminator handling in from_dict() method
    • Returns base class instance when discriminator is null instead of raising ValueError
  2. openapi/api.yaml

    • Marked fields as nullable: true: created, lastUpdated, kty, alg, use, e, n
    • Removed these fields from required lists

Other Changes

  • Updated documentation with [nullable] tags

Files Changed

Templates (Permanent):

  • openapi/templates/model_generic.mustache
  • openapi/api.yaml

Generated Models (Auto-regenerated):

  • 30+ model files in okta/models/

Documentation:

  • docs/OAuth2ClientJsonSigningKeyResponse.md
  • docs/OAuth2ClientJsonWebKeyRsaResponse.md

Backward Compatibility

100% backward compatible

  • Existing code with non-null values continues to work
  • New code can now handle null values gracefully
  • No breaking changes

Usage Example

Before (Broken):

apps = await client.list_applications()
# ValueError: Failed to lookup data type from the field `use`

After (Fixed):

apps = await client.list_applications()
# Works correctly even when JWKS keys have null fields

Fixes deserialization failures when Okta API returns null values for
discriminator fields in JWKS (JSON Web Key) responses.

Changes:
- Updated OpenAPI spec to mark JWKS fields as nullable (created, lastUpdated, kty, alg, use, e, n)
- Added null discriminator handling in model_generic.mustache template
- Updated documentation to reflect nullable fields

All changes are template-based to survive SDK regeneration.

Resolves customer-reported issues where list_applications() failed with
"ValueError: Failed to lookup data type from the field `use`" when JWKS
keys contained null values.
aniket-okta

This comment was marked as outdated.

aniket-okta

This comment was marked as outdated.

Copy link

@aniket-okta aniket-okta left a comment

Choose a reason for hiding this comment

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

Checked out branch 1127600, ran 16/16 tests (9 unit + 7 integration) against the preview org. Three critical bugs confirmed — each with a failing test proving it. Fixes applied locally, all tests pass.

- Added e, n fields to OAuth2ClientJsonWebKeyRsaResponse __properties and from_dict()
- Added x, y, crv fields to OAuth2ClientJsonWebKeyECResponse __properties and from_dict()
- Marked crv as optional (nullable) per API specification (x, y remain required)
- Added null preservation for e, n, crv in to_dict() methods

This ensures RSA and EC JWKS keys properly serialize/deserialize all subclass-specific fields.
…was not necessary with respect to the scope of current requirements.
Copy link

@aniket-okta aniket-okta left a comment

Choose a reason for hiding this comment

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

Review pass 2 — branch re-tested at 0733553e after the two new commits.

Ran 29/29 unit tests (RSA, EC, discriminator, round-trip) + live-org integration against all 18 apps. All RSA e/n fields now correctly populated; EC x/y/crv round-trip clean. Two items remain open — see inline comments.

Copy link

@aniket-okta aniket-okta left a comment

Choose a reason for hiding this comment

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

Approved — verified at 35a3da45.

29/29 unit tests pass, live-org integration clean across all 18 apps. RSA e/n and EC x/y/crv correctly serialized. kty correctly back to required per API spec.

One follow-up: please commit the test files (test_jwks_models_comprehensive.py, test_model_contradictions.py) into tests/ so they run in CI.

@BinoyOza-okta BinoyOza-okta merged commit 07d41ae into master Mar 19, 2026
15 checks passed
@BinoyOza-okta BinoyOza-okta deleted the 1127600 branch March 19, 2026 20:49
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