From 41a57e94864748a482cc7bb192c180273d87db25 Mon Sep 17 00:00:00 2001 From: Jacob Gonzalez Date: Tue, 17 Dec 2024 17:37:48 -0500 Subject: [PATCH 1/3] restore: @name parsing behavior --- types.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/types.go b/types.go index 5f3031e0b..64b63f096 100644 --- a/types.go +++ b/types.go @@ -48,6 +48,20 @@ func (t *TypeSpecDef) Name() string { func (t *TypeSpecDef) TypeName() string { if ignoreNameOverride(t.TypeSpec.Name.Name) { return t.TypeSpec.Name.Name[1:] + } else if t.TypeSpec.Comment != nil { + // get alias from comment '// @name ' + const regexCaseInsensitive = "(?i)" + reTypeName, err := regexp.Compile(regexCaseInsensitive + `^@name\s+(\S+)`) + if err != nil { + panic(err) + } + for _, comment := range t.TypeSpec.Comment.List { + trimmedComment := strings.TrimSpace(strings.TrimLeft(comment.Text, "/")) + texts := reTypeName.FindStringSubmatch(trimmedComment) + if len(texts) > 1 { + return texts[1] + } + } } var names []string From 03ee28dcdace4ffd5c690ed22bb0a5f8be532f4b Mon Sep 17 00:00:00 2001 From: njacob1001 Date: Thu, 19 Dec 2024 18:44:53 -0500 Subject: [PATCH 2/3] feat: add schema name if there is a recursion --- parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.go b/parser.go index 6d1644a88..7a0b59e64 100644 --- a/parser.go +++ b/parser.go @@ -1316,7 +1316,7 @@ func (parser *Parser) ParseDefinition(typeSpecDef *TypeSpecDef) (*Schema, error) parser.debug.Printf("Skipping '%s', recursion detected.", typeName) return &Schema{ - Name: typeName, + Name: typeSpecDef.SchemaName, PkgPath: typeSpecDef.PkgPath, Schema: PrimitiveSchema(OBJECT), }, From 925e5f2f11dde549fd41a13c006c45e6dbec8aa0 Mon Sep 17 00:00:00 2001 From: njacob1001 Date: Thu, 19 Dec 2024 18:45:26 -0500 Subject: [PATCH 3/3] restore: old logic --- types.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/types.go b/types.go index 64b63f096..5f3031e0b 100644 --- a/types.go +++ b/types.go @@ -48,20 +48,6 @@ func (t *TypeSpecDef) Name() string { func (t *TypeSpecDef) TypeName() string { if ignoreNameOverride(t.TypeSpec.Name.Name) { return t.TypeSpec.Name.Name[1:] - } else if t.TypeSpec.Comment != nil { - // get alias from comment '// @name ' - const regexCaseInsensitive = "(?i)" - reTypeName, err := regexp.Compile(regexCaseInsensitive + `^@name\s+(\S+)`) - if err != nil { - panic(err) - } - for _, comment := range t.TypeSpec.Comment.List { - trimmedComment := strings.TrimSpace(strings.TrimLeft(comment.Text, "/")) - texts := reTypeName.FindStringSubmatch(trimmedComment) - if len(texts) > 1 { - return texts[1] - } - } } var names []string