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

[Bug]: Nullable return types. Cannot implement null result #1585

Open
liven-maksim-infotecs opened this issue Oct 23, 2023 · 0 comments
Open
Labels

Comments

@liven-maksim-infotecs
Copy link

liven-maksim-infotecs commented Oct 23, 2023

Describe the bug 🐞

Methods with nullable response types have not null default value. It's an implementation of dto class with default fields.

Step to reproduce

  1. Create an api with method that returns NotFound if id == 0 (e.x.)
[HttpGet()]
async Task<ActionResult<SomeDto>> Get(int id, CancellationToken token)
{
     if (id == 0) {
         return NotFound();
     }
     
     return await dataFactory.CreateAsync(id, token);
}
  1. Create api client interface for this method
public interface ISomeClient {
     [Get("api/some")]
     Task<SomeDto?> GetById(int id);
}
  1. Chagne refit settings with custom exception factory to handle 404 Not Found
public Task<Exception?> CreateAsync(HttpResponseMessage responseMessage) =>
        responseMessage.StatusCode == HttpStatusCode.NotFound
            ? Task.FromResult<Exception?>(null)
            : factory.CreateAsync(responseMessage);
  1. Invoke web request with refit-generated client with id = 0;
  2. Result is not null but a dto instance with default field values.

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

Generated client's method reposonse type must be nullable, default value for this method must be null instead of dto instance with default fields.

Screenshots 🖼️

image
image

IDE

Inteliji Rider

Operating system

Windows

Version

21H2 19044.3570

Device

PC

Refit Version

7.0.0

Additional information ℹ️

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant