Skip to content

fix(cli): unescape dollar-prefixed object keys in jsonExample#12521

Open
jsklan wants to merge 2 commits intomainfrom
devin/1771435653-fix-dollar-ref-key-escaping
Open

fix(cli): unescape dollar-prefixed object keys in jsonExample#12521
jsklan wants to merge 2 commits intomainfrom
devin/1771435653-fix-dollar-ref-key-escaping

Conversation

@jsklan
Copy link
Contributor

@jsklan jsklan commented Feb 18, 2026

Description

Refs: Reported by @jsklan

When an OpenAPI spec contains $ref (or any $-prefixed key) as a literal object key inside an example (not as a JSON reference), the Fern CLI correctly escapes it to \$ref in the Fern definition to avoid collision with the $ example reference prefix. However, when converting back from Fern definition → IR, the backslash was not stripped from object keys in the jsonExample field — only from string values. This caused downstream generators (e.g. Go) to emit invalid code like "\$ref".

Link to Devin run | Requested by: @jsklan

Changes Made

  • ExampleResolver.ts: Added key unescaping in resolveAllReferencesInExample when iterating object entries. Keys starting with \$ are stripped of the leading backslash, matching the existing unescaping logic already applied to string values (lines 45–49 in the same method).
  • versions.yml: Added changelog entry for CLI v3.79.3.

Testing

  • Unit tests added/updated — no tests were added; this is worth flagging
  • Manual review of the escaping/unescaping roundtrip logic

Human Review Checklist

  • Verify the new key unescaping mirrors the existing value unescaping pattern at lines 45–49 of the same method
  • Consider whether a test case should be added for $-prefixed keys roundtripping through OpenAPI → Fern def → IR
  • Note: there is a potential secondary issue where convertObject in convertExampleType.ts looks up typed properties by wire key — if the key is still \$ref at that point, it won't match a property named $ref. This is a separate concern not addressed here.

Open with Devin

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@github-actions
Copy link
Contributor

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments