Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"permissions": {
"allow": [
"Read(./)",
"Edit(./)",
"MultiEdit(./)",
"Write(./)",
"Bash(mkdir:*)",
"Glob",
"Grep",
"Task",
"TodoWrite",
"WebFetch(domain:docs.anthropic.com)",
"WebFetch(domain:docs.claude.com)",
"WebFetch(domain:buildwithfern.com)"
]
},
"env": {
"FERN_TOKEN": "${FERN_TOKEN}",
"NODE_ENV": "development",
"PNPM_VERSION": "9.4.0"
},
"model": "claude-sonnet-4-20250514"
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ seed/python-sdk/**/output.prof
.cursor

# Claude
.claude
CLAUDE.md
**/settings.local.json

# Preview
**/.preview/
Expand Down
106 changes: 102 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,69 @@ Comprehensive generator testing with Docker-based fixtures across all supported

## Core Workflows

1. **Generation**: API Definition → IR → Generator Execution → Output (publish/GitHub/download)
2. **Documentation**: Markdown processing + API references → Static site
3. **Validation**: Schema validation + reference checking + example verification
### Production SDK Generation Flow

When users run `fern generate --group <group-name>` in production:

1. **CLI Version Check**: Fern CLI checks `fern.config.json` for required version and auto-downloads/installs if needed
2. **Configuration Discovery**: CLI locates `generators.yml` file(s) in the fern directory structure:
- Single API: `fern/generators.yml`
- Multiple APIs: `fern/apis/<api-name>/generators.yml` (separate configs per API)
3. **Generator Selection**: Uses `--group` parameter or `default-group` field to determine which generator group to run
4. **IR Generation**: Creates Fern IR file containing all information needed for generation (always latest IR version)
5. **Version Compatibility**: Checks generator version (e.g., `typescript-node-sdk:2.6.3`) against required IR version (e.g., `irVersion: 58`) using `/generators/<lang>/sdk/versions.yml`
6. **IR Migration**: If needed, migrates IR backward to match generator's expected version using `/packages/cli/generation/ir-migrations`
7. **Generation Execution**:
- **Local**: `--local` flag downloads Docker image and runs generation locally
- **Remote**: Uses Fiddle service for server-side generation (being deprecated)
8. **Output Delivery**: Based on `generators.yml` output configuration:
- **Package registries**: npm, PyPI, Maven, NuGet, RubyGems
- **GitHub**: release/pull-request/push modes
- **Local filesystem**: saves to specified directory

### Seed Testing (Development)

Seed validates generator changes against test fixtures. Essential for bug fixes and feature development.

**Structure**: `/test-definitions/` (inputs) → `/packages/seed/` (CLI) → `/seed/<generator>/<fixture>/` (outputs)

**Setup**: `pnpm install && pnpm compile && pnpm seed:build`

**Commands**:
```bash
# Test predefined fixture
pnpm seed test --generator python-sdk --fixture file-download --skip-scripts

# Test custom project
pnpm seed run --generator go-sdk --path /path/to/project --skip-scripts
```

**Development Cycle**:
1. Run seed test to reproduce issue
2. Modify generator code
3. Re-run seed test (use `git diff` to see output changes)
4. Repeat until fixed

**Output**: Seed test overwrites `/seed/<generator>/<fixture>/`, seed run writes to temp directory

### Feature Addition Workflow (Generated Code)

Multi-stage process: API Schema → IR Updates → Generator Updates → Release

**Stages**:
1. **API Schema**: Update `/fern/apis/<definition>/` → Run generator command (check `generators.yml` in each API folder)
2. **IR Updates**: Modify `/packages/ir-sdk/fern/apis/ir-types-latest/definition/` → `pnpm ir:generate`
3. **Versioning**: Update `CHANGELOG.md`, `VERSION`, and `/packages/cli/cli/versions.yml`
4. **Compile**: `pnpm compile` and fix breaking changes (common: `switch` statements need new cases)
5. **Generator Updates**: One PR for CLI/IR updates (merge first), then separate PR(s) for generator changes
6. **IR Migrations**: Update `/packages/cli/generation/ir-migrations/` for backward compatibility

**Key Points**: Multiple PRs required, automatic publishing via `versions.yml`, generators use published (not workspace) IR versions

### Other Core Workflows

1. **Documentation**: Markdown processing + API references → Static site
2. **Validation**: Schema validation + reference checking + example verification

## Important Files & Locations

Expand All @@ -93,7 +153,45 @@ Comprehensive generator testing with Docker-based fixtures across all supported
## Development Notes

- **Generator Development**: Implement `AbstractGeneratorCli`, use IR as input, follow existing language patterns
- **Generator-Specific Documentation**: Each major generator has its own CLAUDE.md file:
- `generators/python/CLAUDE.md` - Python v1+v2 tandem system
- `generators/java/CLAUDE.md` - Java v1+v2 tandem system
- `generators/go/CLAUDE.md` - Go v1+v2 tandem system
- `generators/typescript/CLAUDE.md` - Legacy TypeScript generator
- `generators/ruby-v2/CLAUDE.md` - Modern Ruby generator (standalone)
- `generators/csharp/CLAUDE.md` - Modern C# generator
- **IR Changes**: Require migrations in `packages/generation/ir-migrations/`
- **Testing**: Always run `pnpm test:ete` for end-to-end validation after CLI changes
- **Monorepo**: Use Turbo filters for focused builds/tests on specific packages
- **Docker**: Generators run in Docker containers for isolation and consistency
- **Docker**: Generators run in Docker containers for isolation and consistency

## Generated Code Management

**Identifying**: Generated by Fern (not third-party tools). Common locations: `/sdk/src/serialization/`, `/sdk/src/api/`, `/seed/` test fixtures.

