doc-example-generator
Skill27 starsChanged 2 years agoMITView on GitHub
Generate verified code examples for TypeSpec documentation. Use this skill to create TypeSpec examples that compile successfully, then run each language emitter to extract real API surface code for the <ClientTabs> blocks in user-facing docs.
- Installs packages
In this repository8 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- code-reviewSkill
- create-linter-ruleSkill
- hotfix-releaseSkill
- tcgc-newsletterSkill
- typespec-go-add-spector-testSkill
- typespec-python-releaseSkill
- typespec-ts-add-spector-testSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 3 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
Create a temp directory (e.g., /tmp/tsp-doc-example-<feature>/ or a workspace-relative .tmp/ folder)
- Very specific: line 27
Run npm install --legacy-peer-deps to install all dependencies
- Very specific: line 31
Create a main.tsp file containing the example code.
- Very specific: line 32
Use the @service to decorate the main service namespace
- Very specific: line 37
If the example involves client customization decorators (e.g., @clientName, @access, @usage from …
- Very specific: line 41
Run npx tsp compile . and verify it succeeds with zero errors
- Very specific: line 42
Critical: If a client.tsp file exists, you MUST use it as the entry point: npx tsp compile client.tsp.
- Very specific: line 44
If compilation fails, fix the .tsp files and re-compile until it passes
- Distinctive: line 45
Do NOT proceed to Step 3 until compilation is clean
- Very specific: line 49
After successful compilation, the emitter output will be in the tsp-output/ directory, organized by emitter package name
- Very specific: line 131
If a feature is not supported by a language, use a comment: // NOT_SUPPORTED or # NOT_SUPPORTED
- Very specific: line 132
If the TypeSpec example uses separate main.tsp and client.tsp files, include both in the TypeSpec block with a title attribute:
- Distinctive: line 146
Delete the temporary project directory
- Very specific: line 153
Generated output is empty or unexpected: Verify the tspconfig.yaml emitter configuration.
- Distinctive: line 154
Cannot determine what to extract: Default to extracting the main client class and any models/operations that are directly affected by the …
- Very specific: line 173
Before returning the <ClientTabs> block, verify:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Doc Example Generator
You are a code-example generation agent for TypeSpec documentation. Your goal is to produce verified, real-world code examples that:
- TypeSpec code compiles — every
.tspexample passestsp compilewith no errors - Language tabs show real emitter output — each language's code is extracted from actual emitter-generated output, not hand-written
Scope and Guardrails
This skill operates in a temporary working directory to compile and generate code. It does NOT commit the temp directory — only the resulting <ClientTabs> block is used in documentation.
Workflow
Step 1: Set Up Temporary Project
- Create a temp directory (e.g.,
/tmp/tsp-doc-example-<feature>/or a workspace-relative.tmp/folder) - Copy the
package.jsonfrom this skill's directory (package.jsonnext to this file) into the temp directory - Run
npm install --legacy-peer-depsto install all dependencies
Step 2: Write and Validate TypeSpec Example
- Create a
main.tspfile containing the example code. The example must:- Use the
@serviceto decorate the main service namespace - Include
importandusingstatements for all required libraries - Be self-contained — no external file dependencies beyond installed packages
- Demonstrate the specific feature being documented
- Use the
- If the example involves client customization decorators (e.g.,
@clientName,@access,@usagefrom@azure-tools/typespec-client-generator-core), create a separateclient.tspthat importsmain.tspand applies the decorators using augment syntax (@@decorator). This mirrors the recommended user pattern. - Copy the
tspconfig.yamlfrom this skill's directory (tspconfig.yamlnext to this file) into the temp directory. Add extra emitter options only if the example specifically needs them. - Run
npx tsp compile .and verify it succeeds with zero errors- Critical: If a
client.tspfile exists, you MUST use it as the entry point:npx tsp compile client.tsp. Compiling with.only picks upmain.tspand will NOT apply augment decorators fromclient.tsp. - For
@azure-typespec/http-client-csharpemitter, you need to add an emptymetadata.jsonfile in the output directory to trigger code generation. Create an empty file attsp-output/@azure-typespec/http-client-csharp/metadata.jsonbefore running compilation. - If compilation fails, fix the
.tspfiles and re-compile until it passes - Do NOT proceed to Step 3 until compilation is clean
- Critical: If a
Step 3: Generate Language Code
- After successful compilation, the emitter output will be in the
tsp-output/directory, organized by emitter package name - For each language, locate the generated output directory:
- Python:
tsp-output/@azure-tools/typespec-python/ - C#:
tsp-output/@azure-typespec/http-client-csharp/ - TypeScript:
tsp-output/@azure-tools/typespec-ts/ - Java:
tsp-output/@azure-tools/typespec-java/ - Go:
tsp-output/@azure-tools/typespec-go/
- Python:
Step 4: Extract Key API Surface Code
For each language's generated output, extract only the key API surface — the public types, method signatures, and usage patterns that illustrate the feature being documented. Do NOT include:
- Internal implementation details or private methods
- Boilerplate imports/headers (unless they clarify the example)
- Full file contents — only the relevant class, method, or type declarations
What to extract depends on the documentation goal:
| Documentation Topic | What to Extract |
| Model renaming / customization | The renamed class/struct/type declaration showing the new name |
| Access control | The public API showing which operations/models are exposed or hidden |
| Client structure | Client class declarations and operation group hierarchy |
| Method signatures | The method/function signatures showing parameters, return types |
| Type customization | Model/enum/union type declarations showing the customized shape |
| Paging | The paging method signature and page result type |
| Long-running operations | The LRO method signature and poller/operation types |
| General feature | The public types and operations most directly affected by the feature |
General extraction rules:
- Show the public class/struct/interface declaration with its key members
- Show method signatures (name, parameters, return type) without method bodies
- Include a brief usage snippet (instantiate client, call the method) when it clarifies behavior
- For Go: include the constructor function and key exported types
- For Python: include the class definition with key methods and a usage comment
- For Java: include the builder pattern if client-related, otherwise just the class and methods
- For C#: include both async and sync method signatures when relevant
- For TypeScript: include the interface/type definition and function signature
Step 5: Assemble the <ClientTabs> Block
Combine the TypeSpec source and extracted language code into a <ClientTabs> block following this exact format:
<ClientTabs>
```typespec title="main.tsp"
// TypeSpec code from main.tsp
```
```typespec title="client.tsp"
// TypeSpec code from client.tsp if applicable
```
```python
# Extracted Python API surface
```
```csharp
// Extracted C# API surface
```
```typescript
// Extracted TypeScript API surface
```
```java
// Extracted Java API surface
```
```go
// Extracted Go API surface
```
</ClientTabs>Formatting rules:
- The TypeSpec block always comes first
- Language blocks follow in this order: python, csharp, typescript, java, go
- If a feature is not supported by a language, use a comment:
// NOT_SUPPORTEDor# NOT_SUPPORTED If the TypeSpec example uses separate
main.tspandclient.tspfiles, include both in the TypeSpec block with atitleattribute:```typespec title=main.tsp // main service definition ``` ```typespec title=client.tsp // client customization decorators ```
Step 6: Clean Up
- Delete the temporary project directory
- Return the assembled
<ClientTabs>block to be inserted into documentation
Error Handling
- TypeSpec compilation fails: Fix the
.tspcode. Check decorator signatures against the relevant library's.tspdefinitions. Re-compile until clean. - Emitter generation fails for one language: Note the failure, use
// TODO: fill in <language> example manually — emitter generation failed (<brief reason>)as a placeholder in that language's tab. Do not block other languages. - Generated output is empty or unexpected: Verify the
tspconfig.yamlemitter configuration. Check that the example uses patterns the emitter supports. - Cannot determine what to extract: Default to extracting the main client class and any models/operations that are directly affected by the feature being documented.
@clientNameor other TCGC augment decorators not taking effect: You are likely compilingmain.tspinstead ofclient.tsp. The entry point must be the file that imports everything — usenpx tsp compile client.tsp.
Emitter Runtime Requirements
Some emitters require language-specific runtimes to generate code. If a runtime is missing, the emitter may report an error or produce no output.
| Emitter | Runtime Requirements | Fallback |
| Python | Python 3.9+ (or set use-pyodide: true in tspconfig) | use-pyodide: true uses WASM Python |
| Java | JDK 17+ and Apache Maven | No fallback — skip if unavailable |
| C# | .NET SDK | Emitter produces only metadata.json |
| TypeScript | Node.js (always available); set azure-sdk-for-js: false | May produce empty output — see note |
| Go | Go 1.20+; set module option in tspconfig | No fallback — skip if unavailable |
Note on TypeScript: The TS emitter may produce empty output (0ms) even when reporting success. Ensure
azure-sdk-for-js: falseandis-typespec-test: trueare set in tspconfig options. If output is still empty, the emitter may require additional setup for standalone use.
Quality Checklist
Before returning the <ClientTabs> block, verify:
- TypeSpec code compiles with zero errors
- All five language tabs are present
- Language code is extracted from real emitter output (not hand-written)
- Only key API surface is shown (no internal implementation details)
- The extracted code clearly demonstrates the documented feature or customization
- Code formatting is clean and consistent with existing doc examples
- Temporary project directory has been cleaned up
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

