oxidecomputer / oxidecomputer/progenitor
InvalidResponsePayload instead of Option::None for nullable api endpoint.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 136
- Avg merge
- 8h 36m
- Merged PRs (30d)
- 14
Description
I have an API endpoint that may return no response or some type Inode like this:
"/fs/resolve/{path}": {
"get": {
"operationId": "resolvePath",
"responses": {
"2XX": {
"description": "",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/Inode"
}
],
"nullable": true
}
}
}
}
},
"tags": [
"Filesystem"
],
"parameters": [
{
"in": "path",
"name": "path",
"required": true,
"schema": {
"type": "string"
}
}
]
}
},
typify correctly generates an Option type but if the API returns an empty body i get an InvalidResponsePayload error.
I tracked this down to serde being unable to parse an empty byte array b"" to an Option None here:
pub async fn from_response<E>(response: reqwest::Response) -> Result<Self, Error<E>> {
let status = response.status();
let headers = response.headers().clone();
let full = response.bytes().await.map_err(Error::ResponseBodyError)?;
let inner =
serde_json::from_slice(&full).map_err(|e| Error::InvalidResponsePayload(full, e))?;
Ok(Self {
inner,
status,
headers,
})
}
Can a case for this be added?
I already tried adding a specific 204 Response to the schema, but this fails with assertion failed: response_types.len() <= 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the generated from_response entry point shown in the report and reproduce the nullable endpoint's empty-body response. Inspect the surrounding response parsing and test coverage, then add a regression case that distinguishes an empty body from an invalid nonempty payload and verifies the expected Option behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100