Skip to content

docs(ruby): generate valid Ruby in doc code samples - #1294

Merged
jablan merged 1 commit into
mainfrom
fix/ruby-doc-samples
Sep 23, 2026
Merged

jablan merged 1 commit into
mainfrom
fix/ruby-doc-samples

Conversation

@jablan

@jablan jablan commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

The code samples in the generated Ruby model docs aren't valid Ruby, e.g. ScreenshotUpdateParameters.md:

require 'Phrase'

instance = Phrase::ScreenshotUpdateParameters.new(branch: my-feature-branch,
                                 name: A screenshot name,
                                 description: A screenshot description,
                                 filename: [B@6eec5a54)

Across all model docs: require 'Phrase' instead of the gem name (246 docs), unquoted strings (335), null for missing examples (881), HTML-escaped arrays/hashes (["read",...], 92), and binary fields rendered as a per-run Java identity hash ([B@...). The latter also changes on every generation, causing no-op syncs to phrase-ruby. One API doc (UploadsApi.md) has { ... } placeholders for object params.

After:

require 'phrase'

instance = Phrase::ScreenshotUpdateParameters.new(branch: 'my-feature-branch',
                                 name: 'A screenshot name',
                                 description: 'A screenshot description',
                                 filename: File.new('/path/to/file'))

Changes

  • model_doc.mustache: require '{{gemName}}'; strings (incl. enums) quoted, timestamps as Time.parse('...'), binary fields as File.new('/path/to/file'), everything else via unescaped {{{example}}}.
  • Makefile: the generator renders a missing example as the literal string "null" (and object params as { ... } from its Java code), which mustache can't detect. A perl -pi step after generation rewrites those to nil / {} in clients/ruby/docs/*.md only.

Verification

  • Parsed every ```ruby block in the generated docs with Prism (static, nothing executed): all 543 snippets have no syntax errors, and every argument in the model samples is a literal.
  • Two generations from a clean worktree are byte-identical.
  • Diff against current phrase-ruby master: 243 files, all under docs/.
  • Confirmed no string example contains ', \ or a newline (would break single-quoting) and no real "null" string example exists in the spec.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

API changelog (oasdiff)

Doc-only edits (descriptions, examples) do not appear here.

No changes detected

Model doc samples were not valid Ruby: unquoted strings, `null` for
missing examples, HTML-escaped arrays/hashes, a per-run `[B@...` value
for binary fields, and `require 'Phrase'` instead of the gem name.
Object params in API doc samples rendered as `{ ... }`.

- model_doc.mustache: require the gem name, quote strings, wrap
  timestamps in Time.parse, use File.new for binary fields, and render
  examples unescaped.
- Makefile: mustache can't tell a missing example ("null") from a real
  one, so rewrite those to `nil` (and `{ ... }` to `{}`) after
  generation.

Verified by parsing all 543 generated Ruby snippets with Prism: no
syntax errors, and every model sample argument is a literal.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jablan
jablan merged commit 2200045 into main Sep 23, 2026
13 checks passed
@jablan
jablan deleted the fix/ruby-doc-samples branch September 23, 2026 14:21
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.

2 participants