Fix swagger generation: info block and server tags not included (#5215)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kevwan <1918356+kevwan@users.noreply.github.com>
This commit is contained in:
Copilot
2025-10-06 22:02:42 +08:00
committed by GitHub
parent 7a6c3c8129
commit 61e8894c31
2 changed files with 56 additions and 6 deletions

View File

@@ -18,8 +18,12 @@ func getBoolFromKVOrDefault(properties map[string]string, key string, def bool)
}
//I think this function and those below should handle error, but they didn't.
//Since a default value (def) is provided, any parsing errors will result in the default being returned.
str, err := strconv.Unquote(val[0])
if err != nil || len(str) == 0 {
str := val[0]
// Try to unquote if the string is quoted, otherwise use as-is
if unquoted, err := strconv.Unquote(str); err == nil {
str = unquoted
}
if len(str) == 0 {
return def
}
res, _ := strconv.ParseBool(str)
@@ -35,8 +39,12 @@ func getStringFromKVOrDefault(properties map[string]string, key string, def stri
if len(val) == 0 {
return def
}
str, err := strconv.Unquote(val[0])
if err != nil || len(str) == 0 {
str := val[0]
// Try to unquote if the string is quoted, otherwise use as-is
if unquoted, err := strconv.Unquote(str); err == nil {
str = unquoted
}
if len(str) == 0 {
return def
}
return str
@@ -52,8 +60,12 @@ func getListFromInfoOrDefault(properties map[string]string, key string, def []st
return def
}
str, err := strconv.Unquote(val[0])
if err != nil || len(str) == 0 {
str := val[0]
// Try to unquote if the string is quoted, otherwise use as-is
if unquoted, err := strconv.Unquote(str); err == nil {
str = unquoted
}
if len(str) == 0 {
return def
}
resp := util.FieldsAndTrimSpace(str, commaRune)

View File

@@ -21,6 +21,19 @@ func Test_getBoolFromKVOrDefault(t *testing.T) {
assert.False(t, getBoolFromKVOrDefault(properties, "empty_value", false))
assert.False(t, getBoolFromKVOrDefault(nil, "nil", false))
assert.False(t, getBoolFromKVOrDefault(map[string]string{}, "empty", false))
// Test with unquoted values (as stored by RawText())
unquotedProperties := map[string]string{
"enabled": "true",
"disabled": "false",
"invalid": "notabool",
"empty_value": "",
}
assert.True(t, getBoolFromKVOrDefault(unquotedProperties, "enabled", false))
assert.False(t, getBoolFromKVOrDefault(unquotedProperties, "disabled", true))
assert.False(t, getBoolFromKVOrDefault(unquotedProperties, "invalid", false))
assert.False(t, getBoolFromKVOrDefault(unquotedProperties, "empty_value", false))
}
func Test_getStringFromKVOrDefault(t *testing.T) {
@@ -34,6 +47,17 @@ func Test_getStringFromKVOrDefault(t *testing.T) {
assert.Equal(t, "default", getStringFromKVOrDefault(properties, "missing", "default"))
assert.Equal(t, "default", getStringFromKVOrDefault(nil, "nil", "default"))
assert.Equal(t, "default", getStringFromKVOrDefault(map[string]string{}, "empty", "default"))
// Test with unquoted values (as stored by RawText())
unquotedProperties := map[string]string{
"name": "example",
"title": "Demo API",
"empty": "",
}
assert.Equal(t, "example", getStringFromKVOrDefault(unquotedProperties, "name", "default"))
assert.Equal(t, "Demo API", getStringFromKVOrDefault(unquotedProperties, "title", "default"))
assert.Equal(t, "default", getStringFromKVOrDefault(unquotedProperties, "empty", "default"))
}
func Test_getListFromInfoOrDefault(t *testing.T) {
@@ -50,4 +74,18 @@ func Test_getListFromInfoOrDefault(t *testing.T) {
assert.Equal(t, []string{"default"}, getListFromInfoOrDefault(map[string]string{
"foo": ",,",
}, "foo", []string{"default"}))
// Test with unquoted values (as stored by RawText())
unquotedProperties := map[string]string{
"list": "a, b, c",
"schemes": "http,https",
"tags": "query",
"empty": "",
}
// Note: FieldsAndTrimSpace doesn't actually trim the spaces from returned values
assert.Equal(t, []string{"a", " b", " c"}, getListFromInfoOrDefault(unquotedProperties, "list", []string{"default"}))
assert.Equal(t, []string{"http", "https"}, getListFromInfoOrDefault(unquotedProperties, "schemes", []string{"default"}))
assert.Equal(t, []string{"query"}, getListFromInfoOrDefault(unquotedProperties, "tags", []string{"default"}))
assert.Equal(t, []string{"default"}, getListFromInfoOrDefault(unquotedProperties, "empty", []string{"default"}))
}