Skip to content

Add .empty() method to response builder for no-body responses#1797

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-empty-method-to-responses
Open

Add .empty() method to response builder for no-body responses#1797
Copilot wants to merge 4 commits intomainfrom
copilot/add-empty-method-to-responses

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

Summary

Adds an .empty() method to the response builder to explicitly signal that a response has no body. Generated handler stubs for operations with no response content now call .empty() instead of returning the bare response object.

// Before (generated for DELETE /pet/{petId} with no body)
export const DELETE: deletePet = async ($) => {
  return $.response[400];
};

// After
export const DELETE: deletePet = async ($) => {
  return $.response[400].empty();
};
Original Prompt

Add an .empty() method where applicable to make the fact that a response has no body more explicit.

When generating code for a handler that has no response body, attach .empty().

Manual acceptance tests

  • A route handler generated from an OpenAPI operation with no response body (e.g., DELETE /pet/{petId}) contains .empty() in the generated stub
  • Calling .empty() on $.response[204] returns a response with the correct status and no body
  • Calling .empty() after .header(...) preserves the headers
  • A route with a response body (e.g., GET /pet/{petId}) is unchanged and still generates .random()
  • TypeScript: .empty() is available on a builder for a response with no content; it is absent (type error) when content is defined

Tasks

  • Added empty() to ResponseBuilder, WideResponseBuilder, and GenericResponseBuilderInner interfaces; typed as present only when [keyof Response["content"]] extends [never]
  • Implemented empty() in createResponseBuilder as { ...this, content: undefined }
  • Updated OperationCoder.write() to emit .empty() for no-body responses
  • Updated snapshots for operation-coder and end-to-end generate tests
  • Added unit and type-level tests
  • Documented .empty() in docs/reference.md
  • Resolved merge conflicts with main's counterfact-types refactor (one type per file with JSDoc comments); applied empty() changes to the new individual files (response-builder.ts, wide-response-builder.ts, generic-response-builder.ts)

Copilot AI linked an issue Apr 9, 2026 that may be closed by this pull request
@pmcelhaney pmcelhaney marked this pull request as ready for review April 9, 2026 01:52
Copilot AI changed the title [WIP] Add .empty() method for responses without body Add .empty() method to response builder for no-body responses Apr 9, 2026
Copilot AI requested a review from pmcelhaney April 9, 2026 01:54
@pmcelhaney pmcelhaney enabled auto-merge April 9, 2026 02:43
@pmcelhaney pmcelhaney added this pull request to the merge queue Apr 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Apr 9, 2026
@pmcelhaney
Copy link
Copy Markdown
Collaborator

@copilot address merge conflicts

Co-authored-by: pmcelhaney <51504+pmcelhaney@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

@copilot address merge conflicts

Merged main and resolved the conflicts (commit b386cf4). Main had refactored counterfact-types into one file per type — I applied the empty() changes to the new individual files (response-builder.ts, wide-response-builder.ts, generic-response-builder.ts) and preserved both my type tests and the new no-body response tests from main. All 43 test suites and type tests pass.

Copilot AI requested a review from pmcelhaney April 9, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.empty()

2 participants