From 28b929e0ad5cbd5558393e7e6948367d7a799ffa Mon Sep 17 00:00:00 2001 From: Jared O'Connell Date: Tue, 19 Mar 2024 00:18:50 -0400 Subject: [PATCH] Addressed review feedback --- schema/any.go | 2 +- schema/bool.go | 4 ++-- schema/enum.go | 2 +- schema/float.go | 2 +- schema/int.go | 2 +- schema/map.go | 1 + schema/oneof.go | 1 + schema/pattern.go | 2 +- schema/ref.go | 18 +++++++++--------- schema/schema_schema.go | 2 +- schema/scope_test.go | 15 +++++++++------ schema/string.go | 2 +- 12 files changed, 29 insertions(+), 24 deletions(-) diff --git a/schema/any.go b/schema/any.go index 90d5ee4..dcc34e0 100644 --- a/schema/any.go +++ b/schema/any.go @@ -92,7 +92,7 @@ func (a *AnySchema) ApplyScope(scope Scope, namespace string) { } func (a *AnySchema) ValidateReferences() error { - // Not applicable + // No references in this type. No work to do. return nil } diff --git a/schema/bool.go b/schema/bool.go index f6b0868..02303a7 100644 --- a/schema/bool.go +++ b/schema/bool.go @@ -125,8 +125,8 @@ func (b BoolSchema) ApplyScope(scope Scope, namespace string) { } -func (a BoolSchema) ValidateReferences() error { - // Not applicable +func (b BoolSchema) ValidateReferences() error { + // No references in this type. No work to do. return nil } diff --git a/schema/enum.go b/schema/enum.go index 6e129e3..b5dabbf 100644 --- a/schema/enum.go +++ b/schema/enum.go @@ -30,7 +30,7 @@ func (e EnumSchema[T]) ApplyScope(scope Scope, namespace string) { } func (e EnumSchema[T]) ValidateReferences() error { - // Not applicable + // No references in this type. No work to do. return nil } diff --git a/schema/float.go b/schema/float.go index 75298f2..79123e2 100644 --- a/schema/float.go +++ b/schema/float.go @@ -55,7 +55,7 @@ func (f FloatSchema) ApplyScope(scope Scope, namespace string) { } func (f FloatSchema) ValidateReferences() error { - // Not applicable + // No references in this type. No work to do. return nil } diff --git a/schema/int.go b/schema/int.go index 202d641..11f4829 100644 --- a/schema/int.go +++ b/schema/int.go @@ -39,7 +39,7 @@ func (i IntSchema) ApplyScope(scope Scope, namespace string) { } func (i IntSchema) ValidateReferences() error { - // Not applicable + // No references in this type. No work to do. return nil } diff --git a/schema/map.go b/schema/map.go index 8562a81..e49dd25 100644 --- a/schema/map.go +++ b/schema/map.go @@ -84,6 +84,7 @@ func (m MapSchema[K, V]) ApplyScope(scope Scope, namespace string) { m.KeysValue.ApplyScope(scope, namespace) m.ValuesValue.ApplyScope(scope, namespace) } + func (m MapSchema[K, V]) ValidateReferences() error { err := m.KeysValue.ValidateReferences() if err != nil { diff --git a/schema/oneof.go b/schema/oneof.go index 189450e..af941e8 100644 --- a/schema/oneof.go +++ b/schema/oneof.go @@ -53,6 +53,7 @@ func (o OneOfSchema[KeyType]) ApplyScope(scope Scope, namespace string) { panic(err) } } + func (o OneOfSchema[KeyType]) ValidateReferences() error { for _, t := range o.TypesValue { err := t.ValidateReferences() diff --git a/schema/pattern.go b/schema/pattern.go index 9e24b64..a997b47 100644 --- a/schema/pattern.go +++ b/schema/pattern.go @@ -29,7 +29,7 @@ func (p PatternSchema) ApplyScope(scope Scope, namespace string) { } func (p PatternSchema) ValidateReferences() error { - // Not applicable + // No references in this type. No work to do. return nil } diff --git a/schema/ref.go b/schema/ref.go index 98cb066..890b1f3 100644 --- a/schema/ref.go +++ b/schema/ref.go @@ -107,17 +107,17 @@ func (r *RefSchema) ApplyScope(scope Scope, namespace string) { } func (r *RefSchema) ValidateReferences() error { - if r.referencedObjectCache != nil { - return nil + if r.referencedObjectCache == nil { + return BadArgumentError{ + Message: fmt.Sprintf( + "Ref object reference could not find an object with ID %q in namespace %q", + r.IDValue, + r.ObjectNamespace, + ), + } } - return BadArgumentError{ - Message: fmt.Sprintf( - "Ref object reference could not find an object with ID %q in namespace %q", - r.IDValue, - r.ObjectNamespace, - ), - } + return nil } func (r *RefSchema) Unserialize(data any) (any, error) { diff --git a/schema/schema_schema.go b/schema/schema_schema.go index cba9fd1..66dabc9 100644 --- a/schema/schema_schema.go +++ b/schema/schema_schema.go @@ -843,7 +843,7 @@ var basicObjects = []*ObjectSchema{ nil, nil, nil, - PointerTo(""), + PointerTo(DEFAULT_NAMESPACE), nil, ), "display": displayProperty, diff --git a/schema/scope_test.go b/schema/scope_test.go index 6cddad3..a38e6bd 100644 --- a/schema/scope_test.go +++ b/schema/scope_test.go @@ -189,7 +189,7 @@ func TestUnserialization(t *testing.T) { assert.NoError(t, err) unserialized2, err := scopeTestObjectAType.Unserialize(serialized) assert.NoError(t, err) - // test reversiblity + // test reversibility assert.Equals(t, unserialized2, result) // Now as a ptr @@ -316,14 +316,15 @@ func TestSelfSerialization(t *testing.T) { //nolint:funlen func TestApplyingExternalNamespace(t *testing.T) { - // This test tests applying with scopes, properties, and objects, maps, and lists. - // It must be passed through all of those types. Validating this makes sure that - // it gets applied all the way down, and errors are propagated up. + // This test tests applying a scope to a schema that contains scopes, + // properties, objects, maps, and lists. + // The applied scope must be passed through all of those types, validating + // that the scope gets applied all the way down and that errors are propagated up. var testScope = schema.NewScopeSchema( schema.NewObjectSchema( "scopeTestObjectA", map[string]*schema.PropertySchema{ - "b": schema.NewPropertySchema( + "ref-b": schema.NewPropertySchema( schema.NewNamespacedRefSchema("scopeTestObjectB", "test-namespace", nil), nil, true, @@ -383,7 +384,9 @@ func TestApplyingExternalNamespace(t *testing.T) { ), ) // Not applied yet - assert.Error(t, testScope.ValidateReferences()) + err := testScope.ValidateReferences() + assert.Error(t, err) + assert.Contains(t, err.Error(), "could not find an object") testScope.ApplyScope(externalScope, "test-namespace") // Now it's applied, so the error should be resolved. assert.NoError(t, testScope.ValidateReferences()) diff --git a/schema/string.go b/schema/string.go index 28cd9bb..b7eb0f1 100644 --- a/schema/string.go +++ b/schema/string.go @@ -57,7 +57,7 @@ func (s StringSchema) ApplyScope(scope Scope, namespace string) { } func (s StringSchema) ValidateReferences() error { - // Not applicable + // No references in this type. No work to do. return nil }