Skip to content

Commit

Permalink
add NewNullOf and revert NewNull behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Oct 22, 2024
1 parent 0647d86 commit bb37bb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion new_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NullableString(value *string) *Nullable[string] {
return nil
}
if *value == "" {
return NewNull[string]()
return NewNull()
}
return NewNullableFrom(*value)
}
7 changes: 6 additions & 1 deletion scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ func (nullable Nullable[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(nullable.Value)
}

// NewNull returns a Nullable string that will always marshal into `null`, can be used to unset fields
func NewNull[T string]() *Nullable[T] {
return NewNullOf[T]()
}

// NewNull returns a Nullable that will always marshal into `null`, can be used to unset fields
func NewNull[T NullableConstraint]() *Nullable[T] {
func NewNullOf[T NullableConstraint]() *Nullable[T] {
return &Nullable[T]{
SetNull: true,
}
Expand Down
8 changes: 4 additions & 4 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ func TestUpdateService(t *testing.T) {
Input: ol.ServiceUpdateInputV2{
Parent: ol.NewIdentifier(),
Id: ol.NewID("123456789"),
Description: ol.NewNull[string](),
Framework: ol.NewNull[string](),
TierAlias: ol.NewNull[string](),
LifecycleAlias: ol.NewNull[string](),
Description: ol.NewNull(),
Framework: ol.NewNull(),
TierAlias: ol.NewNull(),
LifecycleAlias: ol.NewNull(),
},
},
{
Expand Down

0 comments on commit bb37bb6

Please sign in to comment.