-
Notifications
You must be signed in to change notification settings - Fork 77
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
Should dropshot endpoints be able to return Option<T>
?
#669
Comments
I vote for rejecting it. I don't see why we would ever want to return |
If there is a technical reason this can't or shouldn't be done, that's fine. Given that at least two of us have hit this problem, then "I don't need it, so nobody else should either" doesn't seem like a compelling argument. |
I didn't realize you were saying you want to be able to return |
This is my specific use case:
We're asking for the details of a fault condition on a link. If the link doesn't have a fault at the moment, I want to return I'm currently using a workaround suggested by John:
If it's complicated or undesirable to support |
I'm not sure whether it makes sense to return |
Agree with the consensus that what we're doing now is wrong. A maximally accurate approach for an interface that sometimes returns a pile of data and sometimes doesn't would be to support multiple response codes e.g. 200 and 204/404 as @davepacheco suggested above. I'm not sure how we could generically support multiple success responses. Perhaps it would suffice to have a type like While I like this a lot and thing it might be the best direction, it would necessitate progenitor work--currently we assume a single success response type (and single error response type). This is, however, directionally work I think we should do in progenitor as well. I suppose there's nothing overtly wrong about a 200 response with content "responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"nullable": true,
"allOf": [
{
"$ref": "#/components/schemas/Foo"
}
]
}
}
}
}, That said, I think we'd do better to steer people away from this approach as we've steered people away from the |
Just an FYI that I hit this tonight and @gjcolombo pointed me here. For my use case I can use a |
Today, these two endpoints:
produce identical OpenAPI definitions:
This is surprising/wrong, and causes generated clients to not realize that
get_option_foo()
might returnNone
/null
instead of aFoo
. It's relatively easy to work around this by returning a struct that contains anOption
. I don't know if returning anOption
directly should work; if not, could we reject it at compile time somehow?The text was updated successfully, but these errors were encountered: