-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce C# Source Generator and the .refitter file format #86
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updated the RefitGeneratorSettings.cs file to include JSON property names for each setting. This change provides better serialization and deserialization, ensuring the settings correctly map to their respective JSON keys when using System.Text.Json.
Added a suppression attribute to bypass the analyzer warning for the GenerateNamespaceImports method in RefitInterfaceImports file. Additionally, formatted the GetImportedNamespaces method for better readability and added System.Diagnostics.CodeAnalysis namespace to the using directives. The analyzer was giving a false positive for a supposedly banned API which is not actually the case, hence the decision to suppress this specific warning.
Modified the suppression annotation of the 'MicrosoftCodeAnalysisCorrectness' warning in the RefitInterfaceImports.cs file to specify that the justification for using banned APIs is because the tool is cross platform. This change better communicates the intent and context of the suppression to fellow developers.
… file in nuget package
Removed the RootNamespace from the Directory.Build.props file as it was redundant. Also, pruned surplus properties from the Refitter.Tests.csproj file, which mainly consisted of unnecessary configurations that were inherited by default. Simplifying these files enhances readability and allows for easier project management.
This commit removes the package and publish steps from the build cycle in both the build and release workflows. This change is made because packaging and publishing do not need to be part of the build process. They have been taken out to make the process cleaner and more efficient.
This reverts commit 99cd351.
Updated the language type of the code snippet in README.md file from 'json' to 'js' for the Refitter.SourceGenerator project. This change was done to enable syntax highlighting for comments in the code snippets, improving readability.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes here introduce a C# Source Generator that uses Refitter for generating a REST API Client using the Refit library. Refitter can generate the Refit interface from OpenAPI specifications
The source generator is distributed as a NuGet package called
Refitter.SourceGenerator
and should be installed to the project that will contain the generated codeUsage
This source generator generates code based on any
.refitter
file included to the project asAdditionalFiles
.The generator can automatically detect all
.refitter
files inside the project that referenced theRefitter.SourceGenerator
package and there is no need to include them manually asAdditionalFiles
File format
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
returnIApiResponse
- a boolean indicating whether to returnIApiResponse<T>
objects. Default isfalse
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
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 empty