Skip to content

goctl api swager: typeContainsTag bug #4898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jaronnie opened this issue May 26, 2025 · 0 comments · May be fixed by #4903
Open

goctl api swager: typeContainsTag bug #4898

jaronnie opened this issue May 26, 2025 · 0 comments · May be fixed by #4903

Comments

@jaronnie
Copy link
Contributor

func typeContainsTag(_ Context, structType apiSpec.DefineStruct, tag string) bool {
	for _, field := range structType.Members {
		tags, _ := apiSpec.Parse(field.Tag)
		for _, t := range tags.Tags() {
			if t.Key == tag {
				return true
			}
		}
	}
	return false
}

do not guess inline member.

Then I use:

func typeContainsTag(_ Context, structType apiSpec.DefineStruct, tag string) bool {
	return len(structType.GetTagMembers(tag)) > 0
}

Why Member is Inline always returns true

// IsTagMember returns true if contains given tag
func (m Member) IsTagMember(tagKey string) bool {
	if m.IsInline {
		return true
	}

	tags := m.Tags()
	for _, tag := range tags {
		if tag.Key == tagKey {
			return true
		}
	}
	return false
}

example request api type(POST):

type SetAutoInspectionRequest {
    AutoInspectSetting
}
type AutoInspectSetting {
    SwitchOn int    `form:"switchOn"` // 开关,0关闭 1开启
    Time     int    `form:"time"` // 时间
    Unit     string `form:"unit"` // 单位,可选:min、hour、day
}
@jaronnie jaronnie linked a pull request May 27, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant