Skip to content

fix(cli): omit optional OpenAPI request bodies #52

Description

@robinbraemer

Defect

Commands generated from an OpenAPI operation with requestBody.required: false still send a JSON null payload when their input omits body. That changes an absent body into a present invalid value.

The production dogfood command akua order-drafts create-worker-bootstrap --input - with only { "path": { "id": "..." } } received 422 Invalid input: expected object, received null, although the public contract marks its JSON body optional.

Reproduction

A local intercepted-transport run of the current CLI executor with the analogous optional-body machines.update operation and input { "path": { "id": "mch_capture" }, "headers": { "if-match": "0" } } captured:

PATCH https://api.akua.dev/v1/machines/mch_capture
Content-Type: application/json
body: null

No request reached production during this reproduction.

origin/main retains the same generated shape for orderDrafts.createWorkerBootstrap:

  • openapi/public.json declares requestBody.required: false.
  • src/generated/public-operation-executor.gen.ts maps omitted input.body to payload: undefined but still passes the payload field.
  • src/generated/openapi-api.gen.ts represents the request as [RequestJson, HttpApiSchema.NoContent].
  • Effect HttpApiClient then encodes the NoContent branch using its default JSON payload encoding, yielding null.

No existing akua-dev/cli issue matched optional bodies, null payloads, or NoContent.

Acceptance criteria

  • Omitting body for every optional JSON request body sends no request bytes and no Content-Type header.
  • Supplying body: {} or an allowed populated object still sends the JSON object and validates it strictly.
  • Explicit body: null remains a client-side input validation error.
  • A generated-command regression test covers orderDrafts.createWorkerBootstrap (including its colon-suffixed path) and one ordinary optional-body operation.
  • Required request bodies continue to fail before transport when omitted.

Scope

Fix the generic OpenAPI/Effect client generation or request serialization boundary; do not add a handwritten exception for worker bootstrap.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions