Skip to content

Conversation

@RobinTail
Copy link
Owner

@RobinTail RobinTail commented Jul 29, 2025

Fixes #2858

Noticed by @coderabbitai in #2857 (comment)

Summary by CodeRabbit

  • Documentation

    • Updated API documentation for several HEAD endpoints to remove detailed error response content, reflecting that no payload is returned for negative responses.
  • Refactor

    • Simplified logic for determining response content in HEAD requests, now relying solely on the HTTP method.
    • Streamlined type definitions for negative responses of HEAD endpoints to indicate no content is returned.
  • Tests

    • Updated tests to align with the simplified response content logic for HEAD requests.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

This change updates the handling of negative responses for HTTP HEAD endpoints by ensuring they return no body, aligning both type definitions and OpenAPI documentation accordingly. Supporting helper functions and tests are adjusted to treat all HEAD responses as body-less, regardless of response variant.

Changes

Cohort / File(s) Change Summary
Client Type Definitions
example/example.client.ts
Negative response types for several HEAD endpoints changed to undefined, removing error payloads.
OpenAPI Documentation
example/example.documentation.yaml
Removed content schemas and example payloads from negative responses for HEAD endpoints.
Helper Logic & Integration
express-zod-api/src/common-helpers.ts,
express-zod-api/src/documentation-helpers.ts,
express-zod-api/src/integration.ts
Simplified doesImplyContent logic to depend only on HTTP method; removed response variant consideration.
Tests
express-zod-api/tests/common-helpers.spec.ts
Updated tests for doesImplyContent to remove response variant checks and assert only on method.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    Client->>API: HEAD /v1/user/retrieve
    API-->>Client: Response headers (no body, regardless of error)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
