Skip to content
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

Generating IObservable type response #322

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

janfolbrecht
Copy link

Refit supports also IObservable reactive response type in interfaces so I added this feature to Refitter because it was missing.
I added property ReturnIApiResponse to Settings and RefitGeneratorSettings
It replaces System.Threading.Task import by System.Reactive and it generates IObservable instead of Task and IObservable<> instead of Task<>.
I added one unit test to test generated output is compilable. I had to add Unit class manually to mock missing System.Reactive.Unit class.

@christianhelle christianhelle self-assigned this Feb 21, 2024
@christianhelle christianhelle added enhancement New feature, bug fix, or request .NET Pull requests that contain changes to .NET code labels Feb 21, 2024
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.33%. Comparing base (67e06eb) to head (0b3e451).
Report is 37 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #322   +/-   ##
=======================================
  Coverage   97.33%   97.33%           
=======================================
  Files          63       63           
  Lines        2398     2402    +4     
=======================================
+ Hits         2334     2338    +4     
  Misses         40       40           
  Partials       24       24           
Flag Coverage Δ
unittests 97.33% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

settings.ReturnIObservable = true;
var generateCode = await GenerateCode(version, filename, settings);
//cannot build without it because System.Reactive package has to be installed first
generateCode += @"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add the System.Reactive package reference to the ProjectFileContents.cs file

<PackageReference Include=""System.Reactive"" Version=""6.0.0"" />

so you don't need to insert a fake Unit type

@christianhelle
Copy link
Owner

@all-contributors please add @janfolbrecht for ideas and code

Copy link
Contributor

@christianhelle

I've put up a pull request to add @janfolbrecht! 🎉

src/Refitter.Core/RefitInterfaceImports.cs Show resolved Hide resolved
}

private string GetAsyncOperationType(bool withVoidReturnType) =>
settings.ReturnIObservable
? "IObservable" + (withVoidReturnType ? "<Unit>" : string.Empty)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much experience working with IObservable<T> but why do we need Unit? What does it do and what is it for?

The examples in the Refit README uses an HttpResponseMessage together with IObservable

// Returns the raw response, as an IObservable that can be used with the
// Reactive Extensions
[Get("/users/{user}")]
IObservable<HttpResponseMessage> GetUser(string user);

@janfolbrecht
Copy link
Author

janfolbrecht commented Feb 22, 2024 via email

@christianhelle
Copy link
Owner

@janfolbrecht are you up for fixing the things I suggested? I perfectly understand if don't feel like it and since the requested changes are trivial I can easily do this myself so we can get this merged

@janfolbrecht
Copy link
Author

janfolbrecht commented Feb 22, 2024 via email

Copy link
Owner

@christianhelle christianhelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janfolbrecht I'll mark this pull request as approved. If you're still up for making the last changes then I can wait with merging, and I will re-review your incoming changes.

I don't mind doing the suggested changes myself if you would rather have it that way

@janfolbrecht
Copy link
Author

Thank you. If you can make suggested changes please do it. Jan

@christianhelle christianhelle merged commit c5e8e06 into christianhelle:main Feb 26, 2024
336 of 742 checks passed
Copy link

sonarcloud bot commented Feb 26, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@christianhelle
Copy link
Owner

@janfolbrecht this contribution is now released to nuget.org as v0.9.8

thanks again!

@janfolbrecht
Copy link
Author

janfolbrecht commented Feb 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request .NET Pull requests that contain changes to .NET code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants