Skip to content

Commit

Permalink
added rupport for structuralconstraints checks for "required" and "ni…
Browse files Browse the repository at this point in the history
…l " in OneOf
  • Loading branch information
rushmash91 committed Jan 30, 2025
1 parent 26fe7c1 commit 77797c3
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions pkg/graph/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,38 @@ func getExpectedTypes(schema *spec.Schema) ([]string, error) {
}

// Handle OneOf schemas
if len(schema.OneOf) > 0 {
var types []string
for _, subType := range schema.OneOf {
types = append(types, subType.Type...)
}
return types, nil
}
if len(schema.OneOf) > 0 {
var types []string
hasStructuralConstraints := false

for _, subSchema := range schema.OneOf {
// Check for structural constraints
if len(subSchema.Required) > 0 || subSchema.Not != nil {
hasStructuralConstraints = true
}
// Collect types if present
if len(subSchema.Type) > 0 {
types = append(types, subSchema.Type...)
}
}

// If we found structural constraints, ensure "object" is included
if hasStructuralConstraints {
if !slices.Contains(types, "object") {
types = append(types, "object")
}
}

// If we found any types, return them
if len(types) > 0 {
return types, nil
}
// If no explicit types but we have structural constraints, return object
if hasStructuralConstraints {
return []string{"object"}, nil
}
}


// Handle AnyOf schemas
if len(schema.AnyOf) > 0 {
Expand Down

0 comments on commit 77797c3

Please sign in to comment.