From 3d5c076a4dd3c32aa66dc6b0789d38cd1cedb39c Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 4 Sep 2024 10:40:04 +0200 Subject: [PATCH] jsonTags[0] -> fieldName --- libs/jsonschema/from_type.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/jsonschema/from_type.go b/libs/jsonschema/from_type.go index 79cd8f1f6..d89fd5987 100644 --- a/libs/jsonschema/from_type.go +++ b/libs/jsonschema/from_type.go @@ -255,9 +255,10 @@ func (c *constructor) fromTypeStruct(typ reflect.Type) (Schema, error) { } jsonTags := strings.Split(structField.Tag.Get("json"), ",") + fieldName := jsonTags[0] // Do not include fields in the schema that will not be serialized during // JSON marshalling. - if jsonTags[0] == "" || jsonTags[0] == "-" || !structField.IsExported() { + if fieldName == "" || fieldName == "-" || !structField.IsExported() { continue } @@ -265,7 +266,7 @@ func (c *constructor) fromTypeStruct(typ reflect.Type) (Schema, error) { // required to be present in the API payload. Thus its absence in the // tags list indicates that the field is required. if !slices.Contains(jsonTags, "omitempty") { - res.Required = append(res.Required, jsonTags[0]) + res.Required = append(res.Required, fieldName) } // Walk the fields of the struct. @@ -278,7 +279,7 @@ func (c *constructor) fromTypeStruct(typ reflect.Type) (Schema, error) { // For every property in the struct, add a $ref to the corresponding // $defs block. refPath := path.Join("#/$defs", typPath) - res.Properties[jsonTags[0]] = &Schema{ + res.Properties[fieldName] = &Schema{ Reference: &refPath, } }