Skip to content

feat: configurable depiction of the HEAD method#2872

Merged
RobinTail merged 8 commits intomasterfrom
feat-configurable-head-depiction
Aug 5, 2025
Merged

feat: configurable depiction of the HEAD method#2872
RobinTail merged 8 commits intomasterfrom
feat-configurable-head-depiction

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Aug 4, 2025

Based on #2791 (reply in thread)

Summary by CodeRabbit

  • New Features
    • Added an option to enable or disable the depiction of the HTTP HEAD method in generated API documentation and client integration.
    • By default, HEAD methods are included for endpoints that support GET; this can now be controlled with a new setting.
  • Documentation
    • Updated changelog to reflect the new minor version and feature.
    • Added a new contributor to the contributors section.
  • Tests
    • Enhanced tests to verify the new HEAD method option in both documentation and integration scenarios.

@RobinTail RobinTail added the enhancement New feature or request label Aug 4, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 4, 2025

Walkthrough

This change introduces a new hasHeadMethod boolean option to the Documentation and Integration classes, allowing users to enable or disable the depiction and handling of the HTTP HEAD method in generated API documentation and client integration. Related tests and documentation are updated, and a new contributor is credited.

Changes

Cohort / File(s) Change Summary
Changelog and Contributor Update
CHANGELOG.md, README.md
Adds a new minor version entry describing the feature and credits contributor @GreaterTamarack in README.
Documentation Class Option
express-zod-api/src/documentation.ts
Adds hasHeadMethod option to DocumentationParams and class, controlling whether HEAD methods are depicted.
Integration Class Option
express-zod-api/src/integration.ts
Adds hasHeadMethod option to IntegrationParams and class, controlling HEAD method generation.
Documentation Test
express-zod-api/tests/documentation.spec.ts
Updates test to set hasHeadMethod: false in a complex types scenario.
Integration Test
express-zod-api/tests/integration.spec.ts
Adds parameterized tests to verify default and disabled HEAD method handling in integration output.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Documentation
    participant Integration
    participant Router

    User->>Documentation: new Documentation({ hasHeadMethod })
    alt hasHeadMethod = true
        Documentation->>Router: walkRoutes(withHead(onEndpoint))
    else hasHeadMethod = false
        Documentation->>Router: walkRoutes(onEndpoint)
    end

    User->>Integration: new Integration({ hasHeadMethod })
    alt hasHeadMethod = true
        Integration->>Router: walkRoutes(withHead(onEndpoint))
    else hasHeadMethod = false
        Integration->>Router: walkRoutes(onEndpoint)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • RobinTail/express-zod-api#2816: Explores and documents Express's handling of the HEAD method, directly related to the new hasHeadMethod option's purpose and implementation.

Poem

A toggle for HEAD, so clever and neat,
Now docs and clients can skip or repeat.
With options in hand, contributors shine,
@GreaterTamarack, your work is divine!
The API grows, with tests in the mix—
Rabbits approve these toggly new tricks! 🐇

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 ee9c8de and 89f1894.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • express-zod-api/src/documentation.ts (3 hunks)
  • express-zod-api/src/integration.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • express-zod-api/src/integration.ts
  • express-zod-api/src/documentation.ts
  • CHANGELOG.md
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-configurable-head-depiction

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.
  • 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.

Support

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

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 4, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-configurable-head-depiction

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.
  • 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.

Support

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

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.

@coveralls-official
Copy link
Copy Markdown

coveralls-official Bot commented Aug 5, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling 58c57bf on feat-configurable-head-depiction
into c3aa525 on master.

@RobinTail RobinTail marked this pull request as ready for review August 5, 2025 19:00
Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (2)
CHANGELOG.md (2)

10-10: Minor grammar fix – missing verb

Handling the HEAD method the feature of Express is missing a verb.
Suggest: Handling the HEAD method is a feature of Express.


9-9: Clarity – add article before “HEAD method”

Depicts HEAD method for each Endpoint …Depicts the HEAD method for each endpoint … for consistency with surrounding text.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5a5165 and ee9c8de.

