Closed DenisNovac closed 3 years ago
This looks suspicious:
.errorOut(statusCode)
.errorOut(
oneOf(
statusMapping(StatusCode.Forbidden, emptyOutput),
statusMapping(StatusCode.InternalServerError, emptyOutput)
)
you should either return the status code as a value from the code, or provide mappings based on the type of the value being returned.
If you'd like to document possible status codes, you can do it using .errorOut(statusCode.description(Forbidden, "..."))
This looks suspicious:
Agree, but it is kinda works. At least i can see this codes in Swagger.
you should either return the status code as a value from the code, or provide mappings based on the type of the value being returned.
If you'd like to document possible status codes, you can do it using
.errorOut(statusCode.description(Forbidden, "..."))
But how do i describe several status codes without statusMapping? If i do like this:
endpoint.post
.in("auth")
.in(jsonBody[Authorize])
.out(setCookie("sessionid"))
.tag("Auth")
.summary("Sign in with user id and password")
.errorOut(statusCode.description(StatusCode.Forbidden, "Invalid user ID or password"))
.errorOut(statusCode.description(StatusCode.InternalServerError, "Unknown error"))
My signature becomes Endpoint[Authorize, (StatusCode, StatusCode), CookieValueWithMeta, Nothing]
Won't
.errorOut(statusCode
.description(StatusCode.Forbidden, "Invalid user ID or password")
.description(StatusCode.InternalServerError, "Unknown error"))
work? You need a single status code, otherwise tapir gets confused ;) That's a separate feature, that we should add, that there are no conflicting inputs/outputs int he endpoint description (that would be validated at run-time, when the description is created)
Oh, now i understand. Chained description
calls works, thank you. I still don't understand why emptyOutput
fails though. Is there any other application to it except for oneOf
with StatusMapping
?
I think oneOf
is the only application. Though the types in the branches should be distinct, so that the right status code can be picked depending on the outcome of the logic function.
The problem seems to be with multiple status outputs, but I would have to debug to say precisely what happened.
Closing as either the problem has been solved, or lacks details. Plus the oneOf
design changed in 0.18.0-M1
Tapir version: 0.15
Describe the bug
Hello. I have this code:
And the controller which does something like this:
In this implementation it gives just errors:
I tried to change it like this so the value in mapping is not Unit:
It does not work either:
Both implementations always returns 500. Also in second version of code there is no error codes in swagger interface.
Shouldn't the signature of emptyOutput be like "EndpointIO.Empty[Unit]"? It is not possible to reach
description
method through EndpointOutput type: