Skip to content

Commit 07d41ae

Browse files
fix: handle nullable discriminator fields in JWKS models (#514)
* fix: handle nullable discriminator fields in JWKS models 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) - 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. * fix: add missing JWKS subclass fields to serialization - 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. * - Reverted the change of making kty as optional.
1 parent c0e9943 commit 07d41ae

7 files changed

+153
-59
lines changed

docs/OAuth2ClientJsonSigningKeyResponse.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ A [JSON Web Key (JWK)](https://tools.ietf.org/html/rfc7517) is a JSON representa
77
Name | Type | Description | Notes
88
------------ | ------------- | ------------- | -------------
99
**id** | **str** | The unique ID of the OAuth Client JSON Web Key | [readonly]
10-
**created** | **str** | Timestamp when the OAuth 2.0 client JSON Web Key was created | [readonly]
11-
**last_updated** | **str** | Timestamp when the OAuth 2.0 client JSON Web Key was updated | [readonly]
10+
**created** | **str** | Timestamp when the OAuth 2.0 client JSON Web Key was created | [optional] [readonly]
11+
**last_updated** | **str** | Timestamp when the OAuth 2.0 client JSON Web Key was updated | [optional] [readonly]
1212
**links** | [**OAuthClientSecretLinks**](OAuthClientSecretLinks.md) | | [optional]
1313
**kid** | **str** | Unique identifier of the JSON Web Key in the OAuth 2.0 client's JWKS | [optional]
1414
**status** | **str** | Status of the OAuth 2.0 client JSON Web Key | [optional]
1515
**kty** | **str** | Cryptographic algorithm family for the certificate's key pair |
16-
**alg** | **str** | Algorithm used in the key |
17-
**use** | **str** | Acceptable use of the JSON Web Key |
16+
**alg** | **str** | Algorithm used in the key | [optional]
17+
**use** | **str** | Acceptable use of the JSON Web Key | [optional]
1818

1919
## Example
2020

docs/OAuth2ClientJsonWebKeyECResponse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Name | Type | Description | Notes
88
------------ | ------------- | ------------- | -------------
99
**x** | **str** | The public x coordinate for the elliptic curve point |
1010
**y** | **str** | The public y coordinate for the elliptic curve point |
11-
**crv** | **str** | The cryptographic curve used with the key |
11+
**crv** | **str** | The cryptographic curve used with the key | [optional]
1212

1313
## Example
1414

docs/OAuth2ClientJsonWebKeyRsaResponse.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ An RSA signing key
66

77
Name | Type | Description | Notes
88
------------ | ------------- | ------------- | -------------
9-
**e** | **str** | RSA key value (exponent) for key binding |
10-
**n** | **str** | RSA key value (modulus) for key binding |
9+
**e** | **str** | RSA key value (exponent) for key binding | [optional]
10+
**n** | **str** | RSA key value (modulus) for key binding | [optional]
1111

1212
## Example
1313

okta/models/o_auth2_client_json_signing_key_response.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ class OAuth2ClientJsonSigningKeyResponse(BaseModel):
5151
""" # noqa: E501
5252

5353
id: StrictStr = Field(description="The unique ID of the OAuth Client JSON Web Key")
54-
created: StrictStr = Field(
55-
description="Timestamp when the OAuth 2.0 client JSON Web Key was created"
54+
created: Optional[StrictStr] = Field(
55+
default=None,
56+
description="Timestamp when the OAuth 2.0 client JSON Web Key was created",
5657
)
57-
last_updated: StrictStr = Field(
58+
last_updated: Optional[StrictStr] = Field(
59+
default=None,
5860
description="Timestamp when the OAuth 2.0 client JSON Web Key was updated",
5961
alias="lastUpdated",
6062
)
@@ -69,8 +71,12 @@ class OAuth2ClientJsonSigningKeyResponse(BaseModel):
6971
kty: StrictStr = Field(
7072
description="Cryptographic algorithm family for the certificate's key pair"
7173
)
72-
alg: StrictStr = Field(description="Algorithm used in the key")
73-
use: StrictStr = Field(description="Acceptable use of the JSON Web Key")
74+
alg: Optional[StrictStr] = Field(
75+
default=None, description="Algorithm used in the key"
76+
)
77+
use: Optional[StrictStr] = Field(
78+
default=None, description="Acceptable use of the JSON Web Key"
79+
)
7480
__properties: ClassVar[List[str]] = [
7581
"id",
7682
"created",
@@ -103,6 +109,9 @@ def kty_validate_enum(cls, value):
103109
@field_validator("use")
104110
def use_validate_enum(cls, value):
105111
"""Validates the enum"""
112+
if value is None:
113+
return value
114+
106115
if value not in set(["sig"]):
107116
raise ValueError("must be one of enum values ('sig')")
108117
return value
@@ -182,11 +191,31 @@ def to_dict(self) -> Dict[str, Any]:
182191
else:
183192
_dict["_links"] = self.links
184193

194+
# set to None if created (nullable) is None
195+
# and model_fields_set contains the field
196+
if self.created is None and "created" in self.model_fields_set:
197+
_dict["created"] = None
198+
199+
# set to None if last_updated (nullable) is None
200+
# and model_fields_set contains the field
201+
if self.last_updated is None and "last_updated" in self.model_fields_set:
202+
_dict["lastUpdated"] = None
203+
185204
# set to None if kid (nullable) is None
186205
# and model_fields_set contains the field
187206
if self.kid is None and "kid" in self.model_fields_set:
188207
_dict["kid"] = None
189208

209+
# set to None if alg (nullable) is None
210+
# and model_fields_set contains the field
211+
if self.alg is None and "alg" in self.model_fields_set:
212+
_dict["alg"] = None
213+
214+
# set to None if use (nullable) is None
215+
# and model_fields_set contains the field
216+
if self.use is None and "use" in self.model_fields_set:
217+
_dict["use"] = None
218+
190219
return _dict
191220

192221
@classmethod

okta/models/o_auth2_client_json_web_key_ec_response.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class OAuth2ClientJsonWebKeyECResponse(OAuth2ClientJsonSigningKeyResponse):
4848
y: StrictStr = Field(
4949
description="The public y coordinate for the elliptic curve point"
5050
)
51-
crv: StrictStr = Field(description="The cryptographic curve used with the key")
51+
crv: Optional[StrictStr] = Field(
52+
default=None, description="The cryptographic curve used with the key"
53+
)
5254
__properties: ClassVar[List[str]] = [
5355
"id",
5456
"created",
@@ -59,11 +61,17 @@ class OAuth2ClientJsonWebKeyECResponse(OAuth2ClientJsonSigningKeyResponse):
5961
"kty",
6062
"alg",
6163
"use",
64+
"x",
65+
"y",
66+
"crv",
6267
]
6368

6469
@field_validator("crv")
6570
def crv_validate_enum(cls, value):
6671
"""Validates the enum"""
72+
if value is None:
73+
return value
74+
6775
if value not in set(["P-256", "P-384", "P-521"]):
6876
raise ValueError("must be one of enum values ('P-256', 'P-384', 'P-521')")
6977
return value
@@ -112,11 +120,36 @@ def to_dict(self) -> Dict[str, Any]:
112120
else:
113121
_dict["_links"] = self.links
114122

123+
# set to None if created (nullable) is None
124+
# and model_fields_set contains the field
125+
if self.created is None and "created" in self.model_fields_set:
126+
_dict["created"] = None
127+
128+
# set to None if last_updated (nullable) is None
129+
# and model_fields_set contains the field
130+
if self.last_updated is None and "last_updated" in self.model_fields_set:
131+
_dict["lastUpdated"] = None
132+
115133
# set to None if kid (nullable) is None
116134
# and model_fields_set contains the field
117135
if self.kid is None and "kid" in self.model_fields_set:
118136
_dict["kid"] = None
119137

138+
# set to None if alg (nullable) is None
139+
# and model_fields_set contains the field
140+
if self.alg is None and "alg" in self.model_fields_set:
141+
_dict["alg"] = None
142+
143+
# set to None if use (nullable) is None
144+
# and model_fields_set contains the field
145+
if self.use is None and "use" in self.model_fields_set:
146+
_dict["use"] = None
147+
148+
# set to None if crv (nullable) is None
149+
# and model_fields_set contains the field
150+
if self.crv is None and "crv" in self.model_fields_set:
151+
_dict["crv"] = None
152+
120153
return _dict
121154

122155
@classmethod
@@ -143,6 +176,9 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
143176
"kty": obj.get("kty"),
144177
"alg": obj.get("alg"),
145178
"use": obj.get("use"),
179+
"x": obj.get("x"),
180+
"y": obj.get("y"),
181+
"crv": obj.get("crv"),
146182
}
147183
)
148184
return _obj

okta/models/o_auth2_client_json_web_key_rsa_response.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ class OAuth2ClientJsonWebKeyRsaResponse(OAuth2ClientJsonSigningKeyResponse):
4242
An RSA signing key
4343
""" # noqa: E501
4444

45-
e: StrictStr = Field(description="RSA key value (exponent) for key binding")
46-
n: StrictStr = Field(description="RSA key value (modulus) for key binding")
45+
e: Optional[StrictStr] = Field(
46+
default=None, description="RSA key value (exponent) for key binding"
47+
)
48+
n: Optional[StrictStr] = Field(
49+
default=None, description="RSA key value (modulus) for key binding"
50+
)
4751
__properties: ClassVar[List[str]] = [
4852
"id",
4953
"created",
@@ -54,6 +58,8 @@ class OAuth2ClientJsonWebKeyRsaResponse(OAuth2ClientJsonSigningKeyResponse):
5458
"kty",
5559
"alg",
5660
"use",
61+
"e",
62+
"n",
5763
]
5864

5965
model_config = ConfigDict(
@@ -100,11 +106,41 @@ def to_dict(self) -> Dict[str, Any]:
100106
else:
101107
_dict["_links"] = self.links
102108

109+
# set to None if created (nullable) is None
110+
# and model_fields_set contains the field
111+
if self.created is None and "created" in self.model_fields_set:
112+
_dict["created"] = None
113+
114+
# set to None if last_updated (nullable) is None
115+
# and model_fields_set contains the field
116+
if self.last_updated is None and "last_updated" in self.model_fields_set:
117+
_dict["lastUpdated"] = None
118+
103119
# set to None if kid (nullable) is None
104120
# and model_fields_set contains the field
105121
if self.kid is None and "kid" in self.model_fields_set:
106122
_dict["kid"] = None
107123

124+
# set to None if alg (nullable) is None
125+
# and model_fields_set contains the field
126+
if self.alg is None and "alg" in self.model_fields_set:
127+
_dict["alg"] = None
128+
129+
# set to None if use (nullable) is None
130+
# and model_fields_set contains the field
131+
if self.use is None and "use" in self.model_fields_set:
132+
_dict["use"] = None
133+
134+
# set to None if e (nullable) is None
135+
# and model_fields_set contains the field
136+
if self.e is None and "e" in self.model_fields_set:
137+
_dict["e"] = None
138+
139+
# set to None if n (nullable) is None
140+
# and model_fields_set contains the field
141+
if self.n is None and "n" in self.model_fields_set:
142+
_dict["n"] = None
143+
108144
return _dict
109145

110146
@classmethod
@@ -131,6 +167,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
131167
"kty": obj.get("kty"),
132168
"alg": obj.get("alg"),
133169
"use": obj.get("use"),
170+
"e": obj.get("e"),
171+
"n": obj.get("n"),
134172
}
135173
)
136174
return _obj

