Skip to content

fix: preserve non-data payload keys in SuccessEnvelopeData - #2472

Open
dajiaohuang wants to merge 1 commit into
larksuite:mainfrom
dajiaohuang:fix/2428-api-non-data-payload
Open

fix: preserve non-data payload keys in SuccessEnvelopeData#2472
dajiaohuang wants to merge 1 commit into
larksuite:mainfrom
dajiaohuang:fix/2428-api-non-data-payload

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Aug 24, 2026

Copy link
Copy Markdown

Summary

When an API response uses a non-"data" key (e.g., /bot/v3/info returns payload under "bot"), the previous implementation discarded the payload and returned an empty object.

Root cause

internal/output/envelope_success.goSuccessEnvelopeData assumed every Lark API wraps its payload in data:

data, ok := m["data"]
if !ok || data == nil {
    return map[string]interface{}{}   // drops everything when payload is not under "data"
}

Fix

When data is absent or nil, fall back to the envelope minus the transport fields (code, msg, data) instead of an empty object. This preserves the JSON output contract (no code/msg leak into business data) and keeps existing tests green.

Testing

  • Existing tests TestSuccessEnvelopeData_MissingDataUsesEmptyObject and TestSuccessEnvelopeData_NilDataUsesEmptyObject still pass (fallback is empty when no other fields present)
  • Added regression test TestSuccessEnvelopeData_NonDataPayloadKeyPreserved

Example

Before:

$ lark-cli api --as bot GET /open-apis/bot/v3/info
{"ok": true, "identity": "bot", "data": {}}

After:

$ lark-cli api --as bot GET /open-apis/bot/v3/info
{"ok": true, "identity": "bot", "data": {"bot": {"activate_status": 2, "app_name": "...", "open_id": "ou_..."}}}

Fixes #2428

Summary by CodeRabbit

  • Bug Fixes
    • Fixed successful responses so business payloads remain available when no nested data field is provided.
    • Preserved response content under alternate fields while excluding protocol metadata.
  • Tests
    • Added regression coverage to verify payload preservation and removal of transport fields.

When an API response uses a non-"data" key (e.g., /bot/v3/info returns
payload under "bot"), the previous implementation discarded the payload
and returned an empty object. Fall back to the envelope minus transport
fields (code, msg, data) so the business payload is preserved.

Fixes larksuite#2428
@CLAassistant

CLAassistant commented Aug 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Aug 24, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 90003f8f-88d8-4db1-8b1b-17ff2495a411

📥 Commits

Reviewing files that changed from the base of the PR and between e0e90a4 and d0c54a3.

📒 Files selected for processing (2)
  • internal/output/envelope_success.go
  • internal/output/envelope_success_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

SuccessEnvelopeData now returns non-data business fields when the response lacks a usable data field. A regression test verifies that bot data is preserved while code and msg are excluded.

Changes

Success payload preservation

Layer / File(s) Summary
Fallback behavior and regression coverage
internal/output/envelope_success.go, internal/output/envelope_success_test.go
SuccessEnvelopeData returns non-transport envelope fields when data is absent or null. Tests verify that bot fields remain and code and msg are removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to d0c54

The change preserves payloads under non-data response keys while excluding transport fields; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the primary fix for preserving non-data payload keys.
Description check ✅ Passed The description explains the problem, root cause, fix, example, testing, and linked issue, although it omits the template headings and checklist format.
Linked Issues check ✅ Passed The implementation and regression test satisfy issue #2428 by preserving non-data payloads and excluding transport fields.
Out of Scope Changes check ✅ Passed The source change and regression test are directly related to the linked issue and PR objectives.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dajiaohuang
dajiaohuang force-pushed the fix/2428-api-non-data-payload branch from d0c54a3 to a825857 Compare August 24, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api command silently drops non-"data" response payloads (e.g. bot/v3/info returns empty data)

2 participants