Skip to content

Extract code examples to generated documentation files - #1350

Merged
TimothyJones merged 1 commit into
mainfrom
claude/cross-language-doc-examples-tqsadm
Jul 17, 2026
Merged

Extract code examples to generated documentation files#1350
TimothyJones merged 1 commit into
mainfrom
claude/cross-language-doc-examples-tqsadm

Conversation

@TimothyJones

Copy link
Copy Markdown
Member

Summary

This PR refactors documentation examples by extracting code snippets from test files into separate generated markdown files. This allows the same code examples to be reused across multiple documentation pages while maintaining a single source of truth.

Key Changes

  • New test files with extractable examples: Added documentation test files for both TypeScript/Jest and Java that contain code examples marked with example-extract and ignore-extract comments:

    • defining-a-server-contract.spec-norun.ts - HTTP server contract examples
    • defining-a-function-contract.spec-norun.ts - Function caller examples
    • defining-a-function-contract-throwing.spec-norun.ts - Throwing function examples
    • receiving-function-calls.spec-norun.ts - Function receiver examples
    • receiving-function-calls-throwing.spec-norun.ts - Throwing function receiver examples
    • registering-functions.spec-norun.ts - Function registration examples
    • verifying-with-triggers.spec-norun.ts - Verification trigger examples
    • Corresponding Java documentation test files in dsl-java/src/test/java/
  • Generated example markdown files: Created .mdx files in packages/documentation/docs/examples/generated/ for each extracted code example:

    • _http-server-config.ts.mdx and .java.mdx
    • _http-server-state-handlers.ts.mdx and .java.mdx
    • _http-server-interactions.ts.mdx and .java.mdx
    • _function-caller-define.ts.mdx and .java.mdx
    • _function-caller-throwing.ts.mdx and .java.mdx
    • _function-receiver-define.ts.mdx and .java.mdx
    • _function-receiver-throwing.ts.mdx and .java.mdx
    • _function-receiver-marshaller.java.mdx
    • _verify-trigger-groups.ts.mdx and .java.mdx
    • _verify-trigger-state-variables.ts.mdx and .java.mdx
    • _verify-register-functions.ts.mdx and .java.mdx
    • _verify-register-marshaller.java.mdx
  • Updated documentation pages: Modified documentation files to import and display the generated examples using Tabs components for language selection:

    • defining-contracts/http-server/defining-example.mdx
    • defining-contracts/function-calls/defining-example.mdx
    • defining-contracts/function-calls/receiving-function-calls.mdx
    • verifying-contracts/http-client/triggers.mdx
    • verifying-contracts/function-execution/registering-functions.mdx
  • Updated helper files: Modified YourApi.ts to add a health() method stub for trigger examples

Implementation Details

  • Code examples are marked in test files using // example-extract _example-name and // end-example comments
  • Test code that should not appear in documentation is wrapped with // ignore-extract and // end-ignore comments
  • Generated .mdx files contain code blocks extracted from the test files
  • Documentation pages now use tabbed interfaces to show language-specific examples side-by-side
  • This approach ensures examples stay in sync with actual working test code

https://claude.ai/code/session_01SoNKMWGAeFzwTQZA5XUhsr

…actor

The code examples added in the recent documentation update were inline in
the mdx files. This moves them alongside the tests of the language DSLs,
marked with example-extractor comments, so they are compiled (and therefore
stay correct) and are presented in both Typescript and Java:

- Function call definition (caller and implementer side, including the
  throwing variants) in both DSLs
- HTTP server-driven contract definition (mockConfig, interactions, and
  state handlers), now with Java examples
- Function registration during verification, including the Java JSON
  marshaller adapters
- Trigger groups for HTTP client verification (TriggerGroupMap /
  TriggerGroups), now with Java examples

Also regenerates the previously-stale extracted examples, and fixes a
broken link in the http-server chapter that failed the docusaurus build.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SoNKMWGAeFzwTQZA5XUhsr
@TimothyJones
TimothyJones merged commit e786f26 into main Jul 17, 2026
14 checks passed
@TimothyJones
TimothyJones deleted the claude/cross-language-doc-examples-tqsadm branch July 17, 2026 07:07
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