**Regenerating**: `pnpm fern generate [--group <name>]` or `pnpm fern:local generate` for local testing

**Validation**: Run `pnpm compile` to check for issues. Test individual fixtures during development. Run full validation (`pnpm check:fix`, `pnpm test`, `pnpm test:ete`) only when changes are complete.

## Seed Testing & Fixtures

### Adding/Updating Fixtures

**New fixtures**: Create `/seed/<generator>/<fixture>/` directory → Add `seed.yml` config → Run `pnpm seed:build` → Run `pnpm test:update` and `pnpm test:ete:update` → Validate → Commit

**Update fixtures**: `pnpm seed:build --filter <fixture-name>` or `pnpm test:update` for snapshots

## Troubleshooting

### Quick Fixes by Issue Type
- **Generator failures**: Check `docker ps` → Rebuild image → Check container logs
- **IR compilation**: `pnpm fern check` → Check circular refs → Review migrations
- **Test failures**: Unit (check generated code) | E2E (`pnpm fern:build`) | Seed (`pnpm seed:build`) | Lint (`pnpm format:fix`)
- **Performance**: Use Turbo filters | `pnpm clean` then rebuild | Check Docker limits

### Debug Locations
- **Build outputs**: `dist/`, `.turbo/` directories
- **Test outputs**: `/seed/<generator>/<fixture>/` directories

# Individual Preferences
@~/.claude/my-fern-instructions.md
119 changes: 119 additions & 0 deletions generators/csharp/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# C# Generator (Modern)

This file provides guidance for Claude Code when working with the C# generator.

## Architecture

The C# generator is a **modern TypeScript-based implementation**:

- **TypeScript-based**: Written in TypeScript using modern generator patterns
- **Clean Architecture**: Follows the improved patterns seen in newer generators
- **Standalone Operation**: No legacy version - purely modern implementation
- **Structured Design**: Well-organized with clear separation of concerns

## Key Directories

### C# Generator (generators/csharp/)
- `base/` - Base generator infrastructure
- `codegen/` - Core C# code generation logic
- `sdk/` - C# SDK generator (TypeScript)
- `model/` - C# class and type generation
- `formatter/` - C# code formatting utilities
- `dynamic-snippets/` - Dynamic code snippet generation
- `csharp.sln` - C# solution file for generated code structure

## Common Issues & Debugging

### C# Generator Issues
- **TypeScript compilation**: Standard TS generator patterns apply
- **C# syntax generation**: Check `codegen/` utilities for C# language patterns
- **NuGet patterns**: .NET package and dependency management
- **Framework compatibility**: .NET Framework vs .NET Core/5+ considerations
- **Namespace organization**: C# namespace and assembly patterns

### .NET-Specific Issues
- **Package references**: NuGet package management and versioning
- **Target framework**: Multi-targeting different .NET versions
- **Assembly loading**: Generated assembly structure and dependencies
- **Serialization**: JSON.NET vs System.Text.Json patterns

## Development Commands

### C# Generator Development
```bash
cd generators/csharp
pnpm install
pnpm compile
```

### Testing
```bash
# From repository root
pnpm seed test --generator csharp-sdk --fixture <fixture-name> --skip-scripts
pnpm seed run --generator csharp-sdk --path /path/to/test/project --skip-scripts
```

## Configuration Options

The C# generator supports configuration in `generators.yml`:

### SDK Generator
- Modern TypeScript-based configuration options
- C#-specific settings for NuGet package generation
- .NET framework targeting options
- Dependency management configuration
- Namespace and assembly naming options

## Debug Patterns

1. **TypeScript compilation**: Check TS compilation in csharp directory
2. **C# syntax issues**: Examine `codegen/` utilities for C# language patterns
3. **NuGet structure**: Verify generated NuGet package follows conventions
4. **Framework compatibility**: Check .NET version requirements in generated code
5. **Assembly structure**: Verify proper C# namespace and class organization

## File Patterns

- **Generated C# code**: Follows C# conventions (PascalCase, proper indentation)
- **Project structure**: Standard .NET project layout with .csproj files
- **Namespace organization**: Proper C# namespace hierarchy
- **Documentation**: XML documentation comments for IntelliSense
- **Testing**: Generated with appropriate C# testing patterns

## C#-Specific Patterns

- **Naming conventions**: Automatic conversion to C# PascalCase conventions
- **Namespace structure**: Proper C# namespace nesting and organization
- **NuGet packaging**: Package specification and dependency management
- **Error handling**: C# exception patterns and custom exception classes
- **HTTP clients**: HttpClient integration with proper disposal patterns
- **JSON handling**: Newtonsoft.Json or System.Text.Json serialization
- **Async patterns**: Proper async/await implementation throughout
- **Property patterns**: C# property syntax with getters/setters
- **Nullable types**: C# nullable reference types and null safety

## Modern Generator Benefits

As a modern TypeScript-based generator:
- **Clean codebase**: No legacy technical debt
- **Consistent patterns**: Follows established modern generator conventions
- **Maintainable**: Well-structured and easy to modify
- **Extensible**: Clear architecture for adding new features
- **Type-safe**: Generated code follows C# type safety best practices

## Testing and Validation

When working with the C# generator:
- Test generated C# code compiles successfully with target .NET versions
- Validate NuGet package structure and metadata
- Check C# naming conventions and code style
- Verify proper async/await patterns
- Test integration with popular C# frameworks and libraries
- Validate JSON serialization/deserialization patterns

## Integration Considerations

- **Framework compatibility**: Ensure compatibility with target .NET versions
- **Dependency management**: Proper NuGet package version management
- **IDE support**: Generated code should work well with Visual Studio and VS Code
- **CI/CD integration**: Generated projects should build in standard .NET pipelines
Loading
Loading