From 0647d8685dcfdb19550ac1db5348f3594514da43 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Tue, 22 Oct 2024 09:33:33 -0500 Subject: [PATCH 1/3] MissingPackageResult field in CheckPackageVersionUpdateInput made Nullable --- .../unreleased/Bugfix-20241022-093210.yaml | 3 + input.go | 68 +++++++++---------- new_input.go | 2 +- scalar.go | 2 +- service_test.go | 8 +-- 5 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 .changes/unreleased/Bugfix-20241022-093210.yaml diff --git a/.changes/unreleased/Bugfix-20241022-093210.yaml b/.changes/unreleased/Bugfix-20241022-093210.yaml new file mode 100644 index 00000000..fa544070 --- /dev/null +++ b/.changes/unreleased/Bugfix-20241022-093210.yaml @@ -0,0 +1,3 @@ +kind: Bugfix +body: 'BREAKING CHANGE: CheckPackageVersionUpdateInput changed to allow MissingPackageResult to be nullable' +time: 2024-10-22T09:32:10.794966-05:00 diff --git a/input.go b/input.go index 8c493dab..682716ee 100644 --- a/input.go +++ b/input.go @@ -254,39 +254,39 @@ type CheckManualUpdateInput struct { // CheckPackageVersionCreateInput represents information about the package version check to be created. type CheckPackageVersionCreateInput struct { - Name string `json:"name" yaml:"name" example:"example_name"` // The display name of the check. (Required.) - Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty" example:"false"` // Whether the check is enabled or not. (Optional.) - EnableOn *iso8601.Time `json:"enableOn,omitempty" yaml:"enableOn,omitempty" example:"2024-01-05T01:00:00.000Z"` // The date when the check will be automatically enabled. (Optional.) - CategoryId ID `json:"categoryId" yaml:"categoryId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the category the check belongs to. (Required.) - LevelId ID `json:"levelId" yaml:"levelId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the level the check belongs to. (Required.) - OwnerId *ID `json:"ownerId,omitempty" yaml:"ownerId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the team that owns the check. (Optional.) - FilterId *ID `json:"filterId,omitempty" yaml:"filterId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the filter of the check. (Optional.) - Notes *string `json:"notes,omitempty" yaml:"notes,omitempty" example:"example_notes"` // Additional information about the check. (Optional.) - PackageManager PackageManagerEnum `json:"packageManager" yaml:"packageManager" example:"NEW_ENUM_SET_DEFAULT"` // The package manager (ecosystem) this package relates to. (Required.) - PackageName string `json:"packageName" yaml:"packageName" example:"example_name"` // The name of the package to be checked. (Required.) - PackageNameIsRegex *bool `json:"packageNameIsRegex,omitempty" yaml:"packageNameIsRegex,omitempty" example:"false"` // Whether or not the value in the package name field is a regular expression. (Optional.) - PackageConstraint PackageConstraintEnum `json:"packageConstraint" yaml:"packageConstraint" example:"NEW_ENUM_SET_DEFAULT"` // The package constraint the service is to be checked for. (Required.) - MissingPackageResult *CheckResultStatusEnum `json:"missingPackageResult,omitempty" yaml:"missingPackageResult,omitempty" example:"NEW_ENUM_SET_DEFAULT"` // The check result if the package isn't being used by a service. (Optional.) - VersionConstraintPredicate *PredicateInput `json:"versionConstraintPredicate,omitempty" yaml:"versionConstraintPredicate,omitempty"` // The predicate that describes the version constraint the package must satisfy. (Optional.) + Name string `json:"name" yaml:"name" example:"example_name"` // The display name of the check. (Required.) + Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty" example:"false"` // Whether the check is enabled or not. (Optional.) + EnableOn *iso8601.Time `json:"enableOn,omitempty" yaml:"enableOn,omitempty" example:"2024-01-05T01:00:00.000Z"` // The date when the check will be automatically enabled. (Optional.) + CategoryId ID `json:"categoryId" yaml:"categoryId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the category the check belongs to. (Required.) + LevelId ID `json:"levelId" yaml:"levelId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the level the check belongs to. (Required.) + OwnerId *ID `json:"ownerId,omitempty" yaml:"ownerId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the team that owns the check. (Optional.) + FilterId *ID `json:"filterId,omitempty" yaml:"filterId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the filter of the check. (Optional.) + Notes *string `json:"notes,omitempty" yaml:"notes,omitempty" example:"example_notes"` // Additional information about the check. (Optional.) + PackageManager PackageManagerEnum `json:"packageManager" yaml:"packageManager" example:"golang"` // The package manager (ecosystem) this package relates to. (Required.) + PackageName string `json:"packageName" yaml:"packageName" example:"example_name"` // The name of the package to be checked. (Required.) + PackageNameIsRegex *bool `json:"packageNameIsRegex,omitempty" yaml:"packageNameIsRegex,omitempty" example:"false"` // Whether or not the value in the package name field is a regular expression. (Optional.) + PackageConstraint PackageConstraintEnum `json:"packageConstraint" yaml:"packageConstraint" example:"matches_version"` // The package constraint the service is to be checked for. (Required.) + MissingPackageResult *CheckResultStatusEnum `json:"missingPackageResult,omitempty" yaml:"missingPackageResult,omitempty" example:"passed"` // The check result if the package isn't being used by a service. (Optional.) + VersionConstraintPredicate *PredicateInput `json:"versionConstraintPredicate,omitempty" yaml:"versionConstraintPredicate,omitempty"` // The predicate that describes the version constraint the package must satisfy. (Optional.) } // CheckPackageVersionUpdateInput represents information about the package version check to be updated. type CheckPackageVersionUpdateInput struct { - Name *string `json:"name,omitempty" yaml:"name,omitempty" example:"example_name"` // The display name of the check. (Optional.) - CategoryId *ID `json:"categoryId,omitempty" yaml:"categoryId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the category the check belongs to. (Optional.) - LevelId *ID `json:"levelId,omitempty" yaml:"levelId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the level the check belongs to. (Optional.) - OwnerId *ID `json:"ownerId,omitempty" yaml:"ownerId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the owner of the check. (Optional.) - FilterId *ID `json:"filterId,omitempty" yaml:"filterId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the filter the check belongs to. (Optional.) - Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty" example:"false"` // Whether the check is enabled or not. (Optional.) - EnableOn *iso8601.Time `json:"enableOn,omitempty" yaml:"enableOn,omitempty" example:"2024-01-05T01:00:00.000Z"` // The date when the check will be automatically enabled. (Optional.) - Notes *string `json:"notes,omitempty" yaml:"notes,omitempty" example:"example_notes"` // Additional information about the check. (Optional.) - Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the check to be updated. (Required.) - PackageManager *PackageManagerEnum `json:"packageManager,omitempty" yaml:"packageManager,omitempty" example:"NEW_ENUM_SET_DEFAULT"` // The package manager (ecosystem) this package relates to. (Optional.) - PackageName *string `json:"packageName,omitempty" yaml:"packageName,omitempty" example:"example_name"` // The name of the package to be checked. (Optional.) - PackageNameIsRegex *bool `json:"packageNameIsRegex,omitempty" yaml:"packageNameIsRegex,omitempty" example:"false"` // Whether or not the value in the package name field is a regular expression. (Optional.) - PackageConstraint *PackageConstraintEnum `json:"packageConstraint,omitempty" yaml:"packageConstraint,omitempty" example:"NEW_ENUM_SET_DEFAULT"` // The package constraint the service is to be checked for. (Optional.) - MissingPackageResult *CheckResultStatusEnum `json:"missingPackageResult,omitempty" yaml:"missingPackageResult,omitempty" example:"NEW_ENUM_SET_DEFAULT"` // The check result if the package isn't being used by a service. (Optional.) - VersionConstraintPredicate *PredicateUpdateInput `json:"versionConstraintPredicate,omitempty" yaml:"versionConstraintPredicate,omitempty"` // The predicate that describes the version constraint the package must satisfy. (Optional.) + Name *string `json:"name,omitempty" yaml:"name,omitempty" example:"example_name"` // The display name of the check. (Optional.) + CategoryId *ID `json:"categoryId,omitempty" yaml:"categoryId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the category the check belongs to. (Optional.) + LevelId *ID `json:"levelId,omitempty" yaml:"levelId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the level the check belongs to. (Optional.) + OwnerId *ID `json:"ownerId,omitempty" yaml:"ownerId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the owner of the check. (Optional.) + FilterId *ID `json:"filterId,omitempty" yaml:"filterId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the filter the check belongs to. (Optional.) + Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty" example:"false"` // Whether the check is enabled or not. (Optional.) + EnableOn *iso8601.Time `json:"enableOn,omitempty" yaml:"enableOn,omitempty" example:"2024-01-05T01:00:00.000Z"` // The date when the check will be automatically enabled. (Optional.) + Notes *string `json:"notes,omitempty" yaml:"notes,omitempty" example:"example_notes"` // Additional information about the check. (Optional.) + Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the check to be updated. (Required.) + PackageManager *PackageManagerEnum `json:"packageManager,omitempty" yaml:"packageManager,omitempty" example:"docker"` // The package manager (ecosystem) this package relates to. (Optional.) + PackageName *string `json:"packageName,omitempty" yaml:"packageName,omitempty" example:"example_name"` // The name of the package to be checked. (Optional.) + PackageNameIsRegex *bool `json:"packageNameIsRegex,omitempty" yaml:"packageNameIsRegex,omitempty" example:"false"` // Whether or not the value in the package name field is a regular expression. (Optional.) + PackageConstraint *PackageConstraintEnum `json:"packageConstraint,omitempty" yaml:"packageConstraint,omitempty" example:"matches_version"` // The package constraint the service is to be checked for. (Optional.) + MissingPackageResult *Nullable[CheckResultStatusEnum] `json:"missingPackageResult,omitempty" yaml:"missingPackageResult,omitempty" example:"failed"` // The check result if the package isn't being used by a service. (Optional.) + VersionConstraintPredicate *PredicateUpdateInput `json:"versionConstraintPredicate,omitempty" yaml:"versionConstraintPredicate,omitempty"` // The predicate that describes the version constraint the package must satisfy. (Optional.) } // CheckRepositoryFileCreateInput specifies the input fields used to create a repo file check. @@ -837,11 +837,11 @@ type PredicateUpdateInput struct { // PropertyDefinitionInput represents the input for defining a property. type PropertyDefinitionInput struct { - Name *string `json:"name,omitempty" yaml:"name,omitempty" example:"example_name"` // The name of the property definition. (Optional.) - Schema *JSONSchema `json:"schema,omitempty" yaml:"schema,omitempty" example:""` // The schema of the property definition. (Optional.) - Description *string `json:"description,omitempty" yaml:"description,omitempty" example:"example_description"` // The description of the property definition. (Optional.) - PropertyDisplayStatus *PropertyDisplayStatusEnum `json:"propertyDisplayStatus,omitempty" yaml:"propertyDisplayStatus,omitempty" example:"NEW_ENUM_SET_DEFAULT"` // The display status of the custom property on service pages. (Optional.) - AllowedInConfigFiles *bool `json:"allowedInConfigFiles,omitempty" yaml:"allowedInConfigFiles,omitempty" example:"true"` // Whether or not the property is allowed to be set in opslevel.yml config files. (Optional.) + Name *string `json:"name,omitempty" yaml:"name,omitempty" example:"example_name"` // The name of the property definition. (Optional.) + Schema *JSONSchema `json:"schema,omitempty" yaml:"schema,omitempty" example:""` // The schema of the property definition. (Optional.) + Description *string `json:"description,omitempty" yaml:"description,omitempty" example:"example_description"` // The description of the property definition. (Optional.) + PropertyDisplayStatus *PropertyDisplayStatusEnum `json:"propertyDisplayStatus,omitempty" yaml:"propertyDisplayStatus,omitempty" example:"hidden"` // The display status of the custom property on service pages. (Optional.) + AllowedInConfigFiles *bool `json:"allowedInConfigFiles,omitempty" yaml:"allowedInConfigFiles,omitempty" example:"true"` // Whether or not the property is allowed to be set in opslevel.yml config files. (Optional.) } // PropertyInput represents the input for setting a property. diff --git a/new_input.go b/new_input.go index dbfa2ee7..d0ab7dd3 100644 --- a/new_input.go +++ b/new_input.go @@ -51,7 +51,7 @@ func NullableString(value *string) *Nullable[string] { return nil } if *value == "" { - return NewNull() + return NewNull[string]() } return NewNullableFrom(*value) } diff --git a/scalar.go b/scalar.go index a7a9377c..a170bc6b 100644 --- a/scalar.go +++ b/scalar.go @@ -78,7 +78,7 @@ func IsID(value string) bool { // NullableConstraint defines what types can be nullable - keep separated using the union operator (pipe) type NullableConstraint interface { - string + ~string } // Nullable can be used to unset a value using an OpsLevel input struct type, should always be instantiated using a constructor. diff --git a/service_test.go b/service_test.go index f808a720..c39df38d 100644 --- a/service_test.go +++ b/service_test.go @@ -351,10 +351,10 @@ func TestUpdateService(t *testing.T) { Input: ol.ServiceUpdateInputV2{ Parent: ol.NewIdentifier(), Id: ol.NewID("123456789"), - Description: ol.NewNull(), - Framework: ol.NewNull(), - TierAlias: ol.NewNull(), - LifecycleAlias: ol.NewNull(), + Description: ol.NewNull[string](), + Framework: ol.NewNull[string](), + TierAlias: ol.NewNull[string](), + LifecycleAlias: ol.NewNull[string](), }, }, { From bb37bb6c257eba98dc1d56bcf7d46564e73086ad Mon Sep 17 00:00:00 2001 From: David Bloss Date: Tue, 22 Oct 2024 10:28:18 -0500 Subject: [PATCH 2/3] add NewNullOf and revert NewNull behavior --- new_input.go | 2 +- scalar.go | 7 ++++++- service_test.go | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/new_input.go b/new_input.go index d0ab7dd3..dbfa2ee7 100644 --- a/new_input.go +++ b/new_input.go @@ -51,7 +51,7 @@ func NullableString(value *string) *Nullable[string] { return nil } if *value == "" { - return NewNull[string]() + return NewNull() } return NewNullableFrom(*value) } diff --git a/scalar.go b/scalar.go index a170bc6b..33e3eff7 100644 --- a/scalar.go +++ b/scalar.go @@ -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, } diff --git a/service_test.go b/service_test.go index c39df38d..f808a720 100644 --- a/service_test.go +++ b/service_test.go @@ -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(), }, }, { From 6b53a4326cf12b74bbe4036a2250a6de76c93cb8 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Tue, 22 Oct 2024 10:49:58 -0500 Subject: [PATCH 3/3] Update scalar.go better NewNullOf description Co-authored-by: Kyle --- scalar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalar.go b/scalar.go index 33e3eff7..b690ab21 100644 --- a/scalar.go +++ b/scalar.go @@ -99,7 +99,7 @@ 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 +// NewNullOf returns a Nullable of any type that fits NullableConstraint that will always marshal into `null`, can be used to unset fields func NewNullOf[T NullableConstraint]() *Nullable[T] { return &Nullable[T]{ SetNull: true,