diff --git a/internal/entitlement/httpdriver/parser.go b/internal/entitlement/httpdriver/parser.go index 29ee882e5..e81005a26 100644 --- a/internal/entitlement/httpdriver/parser.go +++ b/internal/entitlement/httpdriver/parser.go @@ -29,7 +29,7 @@ func (parser) ToMetered(e *entitlement.Entitlement) (*api.EntitlementMetered, er Id: &metered.ID, IsUnlimited: convert.ToPointer(false), // implement IssueAfterReset: metered.IssuesAfterReset, - Metadata: &metered.Metadata, + Metadata: convert.MapToPointer(metered.Metadata), SubjectKey: metered.SubjectKey, Type: api.EntitlementMeteredType(metered.EntitlementType), UpdatedAt: &metered.UpdatedAt, @@ -50,7 +50,7 @@ func (parser) ToStatic(e *entitlement.Entitlement) (*api.EntitlementStatic, erro DeletedAt: static.DeletedAt, FeatureId: static.FeatureID, Id: &static.ID, - Metadata: &static.Metadata, + Metadata: convert.MapToPointer(static.Metadata), SubjectKey: static.SubjectKey, Type: api.EntitlementStaticType(static.EntitlementType), UpdatedAt: &static.UpdatedAt, @@ -73,7 +73,7 @@ func (parser) ToBoolean(e *entitlement.Entitlement) (*api.EntitlementBoolean, er DeletedAt: boolean.DeletedAt, FeatureId: boolean.FeatureID, Id: &boolean.ID, - Metadata: &boolean.Metadata, + Metadata: convert.MapToPointer(boolean.Metadata), SubjectKey: boolean.SubjectKey, Type: api.EntitlementBooleanType(boolean.EntitlementType), UpdatedAt: &boolean.UpdatedAt, diff --git a/pkg/convert/ptr.go b/pkg/convert/ptr.go index d83419edd..3cc43929d 100644 --- a/pkg/convert/ptr.go +++ b/pkg/convert/ptr.go @@ -6,6 +6,13 @@ func ToPointer[T any](value T) *T { return &value } +func MapToPointer[T comparable, U any](value map[T]U) *map[T]U { + if len(value) == 0 { + return nil + } + return &value +} + func ToStringLike[Source, Dest ~string](value *Source) *Dest { if value == nil { return nil