Skip to content

Conversation

kevwan
Copy link
Contributor

@kevwan kevwan commented Oct 12, 2025

Description

Fixes #5229

The getFirstUsableString() function was only handling Go-quoted strings, causing all API summaries (from @doc text and handler names) to be lost in swagger output after the refactoring in commit cf21cb2.

Changes

  • Fix getFirstUsableString() to handle both quoted and unquoted strings
  • Add fallback to use value as-is when unquoting fails
  • Add 17 comprehensive unit tests covering all scenarios

Root Cause

The function tried to unquote plain strings like "Check server health status." using strconv.Unquote(), which expects Go-quoted strings like "\"Check server health status.\"". When unquoting failed, it returned an empty string.

Testing

  • ✅ All 17 new unit tests pass
  • ✅ All existing swagger tests pass
  • ✅ Verified swagger generation produces correct summaries
  • ✅ No regressions introduced

Before Fix

{
  "paths": {
    "/xz-server/health": {
      "get": {
        "summary": "",  // ❌ Empty!
        "operationId": "healthCheck"
      }
    }
  }
}

After Fix

{
  "paths": {
    "/xz-server/health": {
      "get": {
        "summary": "Check server health status.",  // ✅ Restored!
        "operationId": "healthCheck"
      }
    }
  }
}

The getFirstUsableString() function was only handling Go-quoted strings,
causing all API summaries (from @doc text and handler names) to be lost
in swagger output.

Changes:
- Fix getFirstUsableString() to handle both quoted and unquoted strings
- Add fallback to use value as-is when unquoting fails
- Add 17 comprehensive unit tests covering all scenarios

This restores API summaries that were removed after the refactoring in
commit cf21cb2.

Fixes: API summaries missing in swagger documentation
Related: zeromicro#5229
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kevwan kevwan merged commit bea9d15 into zeromicro:master Oct 12, 2025
6 checks passed
@kevwan kevwan deleted the fix/issue-5229 branch October 12, 2025 03:39
sososdk pushed a commit to sososdk/go-zero that referenced this pull request Oct 16, 2025
sososdk pushed a commit to sososdk/go-zero that referenced this pull request Oct 16, 2025
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 this pull request may close these issues.

goctl v1.9.1 makes many swagger properties lost

1 participant