-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Describe the bug
In Go, any slice attribute can store nil instead of an allocated value.
jsonschema-go/jsonschema/infer.go
Line 219 in 2196fed
| s.Type = "array" |
Here, it always sets the type as array, where I think it should be ["null","array"].
To Reproduce
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/google/jsonschema-go/jsonschema"
)
func main() {
schema, err := jsonschema.For[[]int64](&jsonschema.ForOptions{})
if err != nil {
fmt.Fprintf(os.Stderr, "failed to generate JSON schema: %v", err)
os.Exit(1)
}
encoded, err := json.Marshal(schema)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to encode JSON schema: %v", err)
os.Exit(1)
}
fmt.Println(string(encoded))
}Output:
{"type":"array","items":{"type":"integer"}}Expected behavior
All slices should allow the null type:
{"type":["null","array"],"items":{"type":"integer"}}Logs
Not required.
Additional context
No extra context required.
Metadata
Metadata
Assignees
Labels
No labels