Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/helm/helmtoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func HelmToSchema(valuesPath string) result.SchemaResult {

// the top level node is a document node. We need to go one layer
// deeper to get the actual yaml content
result.Diags = parseMapNode(sch, valuesDocument.Content[0], result.Diags)
if len(valuesDocument.Content) > 0 {
result.Diags = parseMapNode(sch, valuesDocument.Content[0], result.Diags)
}

return result
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/schema/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ func ExpandProperties(schema *Schema) *orderedmap.OrderedMap[string, *Schema] {
result = mergeProperties(result, allOf)
}

// dependencies
for _, item := range schema.Dependencies {
dep := ExpandProperties(item)
result = mergeProperties(result, dep)
// if dependencies is a map, we need to expand it
if dependentSchema, ok := schema.Dependencies.(map[string]*Schema); ok {
for _, item := range dependentSchema {
dep := ExpandProperties(item)
result = mergeProperties(result, dep)
}
}

return result
Expand Down
26 changes: 26 additions & 0 deletions pkg/schema/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ func (s *Schema) MarshalJSON() ([]byte, error) {
s.AdditionalPropertiesRaw = &addPropRaw
}

if s.Dependencies != nil {
dependenciesBytes, err := json.Marshal(s.Dependencies)
if err != nil {
return nil, err
}
dependenciesRaw := json.RawMessage(dependenciesBytes)
s.DependenciesRaw = &dependenciesRaw
}

type Alias Schema
return json.Marshal(&struct {
*Alias
Expand Down Expand Up @@ -52,5 +61,22 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
s.AdditionalPropertiesRaw = nil
}

if s.DependenciesRaw != nil {
var dependentRequired map[string][]string
err := json.Unmarshal(*s.DependenciesRaw, &dependentRequired)
if err != nil {
// dependencies is map, try to unmarshal as map[string]*Schema
var dependentSchema map[string]*Schema
err = json.Unmarshal(*s.DependenciesRaw, &dependentSchema)
if err != nil {
return err
}
s.Dependencies = dependentSchema
} else {
// dependencies is map[string][]string
s.Dependencies = dependentRequired
}
}

return nil
}
11 changes: 6 additions & 5 deletions pkg/schema/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ type Schema struct {
OneOf []*Schema `json:"oneOf,omitempty"` // section 10.2.1.3
Not *Schema `json:"not,omitempty"` // section 10.2.1.4
// RFC draft-bhutton-json-schema-00 section 10.2.2 (Apply sub-schemas conditionally)
If *Schema `json:"if,omitempty"` // section 10.2.2.1
Then *Schema `json:"then,omitempty"` // section 10.2.2.2
Else *Schema `json:"else,omitempty"` // section 10.2.2.3
Dependencies map[string]*Schema `json:"dependencies,omitempty"` // section 10.2.2.4
If *Schema `json:"if,omitempty"` // section 10.2.2.1
Then *Schema `json:"then,omitempty"` // section 10.2.2.2
Else *Schema `json:"else,omitempty"` // section 10.2.2.3
DependenciesRaw *json.RawMessage `json:"dependencies,omitempty"` // section 10.2.2.4
Dependencies any `json:"-"` // section 10.2.2.4
// RFC draft-bhutton-json-schema-00 section 10.3.1 (arrays)
PrefixItems []*Schema `json:"prefixItems,omitempty"` // section 10.3.1.1
Items *Schema `json:"items,omitempty"` // section 10.3.1.2 (replaces additionalItems)
Expand All @@ -36,7 +37,7 @@ type Schema struct {
Properties *orderedmap.OrderedMap[string, *Schema] `json:"properties,omitempty"`
PatternProperties map[string]*Schema `json:"patternProperties,omitempty"` // section 10.3.2.2
AdditionalPropertiesRaw *json.RawMessage `json:"additionalProperties,omitempty"` // section 10.3.2.3
AdditionalProperties interface{} `json:"-"`
AdditionalProperties any `json:"-"`
// AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // section 10.3.2.3
PropertyNames *Schema `json:"propertyNames,omitempty"` // section 10.3.2.4
// RFC draft-bhutton-json-schema-validation-00, section 6
Expand Down
Loading