Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
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.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
17 changes: 17 additions & 0 deletions kinde/management_api/create_identity_response_helpers.go
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
}
99 changes: 99 additions & 0 deletions kinde/management_api/create_identity_response_test.go
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)
}
2 changes: 1 addition & 1 deletion kinde/management_api/generate.go
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
54 changes: 44 additions & 10 deletions kinde/management_api/oas_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 25 additions & 17 deletions kinde/management_api/oas_handlers_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading