Open smietanka opened 3 months ago
@smietanka Thanks for taking the time to report this
- This command is generating me only one file for interfaces named
RefitInterfaces.cs
andContracts.cs
but I would like to see multiple clients with proper names likeICoolClient
andIWeatherForecastClient
with methods that belong only to these specific controllers. I have used--multiple-interfaces ByTag
option and its looks pretty fine, but is there an option to split these interfaces into different files?
From v1.2.1 you can split the output into multiple files, but it's pretty primitive and can only split it into 3 files:
Technically, it's possible to split up the Refit interfaces into multiple files. I designed the system in a way that I should be able to easily.
- About contracts, they are as well only inside one file. I would really like to see multiple files with proper names of classes. Classes are generated fine with all properties, but why it is the single file? I would like to see just files with names of the contract. For example:
Error.cs
,User.cs
, etc.
I piggy-back on NSwag for parsing the OpenAPI spec and generating contracts. I get all contracts generated as a single string and I don't intend to analyze and break that single large string down into multiple files. If I can find a way to use NSwag to generate single contracts at a time then I will in the future add support for generating multiple files for the contracts
- Inside the
Contracts.cs
I see a lot of disabled warnings. Is there a way to pass some kind of settings/configuration to the NSwag from Refitter?
I haven't figured out a way to get NSwag to not disable warnings. This is common practice in code generators as they have to support multiple versions of the framework. Refitter (and NSwag) generates code that is compatible with .NET Framework 4.x -> .NET Standard 2.0 -> .NET Core 9.0
It's probably a personal thing, but I treat generated code like pulling in a third-party library and I don't care much about how to structure code that I didn't write. That said, the way I use Refitter is to generate "Client SDK's" for the API's that I build from the CI/CD platform that I use
- Is there a way to pass a summary as well (not only returns) of the method to the generated Refit interface? For now it looks like this
Refitter purely looks at the OpenAPI spec and maps the details in paths
to xml docs in the following way:
I'm generally very open to pull requests so if you have ideas or things you want to add to Refitter that you think you can build yourself then I'll make sure that if you create a pull request we get your changes in 😄
Thanks for your response :)
Yeah, splitting files for each client would be really useful not only for readability but also for git history, etc. Basically, all kinds of splitting contracts or interfaces into different files would really help with git history :)
AddSwaggerGen
now summaries are correctly passed into swagger.json
:)Thanks I will try to check the code what could be changed here
Hey, I just started working with Refitter a couple of days ago. It's a really cool tool, but it seems like a couple of options are not working as expected (or I am missing something), and I do have a problem with creating a proper configuration and parameters for the CLI command to generate contracts and interfaces.
So my case looks like this, I need to build interfaces and contracts after each build of project. I have an ASP.NET WebAPI with two controllers and some models, for now just as simple as possible. So I have created a "refitter.targets" file which I included inside the
.csproj
of my API. Inside targets I have couple<Exec command>
targets where I am callingdotnet tool restore
,dotnet tool update
and of course this commanddotnet refitter $(OpenApiDocumentation) -o $(RefitterOutputDirectory) -n $(ProjectName).Client --contracts-output $(RefitterContractsOutputDirectory) --contracts-namespace $(ProjectName).Contract --no-accept-headers --use-api-response --cancellation-tokens
As I mentioned I have 2 controllers named:
CoolController
andWeatherForecastController
RefitInterfaces.cs
andContracts.cs
but I would like to see multiple clients with proper names likeICoolClient
andIWeatherForecastClient
with methods that belong only to these specific controllers. I have used--multiple-interfaces ByTag
option and its looks pretty fine, but is there an option to split these interfaces into different files?Error.cs
,User.cs
, etc.Contracts.cs
I see a lot of disabled warnings. Is there a way to pass some kind of settings/configuration to the NSwag from Refitter?I really appreciate any help you can provide.