You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The Wolverine docs make it seem like the [Document] attribute returns status code 404 for not-found NULL documents by default.
The first example for the [Document] is this:
[WolverineGet("/invoices/longhand/id")][ProducesResponseType(404)][ProducesResponseType(200, Type =typeof(Invoice))]publicstaticasyncTask<IResult>GetInvoice(Guidid,IQuerySessionsession,CancellationTokencancellationToken){varinvoice=await session.LoadAsync<Invoice>(id, cancellationToken);if(invoice==null)return Results.NotFound();return Results.Ok(invoice);}
That is a bit misleading tho, because there is actually no check for NULL in the second code.
When the document does not exist, the Get(...) handler will still be called, but with NULL for the invoice variable.
A while back the DocumentAttribute.Required property was added to change this behavior, but for backward compatibility reasons the property is false by default.
This code will actually throw a NullReferenceException at invoice.Approved = true when the invoice document with the given number doesn't exist.
Describe the solution you'd like
I suggest the DocumentAttribute.Required property should be changed to true by default.
This corresponds to what I expect from this functionality after reading the docs.
Describe alternatives you've considered
Change the docs to make it more clear, that the handler might be called with NULL.
Additional context
Briefly talked about this suggestion here before.
The text was updated successfully, but these errors were encountered:
haefele
added a commit
to haefele/wolverine
that referenced
this issue
Sep 1, 2024
Is your feature request related to a problem? Please describe.
The Wolverine docs make it seem like the
[Document]
attribute returns status code 404 for not-foundNULL
documents by default.The first example for the
[Document]
is this:Turns into this way simpler and shorter code:
That is a bit misleading tho, because there is actually no check for
NULL
in the second code.When the document does not exist, the
Get(...)
handler will still be called, but withNULL
for theinvoice
variable.A while back the
DocumentAttribute.Required
property was added to change this behavior, but for backward compatibility reasons the property isfalse
by default.Notably, the second handler will still return
404
forNULL
documents, but only because the return value of the handler is null.Another misleading example from the docs is this:
This code will actually throw a
NullReferenceException
atinvoice.Approved = true
when the invoice document with the given number doesn't exist.Describe the solution you'd like
I suggest the
DocumentAttribute.Required
property should be changed totrue
by default.This corresponds to what I expect from this functionality after reading the docs.
Describe alternatives you've considered
Change the docs to make it more clear, that the handler might be called with
NULL
.Additional context
Briefly talked about this suggestion here before.
The text was updated successfully, but these errors were encountered: