resolution doesn't seem to handle $ref at the root
- Dominant language
- Go
- Stars
- 478
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
**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:
```go
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.
Contributor guide
Assessment
This issue has not been assessed yet.