HEAD responses must always have empty bodies, even for error responses (#2858)
Remove error payloads from negative HEAD responses in client types and OpenAPI spec (#2858)
Ensure helper logic and tests treat all HEAD responses as body-less, regardless of variant (#2858)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

  • RobinTail/express-zod-api#2816: Implements and documents correct HTTP HEAD method handling, focusing on headers and streaming, which is related to HEAD response handling in this PR.

Suggested labels

bug

Poem

A HEAD request comes, but brings no tale,
No error, no message, no body to unveil.
Just headers remain, silent and neat—
The code’s now aligned, a tidy feat!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ceafbb6 and 71a30cf.

📒 Files selected for processing (1)
  • CHANGELOG.md (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (22.0.0)
  • GitHub Check: build (22.x)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-2858-head-negative

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a92c610 and 1dae667.

⛔ Files ignored due to path filters (1)
  • express-zod-api/tests/__snapshots__/documentation.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • example/example.client.ts (5 hunks)
  • example/example.documentation.yaml (0 hunks)
  • express-zod-api/src/common-helpers.ts (1 hunks)
  • express-zod-api/src/documentation-helpers.ts (1 hunks)
  • express-zod-api/src/integration.ts (1 hunks)
  • express-zod-api/tests/common-helpers.spec.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • example/example.documentation.yaml
🧰 Additional context used
🧠 Learnings (5)
express-zod-api/src/integration.ts (3)

Learnt from: RobinTail
PR: #2736
File: express-zod-api/tsup.config.ts:12-26
Timestamp: 2025-06-14T16:42:52.972Z
Learning: In express-zod-api tsup configurations, the direct mutation of options.supported in the esbuildOptions callback is intentional behavior and should not be flagged as a side effect issue.

Learnt from: RobinTail
PR: #2428
File: express-zod-api/src/index.ts:44-44
Timestamp: 2025-05-28T18:58:10.064Z
Learning: The type-only import import type {} from "qs"; in express-zod-api/src/index.ts is necessary to avoid TS2742 errors for exported functions like attachRouting, makeRequestMock, testEndpoint, and testMiddleware that have types depending on @types/qs. This import provides the reference TypeScript needs to infer portable type names.

Learnt from: RobinTail
PR: #2833
File: express-zod-api/src/method.ts:3-3
Timestamp: 2025-07-20T11:09:58.980Z
Learning: In express-zod-api, the SomeMethod type (defined as Lowercase<string>) is intentionally broad to represent raw, unvalidated HTTP methods from requests. The narrower Method type is used after validation with isMethod(). This defensive programming pattern separates raw external input types from validated types, allowing graceful handling of unknown methods.

express-zod-api/src/common-helpers.ts (5)

Learnt from: RobinTail
PR: #2428
File: express-zod-api/src/index.ts:44-44
Timestamp: 2025-05-28T18:58:10.064Z
Learning: The type-only import import type {} from "qs"; in express-zod-api/src/index.ts is necessary to avoid TS2742 errors for exported functions like attachRouting, makeRequestMock, testEndpoint, and testMiddleware that have types depending on @types/qs. This import provides the reference TypeScript needs to infer portable type names.

Learnt from: RobinTail
PR: #2736
File: express-zod-api/tsup.config.ts:12-26
Timestamp: 2025-06-14T16:42:52.972Z
Learning: In express-zod-api tsup configurations, the direct mutation of options.supported in the esbuildOptions callback is intentional behavior and should not be flagged as a side effect issue.

Learnt from: RobinTail
PR: #2546
File: express-zod-api/src/json-schema-helpers.ts:75-87
Timestamp: 2025-05-27T20:40:19.548Z
Learning: In express-zod-api's flattenIO function in json-schema-helpers.ts, the additionalProperties field is used as a template to generate property schemas for literal property names extracted from propertyNames.const and propertyNames.enum. Converting boolean additionalProperties values to empty objects {} via Object(entry.additionalProperties) is intentional behavior, as the function only needs property schema templates, not the boolean semantics of additionalProperties.

Learnt from: RobinTail
PR: #2833
File: express-zod-api/src/method.ts:3-3
Timestamp: 2025-07-20T11:09:58.980Z
Learning: In express-zod-api, the SomeMethod type (defined as Lowercase<string>) is intentionally broad to represent raw, unvalidated HTTP methods from requests. The narrower Method type is used after validation with isMethod(). This defensive programming pattern separates raw external input types from validated types, allowing graceful handling of unknown methods.

Learnt from: RobinTail
PR: #2546
File: express-zod-api/src/io-schema.ts:5-8
Timestamp: 2025-05-28T05:04:40.327Z
Learning: The Base type object & { [Symbol.iterator]?: never } in express-zod-api correctly excludes arrays and other iterables from IOSchema. Arrays are properly rejected because they have a defined Symbol.iterator method which conflicts with the never constraint, as demonstrated by TypeScript compiler errors when attempting to assign z.array() to IOSchema.

express-zod-api/src/documentation-helpers.ts (2)

Learnt from: RobinTail
PR: #2736
File: express-zod-api/tsup.config.ts:12-26
Timestamp: 2025-06-14T16:42:52.972Z
Learning: In express-zod-api tsup configurations, the direct mutation of options.supported in the esbuildOptions callback is intentional behavior and should not be flagged as a side effect issue.

Learnt from: RobinTail
PR: #2428
File: express-zod-api/src/index.ts:44-44
Timestamp: 2025-05-28T18:58:10.064Z
Learning: The type-only import import type {} from "qs"; in express-zod-api/src/index.ts is necessary to avoid TS2742 errors for exported functions like attachRouting, makeRequestMock, testEndpoint, and testMiddleware that have types depending on @types/qs. This import provides the reference TypeScript needs to infer portable type names.

express-zod-api/tests/common-helpers.spec.ts (6)

Learnt from: RobinTail
PR: #2736
File: express-zod-api/tsup.config.ts:12-26
Timestamp: 2025-06-14T16:42:52.972Z
Learning: In express-zod-api tsup configurations, the direct mutation of options.supported in the esbuildOptions callback is intentional behavior and should not be flagged as a side effect issue.

Learnt from: RobinTail
PR: #2428
File: express-zod-api/src/index.ts:44-44
Timestamp: 2025-05-28T18:58:10.064Z
Learning: The type-only import import type {} from "qs"; in express-zod-api/src/index.ts is necessary to avoid TS2742 errors for exported functions like attachRouting, makeRequestMock, testEndpoint, and testMiddleware that have types depending on @types/qs. This import provides the reference TypeScript needs to infer portable type names.

Learnt from: RobinTail
PR: #2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:08:56.475Z
Learning: The cjs-test directory in the express-zod-api repository is a test workspace and should be excluded when checking for main project version consistency with changelog entries.

Learnt from: RobinTail
PR: #2546
File: express-zod-api/tests/buffer-schema.spec.ts:32-37
Timestamp: 2025-05-27T19:35:57.357Z
Learning: In the express-zod-api project, tests are run from the express-zod-api workspace directory, and the project uses an ESM-first environment without __dirname. Relative paths like ../logo.svg in test files correctly resolve to the repository root due to this test execution context.

Learnt from: RobinTail
PR: #2546
File: express-zod-api/tests/zts.spec.ts:160-162
Timestamp: 2025-05-27T20:22:30.428Z
Learning: In express-zod-api/tests/zts.spec.ts, the Fruits enum intentionally contains both string and numeric members (Apple = "apple", Banana = "banana", Cantaloupe = "cantaloupe", A = 5) and is used with z.enum(Fruits) to test how the system handles mixed enum types. This is by design for testing purposes.

Learnt from: RobinTail
PR: #2546
File: express-zod-api/src/json-schema-helpers.ts:75-87
Timestamp: 2025-05-27T20:40:19.548Z
Learning: In express-zod-api's flattenIO function in json-schema-helpers.ts, the additionalProperties field is used as a template to generate property schemas for literal property names extracted from propertyNames.const and propertyNames.enum. Converting boolean additionalProperties values to empty objects {} via Object(entry.additionalProperties) is intentional behavior, as the function only needs property schema templates, not the boolean semantics of additionalProperties.

example/example.client.ts (1)

Learnt from: RobinTail
PR: #2428
File: express-zod-api/src/index.ts:44-44
Timestamp: 2025-05-28T18:58:10.064Z
Learning: The type-only import import type {} from "qs"; in express-zod-api/src/index.ts is necessary to avoid TS2742 errors for exported functions like attachRouting, makeRequestMock, testEndpoint, and testMiddleware that have types depending on @types/qs. This import provides the reference TypeScript needs to infer portable type names.

🧬 Code Graph Analysis (4)
express-zod-api/src/integration.ts (1)
express-zod-api/src/common-helpers.ts (1)
  • doesImplyContent (145-145)
express-zod-api/src/common-helpers.ts (1)
express-zod-api/src/method.ts (1)
  • ClientMethod (35-35)
express-zod-api/src/documentation-helpers.ts (1)
express-zod-api/src/common-helpers.ts (1)
  • doesImplyContent (145-145)
express-zod-api/tests/common-helpers.spec.ts (1)
express-zod-api/src/common-helpers.ts (1)
  • doesImplyContent (145-145)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (24.x)
  • GitHub Check: build (20.9.0)
🔇 Additional comments (9)
express-zod-api/src/common-helpers.ts (1)

145-145: LGTM! Correctly implements HTTP HEAD standard behavior.

The simplified logic correctly ensures that HEAD requests never imply content, regardless of response status. This aligns with HTTP standards where HEAD responses must always have an empty body, whether the response is successful (200) or an error (400/500).

express-zod-api/src/integration.ts (1)

110-110: LGTM! Correctly updated to match simplified function signature.

The function call now properly matches the updated doesImplyContent signature, removing the responseVariant parameter. The logic correctly determines content presence based on mimeTypes and method only.

express-zod-api/tests/common-helpers.spec.ts (1)

339-341: LGTM! Test correctly verifies HEAD behavior.

The test properly verifies that HEAD requests return false, aligning with the simplified function logic and HTTP standards.

express-zod-api/src/documentation-helpers.ts (1)

502-502: LGTM! Correctly updated for simplified function signature.

The function call properly removes the variant parameter to match the updated doesImplyContent signature. This ensures HEAD responses in OpenAPI documentation won't include content schemas regardless of response status.

example/example.client.ts (5)

57-57: LGTM! Correctly implements HEAD response behavior.

The change from a structured error object to undefined correctly reflects that HEAD responses should never contain body content, even for error cases.


196-196: LGTM! Consistent with HEAD response standards.

Changing from string to undefined ensures HEAD error responses don't include content, maintaining consistency with HTTP standards.


238-238: LGTM! Properly enforces empty HEAD response body.

The type change ensures avatar endpoint HEAD errors return no content, aligning with the PR objective.


280-280: LGTM! Maintains consistent HEAD behavior.

Stream endpoint HEAD error responses correctly changed to return no content.


393-393: LGTM! Completes consistent HEAD response handling.

Events stream HEAD error responses now properly return no content, completing the consistent implementation across all endpoints.

@RobinTail RobinTail added the refactoring The better way to achieve the same result label Jul 29, 2025
Copy link
Owner Author

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@RobinTail RobinTail merged commit 54b806d into master Jul 29, 2025
13 checks passed
@RobinTail RobinTail deleted the issue-2858-head-negative branch July 29, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prevention refactoring The better way to achieve the same result

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative response to HEAD request should also have no body

2 participants