oxidecomputer / oxidecomputer/progenitor

InvalidResponsePayload instead of Option::None for nullable api endpoint.

Open
#1,197 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.