-
Notifications
You must be signed in to change notification settings - Fork 6
fix(management_api): CreateUserIdentity response decodes identity_id … #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
79c4599
fix(management_api): CreateUserIdentity response decodes identity_id …
BrandtKruger 2793ced
docs: document DeleteAPIApplicationScope breaking rename in CHANGELOG
BrandtKruger d6eedc5
docs: add Features section to CHANGELOG for CreateUserIdentity identi…
BrandtKruger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| <!-- Ideally, this should get auto-generated via tools like [auto-changelog](https://github.com/CookPete/auto-changelog). Eventually, this will get set up as part of the repository template. --> | ||
|
|
||
| ## Unreleased | ||
|
|
||
| ### Features | ||
|
|
||
| - **Management API (generated):** Added `EffectiveIdentityID()` helper method to `CreateIdentityResponseIdentity`. The decoder now handles both `id` and `identity_id` JSON keys when creating identities, accommodating the API's alternate field name for existing enterprise identities. | ||
|
|
||
| ### Breaking changes | ||
|
|
||
| - **Management API (generated):** Response types for the delete API application scope operation were renamed to fix a typo: `DeleteAPIAppliationScope*` → `DeleteAPIApplicationScope*` (e.g. `DeleteAPIAppliationScopeBadRequest` → `DeleteAPIApplicationScopeBadRequest`). If you reference the old type names in your code, update them to the new spelling. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package management_api | ||
|
|
||
| // EffectiveIdentityID returns the identity ID from the CreateIdentity response. | ||
| // The API may return "id" (normal case) or "identity_id" (when creating with existing enterprise identity). | ||
| // This helper returns whichever is set so callers get a single value. | ||
| func (s *CreateIdentityResponseIdentity) EffectiveIdentityID() (string, bool) { | ||
| if s == nil { | ||
| return "", false | ||
| } | ||
| if id, ok := s.ID.Get(); ok && id != "" { | ||
| return id, true | ||
| } | ||
| if id, ok := s.IdentityID.Get(); ok && id != "" { | ||
| return id, true | ||
| } | ||
| return "", false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package management_api | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/go-faster/jx" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestCreateIdentityResponse_Decode_WithId verifies that a response with "id" field decodes correctly. | ||
| func TestCreateIdentityResponse_Decode_WithId(t *testing.T) { | ||
| json := `{ | ||
| "message": "Identity created", | ||
| "code": "IDENTITY_CREATED", | ||
| "identity": { | ||
| "id": "idl_abc123" | ||
| } | ||
| }` | ||
|
|
||
| d := jx.DecodeBytes([]byte(json)) | ||
| var response CreateIdentityResponse | ||
|
|
||
| err := response.Decode(d) | ||
| require.NoError(t, err) | ||
|
|
||
| require.True(t, response.Identity.IsSet(), "Identity should be set") | ||
| identity, _ := response.Identity.Get() | ||
| assert.True(t, identity.ID.IsSet(), "Identity ID should be set") | ||
| id, ok := identity.ID.Get() | ||
| require.True(t, ok) | ||
| assert.Equal(t, "idl_abc123", id) | ||
|
|
||
| effectiveID, ok := identity.EffectiveIdentityID() | ||
| require.True(t, ok) | ||
| assert.Equal(t, "idl_abc123", effectiveID) | ||
| } | ||
|
|
||
| // TestCreateIdentityResponse_Decode_WithIdentityId verifies the bug fix: when the API returns | ||
| // "identity_id" (e.g. for existing enterprise identity), the identity is decoded and EffectiveIdentityID works. | ||
| func TestCreateIdentityResponse_Decode_WithIdentityId(t *testing.T) { | ||
| json := `{ | ||
| "message": "Identity created", | ||
| "code": "IDENTITY_CREATED", | ||
| "identity": { | ||
| "identity_id": "idl_existing_enterprise_123" | ||
| } | ||
| }` | ||
|
|
||
| d := jx.DecodeBytes([]byte(json)) | ||
| var response CreateIdentityResponse | ||
|
|
||
| err := response.Decode(d) | ||
| require.NoError(t, err) | ||
|
|
||
| require.True(t, response.Identity.IsSet(), "Identity should be set") | ||
| identity, _ := response.Identity.Get() | ||
| assert.True(t, identity.IdentityID.IsSet(), "IdentityID should be set (from identity_id field)") | ||
| id, ok := identity.IdentityID.Get() | ||
| require.True(t, ok) | ||
| assert.Equal(t, "idl_existing_enterprise_123", id) | ||
|
|
||
| effectiveID, ok := identity.EffectiveIdentityID() | ||
| require.True(t, ok, "EffectiveIdentityID should return the identity_id value") | ||
| assert.Equal(t, "idl_existing_enterprise_123", effectiveID) | ||
| } | ||
|
|
||
| // TestCreateIdentityResponseIdentity_Decode_IdentityIdField verifies the identity object | ||
| // decoder accepts "identity_id" and populates IdentityID. | ||
| func TestCreateIdentityResponseIdentity_Decode_IdentityIdField(t *testing.T) { | ||
| json := `{"identity_id": "idl_xyz789"}` | ||
|
|
||
| d := jx.DecodeBytes([]byte(json)) | ||
| var identity CreateIdentityResponseIdentity | ||
|
|
||
| err := identity.Decode(d) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.True(t, identity.IdentityID.IsSet(), "IdentityID should be set from identity_id field") | ||
| id, ok := identity.IdentityID.Get() | ||
| require.True(t, ok) | ||
| assert.Equal(t, "idl_xyz789", id) | ||
|
|
||
| effectiveID, ok := identity.EffectiveIdentityID() | ||
| require.True(t, ok) | ||
| assert.Equal(t, "idl_xyz789", effectiveID) | ||
| } | ||
|
|
||
| // TestCreateIdentityResponseIdentity_EffectiveIdentityID_prefers_id verifies EffectiveIdentityID | ||
| // returns ID when both ID and IdentityID are set (e.g. spec allows both). | ||
| func TestCreateIdentityResponseIdentity_EffectiveIdentityID_prefers_id(t *testing.T) { | ||
| identity := CreateIdentityResponseIdentity{} | ||
| identity.SetID(NewOptString("idl_primary")) | ||
| identity.SetIdentityID(NewOptString("idl_secondary")) | ||
|
|
||
| effectiveID, ok := identity.EffectiveIdentityID() | ||
| require.True(t, ok) | ||
| assert.Equal(t, "idl_primary", effectiveID) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package management_api | ||
|
|
||
| //go:generate go run github.com/ogen-go/ogen/cmd/ogen --target . -package management_api --clean https://api-spec.kinde.com/kinde-management-api-spec.yaml | ||
| //go:generate go run github.com/ogen-go/ogen/cmd/ogen --target . -package management_api --clean spec/kinde-management-api-spec.yaml | ||
| //go:generate go run fix_optstring.go |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.