refitter
A tool for generating Refit interfaces and contracts from OpenAPI (Swagger) specifications
465
Generate C# REST API Clients from OpenAPI specifications using Refit - no .NET installation required!
# Pull the image
docker pull christianhelle/refitter
# Generate from local OpenAPI spec
docker run --rm -v $(pwd):/src christianhelle/refitter ./openapi.json
# Generate from URL
docker run --rm -v $(pwd):/src christianhelle/refitter \
https://petstore3.swagger.io/api/v3/openapi.yaml \
--output /src/PetStoreClient.cs
# Latest version
docker pull christianhelle/refitter
# Specific version
docker pull christianhelle/refitter:1.0.0
# Verify installation
docker images | grep refitter
Basic Structure:
docker run [DOCKER_OPTIONS] christianhelle/refitter [REFITTER_ARGUMENTS]
Common Docker Options:
--rm - Auto-remove container after execution (recommended)-v $(pwd):/src - Mount current directory (Linux/macOS)-v ${PWD}:/src - Mount current directory (Windows PowerShell)-v %cd%:/src - Mount current directory (Windows CMD)-u $(id -u):$(id -g) - Run as current user (Linux/macOS, fixes file permissions)-w /src - Set working directory inside container--network host - Access localhost services# Simple generation
docker run --rm -v $(pwd):/src christianhelle/refitter ./openapi.json
# Custom namespace and output
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json \
--namespace "MyCompany.Api.Client" \
--output ./ApiClient.cs
# Using settings file
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json \
--settings-file ./petstore.refitter
# Interface only
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --interface-only --output ./IApiClient.cs
# Contracts only
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --contract-only --output ./Contracts.cs
# With API response wrappers
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --use-api-response
# Multiple interfaces by endpoint
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --multiple-interfaces ByEndpoint
# Multiple interfaces by tag
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --multiple-interfaces ByTag
# Filter by tags
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --tag Pet --tag Store
# With cancellation tokens
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --cancellation-tokens
# Immutable records
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --immutable-records
# Apizr integration
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --use-apizr
# Internal visibility
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --internal
# Custom operation names
docker run --rm -v $(pwd):/src christianhelle/refitter \
./openapi.json --operation-name-template '{operationName}Async'
Make usage easier by creating aliases:
# Add to ~/.bashrc or ~/.zshrc
alias refitter='docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) christianhelle/refitter'
# Reload
source ~/.bashrc
# Use it
refitter ./openapi.json --output ./Client.cs
# Add to $PROFILE
function refitter {
docker run --rm -v ${PWD}:/src christianhelle/refitter $args
}
# Reload
. $PROFILE
# Use it
refitter ./openapi.json --output ./Client.cs
Create refitter.bat in your PATH:
@echo off
docker run --rm -v %cd%:/src christianhelle/refitter %*
-n, --namespace Default namespace (default: GeneratedCode)
-o, --output Output file path (default: Output.cs)
-s, --settings-file Path to .refitter settings file
--contracts-namespace Namespace for contracts
--contracts-output Separate output for contracts
--interface-only Generate only interfaces
--contract-only Generate only contracts
--use-api-response Return IApiResponse<T>
--use-observable-response Return IObservable
--internal Internal type accessibility
--cancellation-tokens Add cancellation token parameters
--multiple-interfaces ByEndpoint or ByTag
--multiple-files Generate separate files
--tag Filter by OpenAPI tags
--match-path Filter paths with regex
--trim-unused-schema Remove unreferenced schemas
--no-deprecated-operations Skip deprecated operations
--immutable-records Generate records instead of classes
--use-apizr Apizr integration
--use-dynamic-querystring-parameters Dynamic query params
--use-polymorphic-serialization System.Text.Json polymorphism
--disposable Generate IDisposable clients
--collection-format Multi/Csv/Ssv/Tsv/Pipes
--integer-type int or long
--operation-name-generator Naming strategy
--no-banner Hide banner
--simple-output Plain text output
Mount your project directory to access files:
# Current directory
docker run --rm -v $(pwd):/src christianhelle/refitter /src/openapi.json
# Specific directory
docker run --rm -v /path/to/project:/src christianhelle/refitter /src/specs/api.json
# Multiple mounts
docker run --rm \
-v $(pwd)/specs:/specs:ro \
-v $(pwd)/output:/output \
christianhelle/refitter /specs/api.json --output /output/Client.cs
# Read-only mount (security)
docker run --rm -v $(pwd)/specs:/specs:ro \
-v $(pwd)/output:/output \
christianhelle/refitter /specs/api.json --output /output/Client.cs
Files created in Docker containers are owned by root by default. Use -u flag:
docker run --rm \
-v $(pwd):/src \
-u $(id -u):$(id -g) \
christianhelle/refitter ./openapi.json
"No such file or directory"
-v $(pwd):/src/src/openapi.json or ./openapi.jsonGenerated files not visible
--output /src/Client.cs or --output ./Client.csPermission denied (Linux/macOS)
-u $(id -u):$(id -g) flagCannot access localhost URLs
--network host flagdocker run --rm --network host -v $(pwd):/src christianhelle/refitter http://localhost:5000/swagger/v1/swagger.jsonVolume mounting on Windows
${PWD} instead of $(pwd)%cd% instead of $(pwd)-v "${PWD}:/src"# Generate client with all common options
docker run --rm -v $(pwd):/src christianhelle/refitter ./openapi.json \
--namespace "PetStore.Api.Client" \
--use-api-response \
--cancellation-tokens \
--multiple-interfaces ByTag \
--tag Pet \
--tag Store \
--no-deprecated-operations \
--operation-name-template '{operationName}Async' \
--trim-unused-schema \
--immutable-records \
--output ./PetStoreClient.cs
MIT License - See LICENSE
Content type
Image
Digest
sha256:fa5c97f45…
Size
82.7 MB
Last updated
2 days ago
docker pull christianhelle/refitter