openapi/api.yaml

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -70314,13 +70314,13 @@ components:
7031470314
description: Timestamp when the OAuth 2.0 client JSON Web Key was created
7031570315
example: '2023-02-21T20:08:24.000Z'
7031670316
readOnly: true
70317-
nullable: false
70317+
nullable: true
7031870318
lastUpdated:
7031970319
type: string
7032070320
description: Timestamp when the OAuth 2.0 client JSON Web Key was updated
7032170321
example: '2023-02-21T20:08:24.000Z'
7032270322
readOnly: true
70323-
nullable: false
70323+
nullable: true
7032470324
_links:
7032570325
$ref: '#/components/schemas/OAuthClientSecretLinks'
7032670326
readOnly: true
@@ -70340,20 +70340,19 @@ components:
7034070340
type: string
7034170341
description: Cryptographic algorithm family for the certificate's key pair
7034270342
example: RSA
70343-
nullable: false
7034470343
enum:
7034570344
- RSA
7034670345
- EC
7034770346
alg:
7034870347
type: string
7034970348
description: Algorithm used in the key
7035070349
example: RS256
70351-
nullable: false
70350+
nullable: true
7035270351
use:
7035370352
type: string
7035470353
description: Acceptable use of the JSON Web Key
7035570354
example: sig
70356-
nullable: false
70355+
nullable: true
7035770356
enum:
7035870357
- sig
7035970358
discriminator:
@@ -70363,11 +70362,7 @@ components:
7036370362
EC: '#/components/schemas/OAuth2ClientJsonWebKeyECResponse'
7036470363
required:
7036570364
- id
70366-
- created
70367-
- lastUpdated
7036870365
- kty
70369-
- alg
70370-
- use
7037170366
OAuth2ClientJsonWebKeyECRequest:
7037270367
title: EC Signing Key
7037370368
description: An EC signing key
@@ -70409,26 +70404,25 @@ components:
7040970404
allOf:
7041070405
- $ref: '#/components/schemas/OAuth2ClientJsonSigningKeyResponse'
7041170406
- type: object
70412-
properties:
70413-
x:
70414-
type: string
70415-
description: The public x coordinate for the elliptic curve point
70416-
y:
70417-
type: string
70418-
description: The public y coordinate for the elliptic curve point
70419-
crv:
70420-
type: string
70421-
description: The cryptographic curve used with the key
70422-
example: P-256
70423-
nullable: false
70424-
enum:
70425-
- P-256
70426-
- P-384
70427-
- P-521
70428-
required:
70429-
- x
70430-
- y
70431-
- crv
70407+
properties:
70408+
x:
70409+
type: string
70410+
description: The public x coordinate for the elliptic curve point
70411+
y:
70412+
type: string
70413+
description: The public y coordinate for the elliptic curve point
70414+
crv:
70415+
type: string
70416+
description: The cryptographic curve used with the key
70417+
example: P-256
70418+
nullable: true
70419+
enum:
70420+
- P-256
70421+
- P-384
70422+
- P-521
70423+
required:
70424+
- x
70425+
- y
7043270426
OAuth2ClientJsonWebKeyRequestBase:
7043370427
type: object
7043470428
properties:
@@ -70543,21 +70537,18 @@ components:
7054370537
description: An RSA signing key
7054470538
allOf:
7054570539
- $ref: '#/components/schemas/OAuth2ClientJsonSigningKeyResponse'
70546-
type: object
70547-
properties:
70548-
e:
70549-
type: string
70550-
description: RSA key value (exponent) for key binding
70551-
example: AQAB
70552-
nullable: false
70553-
n:
70554-
type: string
70555-
description: RSA key value (modulus) for key binding
70556-
example: mkC6yAJVvFwUlmM9gKjb2d-YK5qHFt-mXSsbjWKKs4EfNm-BoQeeovBZtSACyaqLc8IYFTPEURFcbDQ9DkAL04uUIRD2gaHYY7uK0jsluEaXGq2RAIsmzAwNTzkiDw4q9pDL_q7n0f_SDt1TsMaMQayB6bU5jWsmqcWJ8MCRJ1aJMjZ16un5UVx51IIeCbe4QRDxEXGAvYNczsBoZxspDt28esSpq5W0dBFxcyGVudyl54Er3FzAguhgfMVjH-bUec9j2Tl40qDTktrYgYfxz9pfjm01Hl4WYP1YQxeETpSL7cQ5Ihz4jGDtHUEOcZ4GfJrPzrGpUrak8Qp5xcwCqQ
70557-
nullable: false
70558-
required:
70559-
- e
70560-
- n
70540+
- type: object
70541+
properties:
70542+
e:
70543+
type: string
70544+
description: RSA key value (exponent) for key binding
70545+
example: AQAB
70546+
nullable: true
70547+
n:
70548+
type: string
70549+
description: RSA key value (modulus) for key binding
70550+
example: mkC6yAJVvFwUlmM9gKjb2d-YK5qHFt-mXSsbjWKKs4EfNm-BoQeeovBZtSACyaqLc8IYFTPEURFcbDQ9DkAL04uUIRD2gaHYY7uK0jsluEaXGq2RAIsmzAwNTzkiDw4q9pDL_q7n0f_SDt1TsMaMQayB6bU5jWsmqcWJ8MCRJ1aJMjZ16un5UVx51IIeCbe4QRDxEXGAvYNczsBoZxspDt28esSpq5W0dBFxcyGVudyl54Er3FzAguhgfMVjH-bUec9j2Tl40qDTktrYgYfxz9pfjm01Hl4WYP1YQxeETpSL7cQ5Ihz4jGDtHUEOcZ4GfJrPzrGpUrak8Qp5xcwCqQ
70551+
nullable: true
7056170552
OAuth2ClientSecret:
7056270553
type: object
7056370554
properties:

0 commit comments

Comments
 (0)