Skip to content

resolution doesn't seem to handle $ref at the root #56

@buchanae

Description

@buchanae

Describe the bug
I think the jsonschema for the helm values in the cert-manager chart may demonstrate a bug with an edge case in resolution where the root object has a "$ref".

https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/values.schema.json

To Reproduce
Something like:

package main

import (
	"encoding/json"
	"os"

	"github.com/google/jsonschema-go/jsonschema"
)

func main() {
	schemaData, _ := os.ReadFile("values.schema.json")

	var schema jsonschema.Schema
	json.Unmarshal(schemaData, &schema)

	// This is the workaround I used:
	// if strings.HasPrefix(schema.Ref, "#/$defs/") {
	// 	key := strings.TrimPrefix(schema.Ref, "#/$defs/")
	// 	def, ok := schema.Defs[key]
	// 	if ok {
	// 		root := schema
	// 		schema = *def
	// 		schema.Defs = make(map[string]*jsonschema.Schema)
	// 		for k, v := range root.Defs {
	// 			if k != key {
	// 				schema.Defs[k] = v
	// 			}
	// 		}
	// 	}
	// }

	resolved, err := schema.Resolve(&jsonschema.ResolveOptions{})
	if err != nil {
		panic(err)
	}
	if resolved.Schema().Type != "object" {
		panic("bug")
	}
	println("ok")
}

That workaround only seemed to work at the root level. The child properties (e.g. root.properties.acmesolver) were still unresolved for some reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions