-
Given this basic OpenApi: "get": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response"
} And when option [Get("/")]
Task<Response?> Get(); Why is With this code generation I basically have to always bang |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
@jods4 thanks for bringing this up. The option All that said, since Refitter generates the Refit interface, if a I'll play around with this a bit and see if we can find a good solution |
Beta Was this translation helpful? Give feedback.
-
@jods4 I looked into this a bit last night and can see that NSwag itself generates its interface as /// <summary>Find pet by ID</summary>
/// <param name="petId">ID of pet to return</param>
/// <returns>successful operation</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<Pet> GetPetByIdAsync(long petId); So I looked into the code a bit and found When I set the /// <summary>Find pet by ID</summary>
/// <remarks>Returns a single pet</remarks>
/// <param name="petId">ID of pet to return</param>
/// <returns>successful operation</returns>
/// <throws cref="ApiException">Thrown when the request returns a non-success status code.</throws>
[Headers("Accept: application/json")]
[Get("/pet/{petId}")]
Task<Pet> GetPetById(long petId); even though I set This looks like a bug in Refitter that is trivial to fix. My little concern here is that Refitter users have most likely just worked around this issue and introducing this "fix" would "break" things for others |
Beta Was this translation helpful? Give feedback.
-
The fix for this is released in version 0.9.6 |
Beta Was this translation helpful? Give feedback.
I understand your concerns; we had to "fix" this ourselves as well.
I don't see many ways to work around the current codegen: we either use
?.
or!
when accessing the response (I guess you could also checkx == null
).So I just verified this on SharpLab: none of those patterns warn when the type is changed to a non-nullable reference.
I guess the risk of breaking things is low?
Long term I think this is something worth fixing because when working with nullable reference the current behavior is just annoying and objectively wrong. If you want zero risk you could provide a setting to configure the codegen but that's maintenance burden for you.