From 6869cf77d7d15bffde37a2bcab6a43a721c4da12 Mon Sep 17 00:00:00 2001 From: James Palawaga Date: Wed, 6 Mar 2024 18:39:24 -0500 Subject: [PATCH] fix type reflection for repeated custom types --- reflect.go | 4 ++-- reflect_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/reflect.go b/reflect.go index 4bf90a3..f55cb7e 100644 --- a/reflect.go +++ b/reflect.go @@ -494,8 +494,8 @@ func (r *Reflector) reflect(i interface{}, rc *ReflectContext, keepType bool, pa isTextMarshaler := checkTextMarshaler(t, &schema) - if ref, ok := rc.definitionRefs[typeString]; ok && defName != "" { - return ref.Schema(), nil + if def, ok := rc.definitions[typeString]; ok && defName != "" { + return *def, nil } if rc.typeCycles[typeString] != nil && !rc.InlineRefs { diff --git a/reflect_test.go b/reflect_test.go index 4524f4e..26295a4 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -1932,7 +1932,8 @@ func (d *Discover) Enum() []interface{} { func TestReflector_Reflect_ptrDefault(t *testing.T) { type NewThing struct { - DiscoverMode *Discover `json:"discover,omitempty" default:"all"` + DiscoverMode *Discover `json:"discover,omitempty" default:"all"` + DiscoverMode2 *Discover `json:"discover2,omitempty" default:"none"` } r := jsonschema.Reflector{} @@ -1944,7 +1945,8 @@ func TestReflector_Reflect_ptrDefault(t *testing.T) { "JsonschemaGoTestDiscover":{"enum":["all","none"],"type":["null","string"]} }, "properties":{ - "discover":{"$ref":"#/definitions/JsonschemaGoTestDiscover","default":"all"} + "discover":{"$ref":"#/definitions/JsonschemaGoTestDiscover","default":"all"}, + "discover2":{"$ref":"#/definitions/JsonschemaGoTestDiscover","default":"none"} }, "type":"object" }`, s)