Refitter.SourceGenerator
1.2.1-preview.56
See the version list below for details.
dotnet add package Refitter.SourceGenerator --version 1.2.1-preview.56
NuGet\Install-Package Refitter.SourceGenerator -Version 1.2.1-preview.56
<PackageReference Include="Refitter.SourceGenerator" Version="1.2.1-preview.56"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Refitter.SourceGenerator --version 1.2.1-preview.56
#r "nuget: Refitter.SourceGenerator, 1.2.1-preview.56"
// Install Refitter.SourceGenerator as a Cake Addin #addin nuget:?package=Refitter.SourceGenerator&version=1.2.1-preview.56&prerelease // Install Refitter.SourceGenerator as a Cake Tool #tool nuget:?package=Refitter.SourceGenerator&version=1.2.1-preview.56&prerelease
Source Generator
Refitter is available as a C# Source Generator that uses the Refitter.Core library for generating a REST API Client using the Refit library. Refitter can generate the Refit interface from OpenAPI specifications. Refitter could format the generated Refit interface to be managed by Apizr (v6+) and generate some registration helpers too.
The Refitter source generator is a bit untraditional in a sense that it creates a folder called Generated
in the same location as the .refitter
file and generates files to disk under the Generated
folder (can be changed with --outputFolder
). The source generator output should be included in the project and committed to source control. This is done because there is no other way to trigger the Refit source generator to pickup the Refitter generated code
(Translation: I couldn't for the life of me figure how to get that to work, sorry)
Installation
The source generator is distributed as a NuGet package and should be installed to the project that will contain the generated code
dotnet add package Refitter.SourceGenerator
Usage
This source generator generates code based on any .refitter
file included to the project as AdditionalFiles
.
The generator can automatically detect all .refitter
files inside the project that referenced the Refitter.SourceGenerator
package and there is no need to include them manually as AdditionalFiles
.Refitter File format
The following is an example .refitter
file
{
"openApiPath": "/path/to/your/openAPI", // Required
"namespace": "Org.System.Service.Api.GeneratedCode", // Optional. Default=GeneratedCode
"naming": {
"useOpenApiTitle": false, // Optional. Default=true
"interfaceName": "MyApiClient" // Optional. Default=ApiClient
},
"generateContracts": true, // Optional. Default=true
"generateXmlDocCodeComments": true, // Optional. Default=true
"generateStatusCodeComments": true, // Optional. Default=true
"addAutoGeneratedHeader": true, // Optional. Default=true
"addAcceptHeaders": true, // Optional. Default=true
"returnIApiResponse": false, // Optional. Default=false
"responseTypeOverride": { // Optional. Default={}
"File_Upload": "IApiResponse",
"File_Download": "System.Net.Http.HttpContent"
},
"generateOperationHeaders": true, // Optional. Default=true
"typeAccessibility": "Public", // Optional. Values=Public|Internal. Default=Public
"useCancellationTokens": false, // Optional. Default=false
"useIsoDateFormat": false, // Optional. Default=false
"multipleInterfaces": "ByEndpoint", // Optional. May be one of "ByEndpoint" or "ByTag"
"generateDeprecatedOperations": false, // Optional. Default=true
"operationNameTemplate": "{operationName}Async", // Optional. Must contain {operationName} when multipleInterfaces != ByEndpoint
"optionalParameters": false, // Optional. Default=false
"outputFolder": "../CustomOutput" // Optional. Default=./Generated
"outputFilename": "RefitInterface.cs", // Optional. Default=Output.cs for CLI tool
"additionalNamespaces": [ // Optional
"Namespace1",
"Namespace2"
],
"includeTags": [ // Optional. OpenAPI Tag to include when generating code
"Pet",
"Store",
"User"
],
"includePathMatches": [ // Optional. Only include Paths that match the provided regular expression
"^/pet/.*",
"^/store/.*"
],
"useDynamicQuerystringParameters": true, // Optional. Default=false
"dependencyInjectionSettings": { // Optional
"baseUrl": "https://petstore3.swagger.io/api/v3", // Optional. Leave this blank to set the base address manually
"httpMessageHandlers": [ // Optional
"AuthorizationMessageHandler",
"TelemetryMessageHandler"
],
"transientErrorHandler": "Polly", // Optional. Value=None|Polly|HttpResilience
"maxRetryCount": 3, // Optional. Default=6
"firstBackoffRetryInSeconds": 0.5 // Optional. Default=1.0
},
"apizrSettings": { // Optional
"withRequestOptions": true, // Optional. Default=true
"withRegistrationHelper": true, // Optional. Default=false
"withCacheProvider": "InMemory", // Optional. Values=None|Akavache|MonkeyCache|InMemory|DistributedAsString|DistributedAsByteArray. Default=None
"withPriority": true, // Optional. Default=false
"withMediation": true, // Optional. Default=false
"withOptionalMediation": true, // Optional. Default=false
"withMappingProvider": "AutoMapper", // Optional. Values=None|AutoMapper|Mapster. Default=None
"withFileTransfer": true // Optional. Default=false
},
"codeGeneratorSettings": { // Optional. Default settings are the values set in this example
"requiredPropertiesMustBeDefined": true,
"generateDataAnnotations": true,
"anyType": "object",
"dateType": "System.DateTimeOffset",
"dateTimeType": "System.DateTimeOffset",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.ICollection",
"dictionaryType": "System.Collections.Generic.IDictionary",
"arrayInstanceType": "System.Collections.ObjectModel.Collection",
"dictionaryInstanceType": "System.Collections.Generic.Dictionary",
"arrayBaseType": "System.Collections.ObjectModel.Collection",
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"propertySetterAccessModifier": "",
"generateImmutableArrayProperties": false,
"generateImmutableDictionaryProperties": false,
"handleReferences": false,
"jsonSerializerSettingsTransformationMethod": null,
"generateJsonMethods": false,
"enforceFlagEnums": false,
"inlineNamedDictionaries": false,
"inlineNamedTuples": true,
"inlineNamedArrays": false,
"generateOptionalPropertiesAsNullable": false,
"generateNullableReferenceTypes": false,
"generateNativeRecords": false,
"generateDefaultValues": true,
"inlineNamedAny": false,
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
}
}
openApiPath
- points to the OpenAPI Specifications file. This can be the path to a file stored on disk, relative to the.refitter
file. This can also be a URL to a remote file that will be downloaded over HTTP/HTTPSnamespace
- the namespace used in the generated code. If not specified, this defaults toGeneratedCode
naming.useOpenApiTitle
- a boolean indicating whether the OpenApi title should be used. Default istrue
naming.interfaceName
- the name of the generated interface. The generated code will automatically prefix this withI
so if this set toMyApiClient
then the generated interface is calledIMyApiClient
. Default isApiClient
generateContracts
- a boolean indicating whether contracts should be generated. A use case for this is several API clients use the same contracts. Default istrue
generateXmlDocCodeComments
- a boolean indicating whether XML doc comments should be generated. Default istrue
addAutoGeneratedHeader
- a boolean indicating whether XML doc comments should be generated. Default istrue
addAcceptHeaders
- a boolean indicating whether to add accept headers [Headers("Accept: application/json")]. Default istrue
returnIApiResponse
- a boolean indicating whether to returnIApiResponse<T>
objects. Default isfalse
responseTypeOverride
- a dictionary with operation ids (as specified in the OpenAPI document) and a particular return type to use. The types are wrapped in a task, but otherwise unmodified (so make sure to specify or import their namespaces). Default is{}
generateOperationHeaders
- a boolean indicating whether to use operation headers in the generated methods. Default istrue
typeAccessibility
- the generated type accessibility. Possible values arePublic
andInternal
. Default isPublic
useCancellationTokens
- Use cancellation tokens in the generated methods. Default isfalse
useIsoDateFormat
- Set totrue
to explicitly format date query string parameters in ISO 8601 standard date format using delimiters (for example: 2023-06-15). Default isfalse
multipleInterfaces
- Set toByEndpoint
to generate an interface for each endpoint, orByTag
to group Endpoints by their Tag (like SwaggerUI groups them).outputFolder
- a string describing a relative path to a desired output folder. Default is./Generated
outputFilename
- Output filename. Default isOutput.cs
when used from the CLI tool, otherwise its the .refitter filename. SoPetstore.refitter
becomesPetstore.cs
.additionalNamespaces
- A collection of additional namespaces to include in the generated file. A use case for this is when you want to reuse contracts from a different namespace than the generated code. Default is emptyincludeTags
- A collection of tags to use a filter for including endpoints that contain this tag.includePathMatches
- A collection of regular expressions used to filter paths.generateDeprecatedOperations
- a boolean indicating whether deprecated operations should be generated or skipped. Default istrue
operationNameTemplate
- Generate operation names using pattern. This must contain the string {operationName}. An example usage of this could be{operationName}Async
to suffix all method names with Async. When using"multipleIinterfaces": "ByEndpoint"
, This is name of the Execute() method in the interfaceoptionalParameters
- Generate non-required parameters as nullable optional parametersuseDynamicQuerystringParameters
: Set totrue
to wrap multiple query parameters into a single complex one. Default isfalse
(no wrapping).dependencyInjectionSettings
- Setting this will generated extension methods toIServiceCollection
for configuring Refit clients. See https://github.com/reactiveui/refit?tab=readme-ov-file#dynamic-querystring-parameters for more information.baseUrl
- Used as the HttpClient base address. Leave this blank to manually set the base URLhttpMessageHandlers
- A collection ofHttpMessageHandler
that is added to the HttpClient pipelinetransientErrorHandler
- This is the transient error handler to use. Possible values areNone
,Polly
, andHttpResilience
. Default isNone
maxRetryCount
- This is the max retry count used in the Polly retry policy. Default is 6firstBackoffRetryInSeconds
- This is the duration of the initial retry backoff. Default is 1 second
apizrSettings
- Setting this will format Refit interface to be managed by Apizr. See https://www.apizr.net for more informationwithRequestOptions
- Tells if the Refit interface methods should have a final IApizrRequestOptions options parameterwithRegistrationHelper
- Tells if Refitter should generate Apizr registration helpers (extended with dependencyInjectionSettings set, otherwise static)withCacheProvider
- Set the cache provider to be usedwithPriority
- Tells if Apizr should handle request prioritywithMediation
- Tells if Apizr should handle request mediation (extended only)withOptionalMediation
- Tells if Apizr should handle optional request mediation (extended only)withMappingProvider
- Set the mapping provider to be usedwithFileTransfer
- Tells if Apizr should handle file transfer
codeGeneratorSettings
- Setting this allows customization of the NSwag generated types and contractsrequiredPropertiesMustBeDefined
- Default is true,generateDataAnnotations
- Default is true,anyType
- Default isobject
,dateType
- Default isSystem.DateTimeOffset
,dateTimeType
- Default isSystem.DateTimeOffset
,timeType
- Default isSystem.TimeSpan
,timeSpanType
- Default isSystem.TimeSpan
,arrayType
- Default isSystem.Collections.Generic.ICollection
,dictionaryType
- Default isSystem.Collections.Generic.IDictionary
,arrayInstanceType
- Default isSystem.Collections.ObjectModel.Collection
,dictionaryInstanceType
- Default isSystem.Collections.Generic.Dictionary
,arrayBaseType
- Default isSystem.Collections.ObjectModel.Collection
,dictionaryBaseType
- Default isSystem.Collections.Generic.Dictionary
,propertySetterAccessModifier
- Default is ``,generateImmutableArrayProperties
- Default is false,generateImmutableDictionaryProperties
- Default is false,handleReferences
- Default is false,jsonSerializerSettingsTransformationMethod
- Default is null,generateJsonMethods
- Default is false,enforceFlagEnums
- Default is false,inlineNamedDictionaries
- Default is false,inlineNamedTuples
- Default is true,inlineNamedArrays
- Default is false,generateOptionalPropertiesAsNullable
- Default is false,generateNullableReferenceTypes
- Default is false,generateNativeRecords
- Default is falsegenerateDefaultValues
- Default is trueinlineNamedAny
- Default is falseexcludedTypeNames
- Default is empty
Learn more about Target Frameworks and .NET Standard.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.4.1 | 583 | 11/20/2024 | |
1.4.1-preview.62 | 46 | 11/4/2024 | |
1.4.0 | 3,954 | 10/14/2024 | |
1.4.0-preview.61 | 42 | 10/7/2024 | |
1.3.2 | 1,345 | 9/23/2024 | |
1.3.2-preview.60 | 46 | 9/23/2024 | |
1.3.1 | 538 | 9/20/2024 | |
1.3.0 | 1,063 | 9/14/2024 | |
1.2.1-preview.59 | 53 | 9/13/2024 | |
1.2.1-preview.58 | 126 | 9/11/2024 | |
1.2.1-preview.57 | 59 | 9/11/2024 | |
1.2.1-preview.56 | 52 | 9/9/2024 | |
1.2.1-preview.55 | 49 | 9/2/2024 | |
1.2.1-preview.54 | 48 | 8/29/2024 | |
1.2.0 | 2,747 | 8/12/2024 | |
1.2.0-preview.53 | 35 | 8/4/2024 | |
1.2.0-preview.52 | 48 | 7/29/2024 | |
1.1.3 | 19,789 | 7/19/2024 | |
1.1.3-preview.51 | 50 | 7/19/2024 | |
1.1.2 | 24,832 | 7/17/2024 | |
1.1.2-preview.50 | 44 | 7/16/2024 | |
1.1.2-preview.49 | 59 | 7/11/2024 | |
1.1.1 | 187,258 | 7/6/2024 | |
1.1.1-preview.48 | 49 | 7/4/2024 | |
1.1.1-preview.47 | 56 | 7/1/2024 | |
1.1.1-preview.46 | 59 | 6/28/2024 | |
1.1.0.45-preview | 95 | 6/25/2024 | |
1.0.2 | 237,808 | 6/13/2024 | |
1.0.1 | 48,496 | 6/7/2024 | |
1.0.0 | 246,648 | 5/3/2024 | |
0.9.9.44-preview | 80 | 4/29/2024 | |
0.9.9 | 10,296 | 3/7/2024 | |
0.9.8 | 2,089 | 2/27/2024 | |
0.9.7 | 73,380 | 2/7/2024 | |
0.9.6 | 283 | 1/29/2024 | |
0.9.5 | 33,708 | 1/15/2024 | |
0.9.4.43-preview | 157 | 1/15/2024 | |
0.9.4 | 32,169 | 1/12/2024 | |
0.9.3.42-preview | 149 | 1/10/2024 | |
0.9.2 | 20,211 | 1/10/2024 | |
0.9.1 | 4,122 | 1/9/2024 | |
0.9.0 | 8,095 | 1/9/2024 | |
0.8.7.41-preview | 160 | 1/3/2024 | |
0.8.7.40-preview | 237 | 12/20/2023 | |
0.8.7 | 59,369 | 12/18/2023 | |
0.8.6.39-preview | 443 | 12/14/2023 | |
0.8.6.38-preview | 133 | 12/14/2023 | |
0.8.6 | 10,411 | 12/11/2023 | |
0.8.5 | 642 | 11/23/2023 | |
0.8.4 | 817 | 11/7/2023 | |
0.8.3 | 212 | 10/31/2023 | |
0.8.2 | 2,415 | 10/9/2023 | |
0.8.1 | 228 | 10/4/2023 | |
0.8.0 | 7,490 | 9/23/2023 | |
0.7.5 | 209 | 9/7/2023 | |
0.7.4 | 193 | 9/6/2023 | |
0.7.3.37-preview | 254 | 8/25/2023 | |
0.7.3.36-preview | 161 | 8/25/2023 | |
0.7.3.35-preview | 217 | 8/21/2023 | |
0.7.3.34-preview | 194 | 8/15/2023 | |
0.7.3.33-preview | 333 | 8/12/2023 | |
0.7.3 | 885 | 8/26/2023 | |
0.7.2.32-preview | 292 | 8/7/2023 | |
0.7.2 | 269 | 8/7/2023 | |
0.7.1.31-preview | 284 | 8/2/2023 | |
0.7.1.30-preview | 278 | 8/2/2023 | |
0.7.1.29-preview | 176 | 8/1/2023 | |
0.7.1 | 243 | 8/3/2023 | |
0.7.0.28-preview | 242 | 7/28/2023 | |
0.7.0.27-preview | 251 | 7/28/2023 | |
0.7.0.26-preview | 258 | 7/27/2023 | |
0.7.0.23-preview | 268 | 7/27/2023 | |
0.7.0.22-preview | 244 | 7/27/2023 | |
0.7.0.21-preview | 210 | 7/27/2023 | |
0.7.0.20-preview | 220 | 7/27/2023 | |
0.7.0 | 177 | 7/31/2023 | |
0.6.3.10 | 202 | 7/26/2023 | |
0.6.3.9 | 181 | 7/26/2023 | |
0.6.3.8 | 261 | 7/26/2023 | |
0.6.3.7-preview | 238 | 7/26/2023 | |
0.6.3.6-preview | 205 | 7/26/2023 | |
0.6.3.5-preview | 255 | 7/26/2023 | |
0.6.3.4-preview | 251 | 7/26/2023 |