invopop / invopop/jsonschema

got nil pointer when using costom JSONSchema func

Open
#84 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
952
Forks
136
PR merge metrics
No merged PRs in 30d

Description

`func (Coustom) JSONSchema() *jsonschema.Schema {
return &jsonschema.Schema{
Type:"string",
}
}`

I just add this func to my coustom struct, and got a nil pointer from here:

> github.com/invopop/jsonschema.(*Reflector).reflectCustomSchema(0x7f6855c136f8?, 0x7f687f7d8108?, {0xbe1478, 0xad3980})
/home/XXX/go/pkg/mod/github.com/invopop/jsonschema@v0.7.0/reflect.go:423 +0xb0
github.com/invopop/jsonschema.(*Reflector).reflectTypeToSchema(0xc00021fa58, 0xc00021f960?, {0xbe1478, 0xad3980})
/home/XXX/go/pkg/mod/github.com/invopop/jsonschema@v0.7.0/reflect.go:348 +0x89
github.com/invopop/jsonschema.(*Reflector).reflectTypeToSchemaWithID(0xc00021fa58, 0xbe1478?, {0xbe1478, 0xad3980})
/home/XXX/go/pkg/mod/github.com/invopop/jsonschema@v0.7.0/reflect.go:324 +0x2c
github.com/invopop/jsonschema.(*Reflector).ReflectFromType(0xc00021fa58, {0xbe1478, 0xad3980})
/home/XXX/go/pkg/mod/github.com/invopop/jsonschema@v0.7.0/reflect.go:244 +0xf3
github.com/invopop/jsonschema.(*Reflector).Reflect(0xb0?, {0xad3980?, 0xc0000c3340?})
/home/XXX/go/pkg/mod/github.com/invopop/jsonschema@v0.7.0/reflect.go:230 +0x4a

I tried `func (*Coustom) JSONSchema() *jsonschema.Schema` ,but still got the same error.

Did I make a mistake somewhere?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at reflect.go:423 in Reflector.reflectCustomSchema and reproduce the nil pointer with the Custom.JSONSchema implementation shown in the issue. Trace the call through reflectTypeToSchema and ReflectFromType; done means the custom schema can be reflected without a nil pointer and produces the requested string type.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.