fix(cli): preserve example JSON key order in ledger publish#16672
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
fix(cli): preserve example JSON key order in ledger publish#16672devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Replace recursive stableStringify with JSON.stringify in the CLI's ledger publish path. The old stableStringify sorted ALL object keys at every nesting level, which reordered preformatted API example bodies (request/response JSON) alphabetically. Now only top-level manifest entry keys (apiDefinitionId) are sorted for deterministic hashing. Nested content — including API examples — preserves its original field order. Co-Authored-By: cbro <cbro@buildwithfern.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…bleStringify Rework the approach: instead of replacing stableStringify entirely, teach it to skip recursive key-sorting for subtrees rooted at known preformatted keys (requestBody, responseBody, payload, body). Uses a WeakSet to track which objects belong to a preformatted subtree so deeply nested keys are also preserved. This is CLI-only — no FDR changes needed. Co-Authored-By: cbro <cbro@buildwithfern.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes ledger publish reordering API example JSON fields alphabetically.
Changes Made
The CLI's
publishDocsLedger.tsusesstableStringifyto serialize the API manifest blob — this recursively sorts ALL object keys at every nesting level for deterministic hashing, including preformatted API example bodies (requestBody/responseBody).Before (broken): example
{ "name": "Monstera", "species": "...", "id": "..." }→{ "id": "...", "name": "Monstera", "species": "..." }After (fixed): example key order preserved as authored.
The fix teaches
stableStringifyto skip sorting for subtrees rooted at known preformatted keys:Uses a
WeakSetto track which objects belong to a preformatted subtree so deeply nested keys (e.g.care.waterinside aresponseBody) are also preserved. CLI-only change — no FDR changes needed.Preformatted keys cover all
z.unknown()example body fields in the fdr-sdk register contract:Endpoint examples:
requestBody,responseBodyWebhook examples:
payloadWebSocket message examples:
bodyAdded changelog entry
Testing
responseBodywhose keys are intentionally non-alphabetical; verifies both top-level and nested key order preserved@fern-api/remote-workspace-runnerpassLink to Devin session: https://app.devin.ai/sessions/b5df68c7e9ef4f629ca01c7a1f0aac15
Requested by: @broady