Closed Nabushika closed 1 year ago
The response enums are enums because their variants encode the response body corresponding to the HTTP status code. ie ListResponse::<Pod>::Ok(l)
represents an HTTP response with status code OK and l: List<Pod>
body, while ListResponse::<Pod>::Other(o)
represents an HTTP response with all other status codes and o: serde_json::Value
body. It doesn't make sense to me to serialize the response enum as a whole to JSON, because such an impl would only serialize its variant data and the status code information would be lost. For the same reason I don't understand how your mocking would work as you described it, since just a Vec<u8>
by itself is not enough to deserialize the response. You need both status code and body to give to k8s_openapi::Response::try_from_parts
.
Ah, sorry - I think I must have got a little mixed up. List<T>
is definitely serializable, I was struggling with the trait bounds since I was dealing with a CRD and couldn't seem to construct a list.
Sorry for the clutter - closing this issue now.
Currently working on mocking API calls to Kubernetes using
tower_test
. The responses need to be in aVec<u8>
form for sending back from the mock API.This works, meaning I can mock individual
GET
methods:This does not, meaning I can't mock
api.list()
calls (or rather, I can't use Rust objects, and instead have to send back my own json manually):Can we add a
serde::Serialize
implementation forListResponse
, since we can serialize other objects?