diff --git a/jsonschema/oas3/defs_test.go b/jsonschema/oas3/defs_test.go index 28fb858..ffb1941 100644 --- a/jsonschema/oas3/defs_test.go +++ b/jsonschema/oas3/defs_test.go @@ -27,9 +27,9 @@ func TestSchema_Defs_Success(t *testing.T) { // Navigate to the user property which references #/$defs/User rootSchema := root.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - properties := rootSchema.GetLeft().GetProperties() + properties := rootSchema.GetSchema().GetProperties() require.NotNil(t, properties) userProperty, exists := properties.Get("user") @@ -44,10 +44,10 @@ func TestSchema_Defs_Success(t *testing.T) { // Get the resolved schema result := userProperty.GetResolvedSchema() require.NotNil(t, result) - assert.True(t, result.IsLeft()) + assert.True(t, result.IsSchema()) // Verify it's the User schema - resolvedSchema := result.GetLeft() + resolvedSchema := result.GetSchema() assert.Equal(t, []SchemaType{SchemaTypeObject}, resolvedSchema.GetType()) // Verify it has the expected properties @@ -56,13 +56,13 @@ func TestSchema_Defs_Success(t *testing.T) { nameProperty, exists := resolvedProperties.Get("name") require.True(t, exists) - assert.True(t, nameProperty.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeString}, nameProperty.GetLeft().GetType()) + assert.True(t, nameProperty.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeString}, nameProperty.GetSchema().GetType()) ageProperty, exists := resolvedProperties.Get("age") require.True(t, exists) - assert.True(t, ageProperty.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeInteger}, ageProperty.GetLeft().GetType()) + assert.True(t, ageProperty.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeInteger}, ageProperty.GetSchema().GetType()) }) t.Run("resolve chained references through $defs", func(t *testing.T) { @@ -78,9 +78,9 @@ func TestSchema_Defs_Success(t *testing.T) { // Navigate to the user property which references User, which itself references Address rootSchema := root.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - properties := rootSchema.GetLeft().GetProperties() + properties := rootSchema.GetSchema().GetProperties() require.NotNil(t, properties) userProperty, exists := properties.Get("user") @@ -95,10 +95,10 @@ func TestSchema_Defs_Success(t *testing.T) { // Get the resolved User schema userResult := userProperty.GetResolvedSchema() require.NotNil(t, userResult) - assert.True(t, userResult.IsLeft()) + assert.True(t, userResult.IsSchema()) // Verify the User schema has an address property that references Address - userSchema := userResult.GetLeft() + userSchema := userResult.GetSchema() userProperties := userSchema.GetProperties() require.NotNil(t, userProperties) @@ -123,9 +123,9 @@ func TestSchema_Defs_Success(t *testing.T) { // Navigate to the chainedRef property which references ChainedRef -> ChainedTarget rootSchema := root.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - properties := rootSchema.GetLeft().GetProperties() + properties := rootSchema.GetSchema().GetProperties() require.NotNil(t, properties) chainedProperty, exists := properties.Get("chainedRef") @@ -140,10 +140,10 @@ func TestSchema_Defs_Success(t *testing.T) { // Get the resolved schema - should be the final ChainedTarget result := chainedProperty.GetResolvedSchema() require.NotNil(t, result) - assert.True(t, result.IsLeft()) + assert.True(t, result.IsSchema()) // Verify it's the ChainedTarget schema - resolvedSchema := result.GetLeft() + resolvedSchema := result.GetSchema() assert.Equal(t, []SchemaType{SchemaTypeObject}, resolvedSchema.GetType()) // Verify it has the expected properties @@ -152,13 +152,13 @@ func TestSchema_Defs_Success(t *testing.T) { valueProperty, exists := resolvedProperties.Get("value") require.True(t, exists) - assert.True(t, valueProperty.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeString}, valueProperty.GetLeft().GetType()) + assert.True(t, valueProperty.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeString}, valueProperty.GetSchema().GetType()) descProperty, exists := resolvedProperties.Get("description") require.True(t, exists) - assert.True(t, descProperty.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeString}, descProperty.GetLeft().GetType()) + assert.True(t, descProperty.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeString}, descProperty.GetSchema().GetType()) }) t.Run("resolve reference from within nested schema with local $defs", func(t *testing.T) { @@ -174,16 +174,16 @@ func TestSchema_Defs_Success(t *testing.T) { // Navigate to the NestedSchema which has its own $defs rootSchema := root.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - nestedSchema, ok := rootSchema.GetLeft().GetDefs().Get("NestedSchema") + nestedSchema, ok := rootSchema.GetSchema().GetDefs().Get("NestedSchema") require.True(t, ok) nestedSchemaResolved := nestedSchema.MustGetResolvedSchema() - require.True(t, nestedSchemaResolved.IsLeft()) + require.True(t, nestedSchemaResolved.IsSchema()) // Get the localRef property which should reference the local $defs/LocalDef - properties := nestedSchemaResolved.GetLeft().GetProperties() + properties := nestedSchemaResolved.GetSchema().GetProperties() require.NotNil(t, properties) localRef, exists := properties.Get("localRef") @@ -199,10 +199,10 @@ func TestSchema_Defs_Success(t *testing.T) { // Get the resolved localRef schema localRefResolved := localRef.GetResolvedSchema() require.NotNil(t, localRefResolved) - require.True(t, localRefResolved.IsLeft()) + require.True(t, localRefResolved.IsSchema()) // Verify it's the LocalDef schema - resolvedSchema := localRefResolved.GetLeft() + resolvedSchema := localRefResolved.GetSchema() assert.Equal(t, []SchemaType{SchemaTypeObject}, resolvedSchema.GetType()) // Verify it has the expected properties @@ -211,8 +211,8 @@ func TestSchema_Defs_Success(t *testing.T) { localValueProperty, exists := resolvedProperties.Get("localValue") require.True(t, exists) - assert.True(t, localValueProperty.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeString}, localValueProperty.GetLeft().GetType()) + assert.True(t, localValueProperty.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeString}, localValueProperty.GetSchema().GetType()) }) t.Run("$defs getter method works correctly", func(t *testing.T) { @@ -222,26 +222,26 @@ func TestSchema_Defs_Success(t *testing.T) { require.NoError(t, err) // Get the $defs from the root schema - require.True(t, root.IsLeft()) - schema := root.GetLeft() + require.True(t, root.IsSchema()) + schema := root.GetSchema() defs := schema.GetDefs() require.NotNil(t, defs) // Verify we have the expected definitions userDef, exists := defs.Get("User") require.True(t, exists) - assert.True(t, userDef.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeObject}, userDef.GetLeft().GetType()) + assert.True(t, userDef.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeObject}, userDef.GetSchema().GetType()) addressDef, exists := defs.Get("Address") require.True(t, exists) - assert.True(t, addressDef.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeObject}, addressDef.GetLeft().GetType()) + assert.True(t, addressDef.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeObject}, addressDef.GetSchema().GetType()) nestedDef, exists := defs.Get("NestedSchema") require.True(t, exists) - assert.True(t, nestedDef.IsLeft()) - assert.Equal(t, []SchemaType{SchemaTypeObject}, nestedDef.GetLeft().GetType()) + assert.True(t, nestedDef.IsSchema()) + assert.Equal(t, []SchemaType{SchemaTypeObject}, nestedDef.GetSchema().GetType()) }) } @@ -261,9 +261,9 @@ func TestSchema_Defs_Error(t *testing.T) { // Navigate to the nonExistentRef property which references a non-existent definition rootSchema := root.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - properties := rootSchema.GetLeft().GetProperties() + properties := rootSchema.GetSchema().GetProperties() require.NotNil(t, properties) nonExistentProperty, exists := properties.Get("nonExistentRef") @@ -358,9 +358,9 @@ func TestSchema_ExternalDefs_Success(t *testing.T) { // Navigate to the externalUser property which references external $defs rootSchema := testSchema.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - properties := rootSchema.GetLeft().GetProperties() + properties := rootSchema.GetSchema().GetProperties() require.NotNil(t, properties) externalUserProperty, exists := properties.Get("externalUser") @@ -375,10 +375,10 @@ func TestSchema_ExternalDefs_Success(t *testing.T) { // Get the resolved schema result := externalUserProperty.GetResolvedSchema() require.NotNil(t, result, "resolved schema should not be nil") - assert.True(t, result.IsLeft(), "resolved schema should be a schema, not a reference") + assert.True(t, result.IsSchema(), "resolved schema should be a schema, not a reference") // Verify the resolved schema has the expected structure - resolvedSchema := result.GetLeft() + resolvedSchema := result.GetSchema() assert.Equal(t, []SchemaType{SchemaTypeObject}, resolvedSchema.GetType(), "resolved schema should be object type") resolvedProperties := resolvedSchema.GetProperties() @@ -387,13 +387,13 @@ func TestSchema_ExternalDefs_Success(t *testing.T) { // Verify ExternalUser properties idProperty, exists := resolvedProperties.Get("id") require.True(t, exists, "resolved schema should have id property") - assert.True(t, idProperty.IsLeft(), "id property should be a schema") - assert.Equal(t, []SchemaType{SchemaTypeInteger}, idProperty.GetLeft().GetType(), "id should be integer type") + assert.True(t, idProperty.IsSchema(), "id property should be a schema") + assert.Equal(t, []SchemaType{SchemaTypeInteger}, idProperty.GetSchema().GetType(), "id should be integer type") nameProperty, exists := resolvedProperties.Get("name") require.True(t, exists, "resolved schema should have name property") - assert.True(t, nameProperty.IsLeft(), "name property should be a schema") - assert.Equal(t, []SchemaType{SchemaTypeString}, nameProperty.GetLeft().GetType(), "name should be string type") + assert.True(t, nameProperty.IsSchema(), "name property should be a schema") + assert.Equal(t, []SchemaType{SchemaTypeString}, nameProperty.GetSchema().GetType(), "name should be string type") }) t.Run("resolve reference to non-existent external $defs", func(t *testing.T) { @@ -422,9 +422,9 @@ func TestSchema_ExternalDefs_Success(t *testing.T) { // Navigate to the nonExistentUser property which references non-existent external $defs rootSchema := testSchema.MustGetResolvedSchema() - require.True(t, rootSchema.IsLeft()) + require.True(t, rootSchema.IsSchema()) - properties := rootSchema.GetLeft().GetProperties() + properties := rootSchema.GetSchema().GetProperties() require.NotNil(t, properties) nonExistentProperty, exists := properties.Get("nonExistentUser") diff --git a/jsonschema/oas3/inline.go b/jsonschema/oas3/inline.go index fda1162..07b0724 100644 --- a/jsonschema/oas3/inline.go +++ b/jsonschema/oas3/inline.go @@ -293,7 +293,7 @@ func analyzeReferences(ctx context.Context, schema *JSONSchema[Referenceable], o return analyzeReferences(ctx, ConcreteToReferenceable(resolved), opts, refTracker, visited, counter) } - if resolved.IsRight() { + if resolved.IsBool() { return nil // Boolean schemas don't have references to analyze } @@ -302,7 +302,7 @@ func analyzeReferences(ctx context.Context, schema *JSONSchema[Referenceable], o currentFrame = visited[len(visited)-1] } - js := resolved.GetLeft() + js := resolved.GetSchema() // Analyze all nested schemas for _, schema := range js.AllOf { @@ -445,7 +445,7 @@ func inlineRecursive(ctx context.Context, schema *JSONSchema[Referenceable], opt // This is the second+ occurrence of a circular reference // Rewrite the reference if needed, then don't recurse if info.rewrittenRef != "" { - schema.GetLeft().Ref = pointer.From(references.Reference(info.rewrittenRef)) + schema.GetSchema().Ref = pointer.From(references.Reference(info.rewrittenRef)) rewrittenAbsRef := references.Reference(opts.ResolveOptions.TargetLocation + info.rewrittenRef) // Add reverse lookup for the rewritten reference if !refTracker.Has(rewrittenAbsRef.String()) { @@ -459,12 +459,12 @@ func inlineRecursive(ctx context.Context, schema *JSONSchema[Referenceable], opt } // If not preserve, this reference should be inlined - we'll process its content below } - if resolved.IsRight() { + if resolved.IsBool() { inlineSchemaInPlace(schema, resolved) return schema, nil } - js := resolved.GetLeft() + js := resolved.GetSchema() // Walk through allOf schemas for i, s := range js.AllOf { @@ -613,7 +613,7 @@ func inlineRecursive(ctx context.Context, schema *JSONSchema[Referenceable], opt inlineSchemaInPlace(schema, resolved) } else if info.rewrittenRef != "" { // This is a preserved reference - rewrite it to point to the new $defs location - schema.GetLeft().Ref = pointer.From(references.Reference(info.rewrittenRef)) + schema.GetSchema().Ref = pointer.From(references.Reference(info.rewrittenRef)) rewrittenAbsRef := references.Reference(opts.ResolveOptions.TargetLocation + info.rewrittenRef) // Add reverse lookup for the rewritten reference if !refTracker.Has(rewrittenAbsRef.String()) { @@ -662,11 +662,11 @@ func inlineSchemaInPlace(schema *JSONSchema[Referenceable], resolved *JSONSchema // removeUnusedDefs removes $defs that are no longer referenced after inlining func removeUnusedDefs(_ context.Context, schema *JSONSchema[Referenceable], refTracker *sequencedmap.Map[string, *refInfo]) { - if schema == nil || !schema.IsLeft() { + if schema == nil || !schema.IsSchema() { return } - schemaObj := schema.GetLeft() + schemaObj := schema.GetSchema() if schemaObj == nil || schemaObj.Defs == nil || schemaObj.Defs.Len() == 0 { return } @@ -802,11 +802,11 @@ func consolidateDefinitions(schema *JSONSchema[Referenceable], refTracker *seque } // Ensure we have a schema object (not a boolean schema) - if schema.IsRight() { + if schema.IsBool() { return errors.New("cannot add definitions to a boolean schema") } - js := schema.GetLeft() + js := schema.GetSchema() if js == nil { return errors.New("schema object is nil") } diff --git a/jsonschema/oas3/jsonschema.go b/jsonschema/oas3/jsonschema.go index 05db70e..5d55a54 100644 --- a/jsonschema/oas3/jsonschema.go +++ b/jsonschema/oas3/jsonschema.go @@ -79,8 +79,8 @@ func NewReferencedScheme(ctx context.Context, ref references.Reference, resolved referenceResolution = &references.ResolveResult[JSONSchema[Referenceable]]{ Object: &JSONSchema[Referenceable]{ EitherValue: values.EitherValue[Schema, core.Schema, bool, bool]{ - Left: resolvedSchema.GetLeft(), - Right: resolvedSchema.GetRight(), + Left: resolvedSchema.GetSchema(), + Right: resolvedSchema.GetBool(), }, }, } @@ -105,12 +105,53 @@ func NewReferencedScheme(ctx context.Context, ref references.Reference, resolved return js } +// IsSchema returns true if the JSONSchema is a schema object. +// Returns false if the JSONSchema is a boolean value. +// A convenience method equivalent to calling IsLeft(). +func (j *JSONSchema[T]) IsSchema() bool { + if j == nil { + return false + } + return j.IsLeft() +} + +// GetSchema returns the schema object if the JSONSchema is a schema object. +// Returns nil if the JSONSchema is a boolean value. +// A convenience method equivalent to calling GetLeft(). +func (j *JSONSchema[T]) GetSchema() *Schema { + if j == nil { + return nil + } + return j.GetLeft() +} + +// IsBool returns true if the JSONSchema is a boolean value. +// Returns false if the JSONSchema is a schema object. +// A convenience method equivalent to calling IsRight(). +func (j *JSONSchema[T]) IsBool() bool { + if j == nil { + return false + } + return j.IsRight() +} + +// GetBool returns the boolean value if the JSONSchema is a boolean value. +// Returns nil if the JSONSchema is a schema object. +// A convenience method equivalent to calling GetRight(). +func (j *JSONSchema[T]) GetBool() *bool { + if j == nil { + return nil + } + return j.GetRight() +} + +// GetExtensions returns the extensions object if the JSONSchema is a schema object or an empty extensions object if the JSONSchema is a boolean value. func (j *JSONSchema[Concrete]) GetExtensions() *extensions.Extensions { - if j == nil || j.IsRight() { + if j == nil || j.IsBool() { return extensions.New() } - return j.GetLeft().GetExtensions() + return j.GetSchema().GetExtensions() } // GetParent returns the immediate parent reference if this schema was resolved via a reference chain. @@ -186,20 +227,20 @@ func (j *JSONSchema[T]) IsEqual(other *JSONSchema[T]) bool { } // Validate validates the JSONSchema against the JSON Schema specification. -// This is a wrapper around calling GetLeft().Validate() for schema objects. +// This is a wrapper around calling GetSchema().Validate() for schema objects. func (j *JSONSchema[T]) Validate(ctx context.Context, opts ...validation.Option) []error { if j == nil { return []error{} } // If it's a boolean schema, no validation needed - if j.IsRight() { + if j.IsBool() { return []error{} } // If it's a schema object, validate it - if j.IsLeft() { - schema := j.GetLeft() + if j.IsSchema() { + schema := j.GetSchema() if schema != nil { // Convert opts to the expected validation options type // For now, we'll call without options since the Schema.Validate method @@ -243,11 +284,11 @@ func (j *JSONSchema[T]) ShallowCopy() *JSONSchema[T] { } // Shallow copy the EitherValue contents - if j.IsLeft() && j.GetLeft() != nil { - result.Left = j.GetLeft().ShallowCopy() + if j.IsSchema() && j.GetSchema() != nil { + result.Left = j.GetSchema().ShallowCopy() } - if j.IsRight() && j.GetRight() != nil { - rightVal := *j.GetRight() + if j.IsBool() && j.GetBool() != nil { + rightVal := *j.GetBool() result.Right = &rightVal } diff --git a/jsonschema/oas3/resolution.go b/jsonschema/oas3/resolution.go index 183e0f3..e3980fa 100644 --- a/jsonschema/oas3/resolution.go +++ b/jsonschema/oas3/resolution.go @@ -29,11 +29,11 @@ func (s *JSONSchema[Referenceable]) IsResolved() bool { // IsReference returns true if the JSONSchema is a reference, false otherwise func (j *JSONSchema[Referenceable]) IsReference() bool { - if j == nil || j.IsRight() { + if j == nil || j.IsBool() { return false } - return j.GetLeft().IsReference() + return j.GetSchema().IsReference() } // GetReference returns the reference of the JSONSchema if present, otherwise an empty string @@ -49,11 +49,11 @@ func (j *JSONSchema[Referenceable]) GetReference() references.Reference { // GetRef returns the reference of the JSONSchema if present, otherwise an empty string // This method is identical to GetReference() but was kept for backwards compatibility func (j *JSONSchema[Referenceable]) GetRef() references.Reference { - if j == nil || j.IsRight() { + if j == nil || j.IsBool() { return "" } - return j.GetLeft().GetRef() + return j.GetSchema().GetRef() } // GetAbsRef returns the absolute reference of the JSONSchema if present, otherwise an empty string @@ -292,7 +292,7 @@ func resolveJSONSchemaWithTracking(ctx context.Context, schema *JSONSchema[Refer return validationErrs, fmt.Errorf("unable to resolve reference: %s", schema.GetRef()) } - if obj.IsRight() { + if obj.IsBool() { return validationErrs, nil } diff --git a/jsonschema/oas3/resolution_external_ref_test.go b/jsonschema/oas3/resolution_external_ref_test.go index 50b50e6..1442f79 100644 --- a/jsonschema/oas3/resolution_external_ref_test.go +++ b/jsonschema/oas3/resolution_external_ref_test.go @@ -64,9 +64,9 @@ func TestJSONSchema_Resolve_ExternalWithInternalRefs(t *testing.T) { // Get the resolved schema result := schema.GetResolvedSchema() require.NotNil(t, result, "resolved schema should not be nil") - assert.True(t, result.IsLeft(), "should be a schema object") + assert.True(t, result.IsSchema(), "should be a schema object") - personSchema := result.GetLeft() + personSchema := result.GetSchema() require.NotNil(t, personSchema, "person schema should not be nil") // Check that Person has properties @@ -97,9 +97,9 @@ func TestJSONSchema_Resolve_ExternalWithInternalRefs(t *testing.T) { // Get the resolved address schema addressResolved := addressProp.GetResolvedSchema() require.NotNil(t, addressResolved, "resolved address schema should not be nil") - assert.True(t, addressResolved.IsLeft(), "address should be a schema object") + assert.True(t, addressResolved.IsSchema(), "address should be a schema object") - addressSchema := addressResolved.GetLeft() + addressSchema := addressResolved.GetSchema() require.NotNil(t, addressSchema, "address schema should not be nil") // Verify address has the expected properties @@ -115,8 +115,8 @@ func TestJSONSchema_Resolve_ExternalWithInternalRefs(t *testing.T) { t.Log("Address property is not a reference - it may have been inlined during resolution") // The reference may have been automatically resolved // Check if it's directly an object - assert.True(t, addressProp.IsLeft(), "address should be a schema object") - addressSchema := addressProp.GetLeft() + assert.True(t, addressProp.IsSchema(), "address should be a schema object") + addressSchema := addressProp.GetSchema() require.NotNil(t, addressSchema, "address schema should not be nil") } }) @@ -166,9 +166,9 @@ func TestJSONSchema_Resolve_ExternalWithInternalRefs(t *testing.T) { // Get the resolved schema result := schema.GetResolvedSchema() require.NotNil(t, result, "resolved schema should not be nil") - assert.True(t, result.IsLeft(), "should be a schema object") + assert.True(t, result.IsSchema(), "should be a schema object") - treeNodeSchema := result.GetLeft() + treeNodeSchema := result.GetSchema() require.NotNil(t, treeNodeSchema, "tree node schema should not be nil") // Check that TreeNode has properties @@ -181,8 +181,8 @@ func TestJSONSchema_Resolve_ExternalWithInternalRefs(t *testing.T) { require.NotNil(t, childrenProp, "children property should not be nil") // Check the items property of the array - assert.True(t, childrenProp.IsLeft(), "children should be a schema object") - childrenSchema := childrenProp.GetLeft() + assert.True(t, childrenProp.IsSchema(), "children should be a schema object") + childrenSchema := childrenProp.GetSchema() require.NotNil(t, childrenSchema, "children schema should not be nil") // Check that it's an array type schemaTypes := childrenSchema.GetType() diff --git a/jsonschema/oas3/resolution_test.go b/jsonschema/oas3/resolution_test.go index 83a3b5b..3498e7b 100644 --- a/jsonschema/oas3/resolution_test.go +++ b/jsonschema/oas3/resolution_test.go @@ -265,8 +265,8 @@ func TestJSONSchema_Resolve_RootDocument(t *testing.T) { require.NotNil(t, result) // Should return the JSONSchema wrapping the original schema // We can't do direct equality comparison due to cache side effects, so check the content - assert.True(t, result.IsLeft()) - assert.NotNil(t, result.GetLeft()) + assert.True(t, result.IsSchema()) + assert.NotNil(t, result.GetSchema()) }) t.Run("resolve JSON pointer against root document", func(t *testing.T) { @@ -290,10 +290,10 @@ func TestJSONSchema_Resolve_RootDocument(t *testing.T) { result := schema.GetResolvedSchema() require.NotNil(t, result) // Should contain the resolved JSONSchema - check if it has a Schema on the Left - assert.True(t, result.IsLeft()) + assert.True(t, result.IsSchema()) assert.NotNil(t, result.Left) // The resolved schema should be a string type property - schemaTypes := result.GetLeft().GetType() + schemaTypes := result.GetSchema().GetType() require.NotEmpty(t, schemaTypes) assert.Equal(t, SchemaTypeString, schemaTypes[0]) }) @@ -320,8 +320,8 @@ func TestJSONSchema_Resolve_RootDocument(t *testing.T) { // Should return the JSONSchema wrapping the original schema // We can't do direct equality comparison due to cache side effects, so check the content require.NotNil(t, result) - assert.True(t, result.IsLeft()) - assert.NotNil(t, result.GetLeft()) + assert.True(t, result.IsSchema()) + assert.NotNil(t, result.GetSchema()) }) } @@ -361,9 +361,9 @@ properties: result := schema.GetResolvedSchema() require.NotNil(t, result) // Should contain the resolved JSONSchema - check if it has a Schema on the Left - assert.True(t, result.IsLeft()) + assert.True(t, result.IsSchema()) assert.NotNil(t, result.Left) - assert.NotNil(t, result.GetLeft().Type) + assert.NotNil(t, result.GetSchema().Type) }) t.Run("resolve with JSON pointer in file path", func(t *testing.T) { @@ -575,9 +575,9 @@ func TestJSONSchema_Resolve(t *testing.T) { require.NotNil(t, result) // ResolveSchema returns a JSONSchema (EitherValue), so check if it has the expected schema on the left - assert.True(t, result.IsLeft()) - resolvedSchema := result.GetLeft() - originalSchema := schema.GetLeft() + assert.True(t, result.IsSchema()) + resolvedSchema := result.GetSchema() + originalSchema := schema.GetSchema() assert.Equal(t, originalSchema.Type, resolvedSchema.Type) }) @@ -977,8 +977,8 @@ func TestResolveSchema_ChainedReference_Success(t *testing.T) { // Verify the schema has the expected description from the final LocalChainedSchema // This tests that the local reference #/components/schemas/LocalChainedSchema // was resolved correctly within chained.yaml (not against main.yaml) - if resolved.IsLeft() { - schema := resolved.GetLeft() + if resolved.IsSchema() { + schema := resolved.GetSchema() assert.Equal(t, "Local chained schema", schema.GetDescription()) // Verify the schema has properties @@ -991,8 +991,8 @@ func TestResolveSchema_ChainedReference_Success(t *testing.T) { require.NotNil(t, nestedValue) // Verify the nested property structure (it should be a JSONSchema) - if nestedValue.IsLeft() { - nestedSchema := nestedValue.GetLeft() + if nestedValue.IsSchema() { + nestedSchema := nestedValue.GetSchema() assert.Equal(t, "A nested value in the chained schema", nestedSchema.GetDescription()) } } diff --git a/jsonschema/oas3/shallowcopy_test.go b/jsonschema/oas3/shallowcopy_test.go index 12c330e..1e7b8b9 100644 --- a/jsonschema/oas3/shallowcopy_test.go +++ b/jsonschema/oas3/shallowcopy_test.go @@ -30,7 +30,7 @@ func TestJSONSchema_ShallowCopy_Success(t *testing.T) { assert.True(t, original.IsEqual(copied), "original and copy should be equal initially") // Modify the copy by adding a new property - copied.GetLeft().Properties.Set("email", oas3.NewJSONSchemaFromSchema[oas3.Referenceable](&oas3.Schema{ + copied.GetSchema().Properties.Set("email", oas3.NewJSONSchemaFromSchema[oas3.Referenceable](&oas3.Schema{ Type: oas3.NewTypeFromString("string"), })) diff --git a/jsonschema/oas3/validation.go b/jsonschema/oas3/validation.go index 19465a7..475563c 100644 --- a/jsonschema/oas3/validation.go +++ b/jsonschema/oas3/validation.go @@ -49,8 +49,8 @@ func Validate[T Referenceable | Concrete](ctx context.Context, schema *JSONSchem return nil } - if schema.IsLeft() { - return schema.GetLeft().Validate(ctx, opts...) + if schema.IsSchema() { + return schema.GetSchema().Validate(ctx, opts...) } return nil diff --git a/jsonschema/oas3/walk.go b/jsonschema/oas3/walk.go index 4910c08..f2a9440 100644 --- a/jsonschema/oas3/walk.go +++ b/jsonschema/oas3/walk.go @@ -64,7 +64,7 @@ func walkSchema(ctx context.Context, schema *JSONSchema[Referenceable], loc walk return false } - if schema.IsLeft() { + if schema.IsSchema() { js := schema.Left // Walk through allOf schemas diff --git a/openapi/README.md b/openapi/README.md index 02fe989..3a084b6 100644 --- a/openapi/README.md +++ b/openapi/README.md @@ -109,8 +109,8 @@ if len(validationErrs) > 0 { } } -if schema.IsLeft() { - schemaObj := schema.GetLeft() +if schema.IsSchema() { + schemaObj := schema.GetSchema() fmt.Println("Schema Types:") for _, t := range schemaObj.GetType() { fmt.Printf(" %s\n", t) @@ -329,8 +329,8 @@ for item := range openapi.Walk(ctx, doc) { return nil }, Schema: func(schema *oas3.JSONSchema[oas3.Referenceable]) error { - if schema.IsLeft() && schema.GetLeft().Type != nil { - types := schema.GetLeft().GetType() + if schema.IsSchema() && schema.GetSchema().Type != nil { + types := schema.GetSchema().GetType() if len(types) > 0 { fmt.Printf("Found Schema of type: %s\n", types[0]) } @@ -637,8 +637,8 @@ doc := &openapi.OpenAPI{ if doc.Components != nil && doc.Components.Schemas != nil { for name, schema := range doc.Components.Schemas.All() { fmt.Printf("Found schema component: %s\n", name) - if schema.IsLeft() && schema.GetLeft().Type != nil { - types := schema.GetLeft().GetType() + if schema.IsSchema() && schema.GetSchema().Type != nil { + types := schema.GetSchema().GetType() if len(types) > 0 { fmt.Printf(" Type: %s\n", types[0]) } diff --git a/openapi/openapi_examples_test.go b/openapi/openapi_examples_test.go index f1b8fd4..59ab0e8 100644 --- a/openapi/openapi_examples_test.go +++ b/openapi/openapi_examples_test.go @@ -94,8 +94,8 @@ required: } // Access schema properties - if schema.IsLeft() { - schemaObj := schema.GetLeft() + if schema.IsSchema() { + schemaObj := schema.GetSchema() fmt.Println("Schema Types:") for _, t := range schemaObj.GetType() { fmt.Printf(" %s\n", t) @@ -392,8 +392,8 @@ func Example_walking() { return nil }, Schema: func(schema *oas3.JSONSchema[oas3.Referenceable]) error { - if schema.IsLeft() && schema.GetLeft().Type != nil { - types := schema.GetLeft().GetType() + if schema.IsSchema() && schema.GetSchema().Type != nil { + types := schema.GetSchema().GetType() if len(types) > 0 { fmt.Printf("Found Schema of type: %s\n", types[0]) } @@ -747,8 +747,8 @@ func Example_workingWithComponents() { if doc.Components != nil && doc.Components.Schemas != nil { for name, schema := range doc.Components.Schemas.All() { fmt.Printf("Found schema component: %s\n", name) - if schema.IsLeft() && schema.GetLeft().Type != nil { - types := schema.GetLeft().GetType() + if schema.IsSchema() && schema.GetSchema().Type != nil { + types := schema.GetSchema().GetType() if len(types) > 0 { fmt.Printf(" Type: %s\n", types[0]) }