From d7820fcceaf2501861ef33f2643ecfaeafe57d4b Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Thu, 26 Feb 2026 20:49:48 +0100 Subject: [PATCH 1/2] Update CLAUDE.md with comprehensive project guidance for Claude Code Replace minimal MCP server note with full developer guidance including build/test commands, architecture overview, code conventions, and multi-targeting notes. Uses .slnx solution format with a note about net8.0 incompatibility requiring project-level test runs. Co-Authored-By: Claude Opus 4.6 --- CLAUDE.md | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 615e58179..18042c917 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,2 +1,104 @@ -## MCP Servers Available -- mem0: Use this AI memory for storing and retrieving long-term context as well as short-term context \ No newline at end of file +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Build & Test Commands + +```bash +# Build +dotnet build RestSharp.slnx -c Debug + +# Run all tests +dotnet test RestSharp.slnx -c Debug + +# Run tests for a specific TFM +dotnet test RestSharp.slnx -f net9.0 + +# Run a single test by fully-qualified name +dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj --filter "FullyQualifiedName=RestSharp.Tests.ObjectParserTests.ShouldUseRequestProperty" -f net8.0 + +# Pack +dotnet pack src/RestSharp/RestSharp.csproj -c Release -o nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg +``` + +**Note:** `dotnet test` with `.slnx` does not work with `net8.0`. To run tests targeting `net8.0`, use individual project files: `dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj -f net8.0` + +## Project Overview + +RestSharp is a lightweight HTTP API client library for .NET that wraps `HttpClient`. It provides default parameters, multiple parameter types (query, URL segment, header, cookie, body), built-in JSON/XML/CSV serialization, and authentication support. + +### Repository Layout + +- `src/RestSharp/` — Core library +- `src/RestSharp.Serializers.NewtonsoftJson/` — Newtonsoft.Json serializer adapter +- `src/RestSharp.Serializers.Xml/` — Custom XML serializer +- `src/RestSharp.Serializers.CsvHelper/` — CsvHelper serializer adapter +- `src/RestSharp.Extensions.DependencyInjection/` — DI integration +- `gen/SourceGenerator/` — Custom incremental source generators +- `test/RestSharp.Tests/` — Unit tests +- `test/RestSharp.Tests.Integrated/` — Integration tests (WireMock-based) +- `test/RestSharp.Tests.Serializers.*/` — Serializer-specific tests + +## Architecture + +### Core Classes + +- **RestClient** (`RestClient.cs`, split into partials `RestClient.*.cs`) — Main entry point. Wraps `HttpClient`, holds `ReadOnlyRestClientOptions`, `RestSerializers`, and `DefaultParameters`. Thread-safe when configured via `RestClientOptions`. +- **RestRequest** (`Request/RestRequest.cs`) — Request container with fluent API via extension methods in `RestRequest*.cs` files. Parameters split by type: query, body, header, URL segment, cookie, file. +- **RestResponse / RestResponse\** (`Response/RestResponse*.cs`) — Immutable response containers generated by `[GenerateClone]` source generator. +- **RestClientOptions** (`Options/RestClientOptions.cs`) — Mutable configuration class. An immutable `ReadOnlyRestClientOptions` wrapper is generated by `[GenerateImmutable]`. + +### Request Pipeline + +`ExecuteAsync` → build request → interceptor chain (`BeforeRequest` → `BeforeHttpRequest` → send → `AfterHttpRequest` → `AfterRequest`) → deserialization → error handling. Interceptors are configured via `RestClientOptions.Interceptors`. + +### Parameter System (`Parameters/`) + +Abstract `Parameter` record base with concrete types: `HeaderParameter`, `QueryParameter`, `BodyParameter`, `UrlSegmentParameter`, `FileParameter`, `GetOrPostParameter`, `CookieParameter`. `ObjectParser` converts objects to parameters via reflection. + +### Serialization (`Serializers/`) + +`ISerializer`/`IDeserializer` interfaces. `RestSerializers` manages serializers by `DataFormat` enum (Json, Xml, Csv). Default: `SystemTextJsonSerializer`. Configured via `ConfigureSerialization` delegate in client constructors. + +### Authentication (`Authenticators/`) + +`IAuthenticator` with single `Authenticate(IRestClient, RestRequest)` method. Built-in: `HttpBasicAuthenticator`, `JwtAuthenticator`, OAuth1/OAuth2 authenticators. Set via `RestClientOptions.Authenticator`. + +### Source Generators (`gen/SourceGenerator/`) + +- `[GenerateImmutable]` — Creates read-only wrapper (used on `RestClientOptions`) +- `[GenerateClone]` — Creates static factory clone methods (used on `RestResponse`) +- `[Exclude]` — Excludes properties from immutable generation +- Generator target must be `netstandard2.0`. Inspect output in `obj///generated/SourceGenerator/`. + +## Multi-Targeting + +**Library:** `netstandard2.0`, `net471`, `net48`, `net8.0`, `net9.0`, `net10.0` +**Tests:** `net48` (Windows only), `net8.0`, `net9.0`, `net10.0` + +Use conditional compilation for TFM-specific APIs: `#if NET`, `#if NET8_0_OR_GREATER`. `System.Text.Json` is a NuGet dependency on older TFMs but built-in on net8.0+. + +## Code Style & Conventions + +- **C# version:** preview (latest features) +- **Nullable:** Enabled in `/src`, disabled in `/test` +- **License header required** in all `/src` files (Apache-2.0, see `.github/copilot-instructions.md` for exact text) +- **Strong-named** assemblies via `RestSharp.snk` +- **Partial classes** for large types, linked via `` in csproj +- **Package versions** centrally managed in `Directory.Packages.props` — don't pin in individual projects +- **Versioning** via MinVer from git tags (no hardcoded versions) +- Follow `.editorconfig` for formatting + +## Testing + +- **Stack:** xUnit + FluentAssertions + AutoFixture +- **HTTP mocking:** WireMock.Net (avoid live endpoints) +- Global usings in test projects: `Xunit`, `FluentAssertions`, `AutoFixture` +- Guard TFM-specific tests with `#if NET8_0_OR_GREATER` +- Test results: `test-results//.trx` + +## Working with Issues + +- Avoid changing default behavior unless absolutely necessary +- Avoid breaking the existing API +- Leave existing tests intact to catch regressions; add new tests for fixed cases From a57c1ecb1dffe4afa6c659824fd6ca17bbdd2e98 Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Thu, 26 Feb 2026 21:01:14 +0100 Subject: [PATCH 2/2] Fix misleading "immutable" claim about RestResponse in CLAUDE.md RestResponse types have public setters on all properties. Remove the incorrect "immutable" label and clarify what [GenerateClone] actually does. Co-Authored-By: Claude Opus 4.6 --- CLAUDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index 18042c917..1fd8c31b5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -45,7 +45,7 @@ RestSharp is a lightweight HTTP API client library for .NET that wraps `HttpClie - **RestClient** (`RestClient.cs`, split into partials `RestClient.*.cs`) — Main entry point. Wraps `HttpClient`, holds `ReadOnlyRestClientOptions`, `RestSerializers`, and `DefaultParameters`. Thread-safe when configured via `RestClientOptions`. - **RestRequest** (`Request/RestRequest.cs`) — Request container with fluent API via extension methods in `RestRequest*.cs` files. Parameters split by type: query, body, header, URL segment, cookie, file. -- **RestResponse / RestResponse\** (`Response/RestResponse*.cs`) — Immutable response containers generated by `[GenerateClone]` source generator. +- **RestResponse / RestResponse\** (`Response/RestResponse*.cs`) — Response containers with public setters. `[GenerateClone]` generates a static factory to copy base properties from `RestResponse` into `RestResponse`. - **RestClientOptions** (`Options/RestClientOptions.cs`) — Mutable configuration class. An immutable `ReadOnlyRestClientOptions` wrapper is generated by `[GenerateImmutable]`. ### Request Pipeline