⛔ Files ignored due to path filters (2)
  • express-zod-api/tests/__snapshots__/documentation.spec.ts.snap is excluded by !**/*.snap
  • express-zod-api/tests/__snapshots__/integration.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • README.md (1 hunks)
  • express-zod-api/src/documentation.ts (3 hunks)
  • express-zod-api/src/integration.ts (3 hunks)
  • express-zod-api/tests/documentation.spec.ts (1 hunks)
  • express-zod-api/tests/integration.spec.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:11:20.768Z
Learning: In the express-zod-api repository, RobinTail follows a release workflow where package.json version is only updated on the master branch after merging all planned release changes. Changelog entries may show future version numbers while package.json remains at the previous version during feature development, and this is intentional workflow, not a version inconsistency that needs to be flagged.
📚 Learning: the type-only import `import type {} from "qs";` in express-zod-api/src/index.ts is necessary to avo...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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.

Applied to files:

  • express-zod-api/tests/integration.spec.ts
  • express-zod-api/src/integration.ts
  • express-zod-api/src/documentation.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: in express-zod-api tsup configurations, the direct mutation of `options.supported` in the `esbuildop...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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.

Applied to files:

  • express-zod-api/tests/integration.spec.ts
  • express-zod-api/src/integration.ts
  • express-zod-api/src/documentation.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: in express-zod-api/tests/zts.spec.ts, the `fruits` enum intentionally contains both string and numer...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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.

Applied to files:

  • express-zod-api/tests/integration.spec.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: in the express-zod-api project, tests are run from the `express-zod-api` workspace directory, and th...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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.

Applied to files:

  • express-zod-api/tests/integration.spec.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: the `cjs-test` directory in the express-zod-api repository is a test workspace and should be exclude...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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.

Applied to files:

  • express-zod-api/tests/integration.spec.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: in express-zod-api's `flattenio` function in json-schema-helpers.ts, the `additionalproperties` fiel...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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`.

Applied to files:

  • express-zod-api/src/integration.ts
  • express-zod-api/src/documentation.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: in express-zod-api, when migrating from zod v3 to v4, the correct approach for internal type imports...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-01T09:48:13.742Z
Learning: In express-zod-api, when migrating from Zod v3 to v4, the correct approach for internal type imports is to change from `import type { $ZodType } from "zod/v4/core"` to `import { z } from "zod"` and then use `z.core.$ZodType`. The zod/v4/core module is reexported as z.core by the main zod package, making this a valid and working approach.

Applied to files:

  • express-zod-api/src/integration.ts
  • express-zod-api/tests/documentation.spec.ts
📚 Learning: in express-zod-api, the `somemethod` type (defined as `lowercase`) is intentionally broad to...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#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.

Applied to files:

  • express-zod-api/src/integration.ts
📚 Learning: in express-zod-api, when working with zod's json schema override callbacks, using `delete` to mutate...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/src/documentation-helpers.ts:508-512
Timestamp: 2025-05-28T07:58:09.853Z
Learning: In express-zod-api, when working with Zod's JSON schema override callbacks, using `delete` to mutate `ctx.jsonSchema` is the recommended approach per Zod's official documentation, even if it triggers performance linting warnings. This is preferable to creating copies with `undefined` values, especially for snapshot testing.

Applied to files:

  • express-zod-api/src/integration.ts
📚 Learning: the `_zod` property in zod v4 schemas is officially documented and recommended for library authors t...
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/src/metadata.ts:5-13
Timestamp: 2025-05-27T20:08:50.699Z
Learning: The `_zod` property in Zod v4 schemas is officially documented and recommended for library authors to differentiate between Zod 3 and Zod 4 schemas at runtime, despite the underscore prefix. This is explicitly mentioned in Zod's library authors documentation and is not a private internal property.

Applied to files:

  • express-zod-api/src/integration.ts
🧬 Code Graph Analysis (2)
express-zod-api/src/integration.ts (1)
express-zod-api/src/routing-walker.ts (1)
  • withHead (15-20)
express-zod-api/src/documentation.ts (1)
express-zod-api/src/routing-walker.ts (1)
  • withHead (15-20)
⏰ 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). (5)
  • GitHub Check: build (24.x)
  • GitHub Check: build (22.12.0)
  • GitHub Check: build (22.x)
  • GitHub Check: build (20.19.0)
  • GitHub Check: build (20.x)
🔇 Additional comments (9)
README.md (1)

87-87: LGTM! Appropriate contributor recognition.

The addition of @GreaterTamarack to the contributors section follows the established format and properly acknowledges their contribution to the HEAD method feature.

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

50-54: Well-documented parameter addition.

The hasHeadMethod parameter is properly documented with clear JSDoc description and appropriate default value that maintains backward compatibility.


98-98: Consistent parameter handling.

The constructor parameter correctly defaults to true, ensuring backward compatibility while enabling the new feature.


157-157: Correct conditional implementation.

The conditional logic properly applies the withHead wrapper only when hasHeadMethod is true, allowing users to disable HEAD method generation for GET endpoints. This implementation is consistent with the same pattern used in documentation.ts.

express-zod-api/src/documentation.ts (3)

62-66: Consistent parameter documentation.

The hasHeadMethod parameter documentation matches the implementation in integration.ts, ensuring consistent behavior across documentation and client generation.


157-157: Backward-compatible default value.

The default value of true maintains existing behavior while enabling the new feature to disable HEAD method depiction.


265-265: Consistent implementation pattern.

The conditional logic mirrors the exact implementation in integration.ts (line 157), ensuring uniform behavior across both documentation generation and client integration when controlling HEAD method depiction.

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

55-55: Good test coverage for the new feature.

The addition of hasHeadMethod: false appropriately tests the new configurable HEAD method feature. This ensures the Documentation class correctly handles the option when HEAD method generation is disabled.

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

69-86: Excellent parameterized test for the HEAD method feature.

The test comprehensively covers both the default behavior (undefined) and explicit disable behavior (false) for the hasHeadMethod option in the Integration class. The test structure follows established patterns and uses appropriate snapshot testing to verify the generated output.

Copy link
Copy Markdown
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.

ready

@RobinTail RobinTail merged commit 9953a74 into master Aug 5, 2025
13 checks passed
@RobinTail RobinTail deleted the feat-configurable-head-depiction branch August 5, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant