Skip to content

Conversation

@RobinTail
Copy link
Owner

@RobinTail RobinTail commented Jul 29, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Corrected the negative response MIME type for deprecated error handling to use "text/plain" instead of "application/json" in both documentation and response handling.
  • Documentation

    • Updated the changelog to reflect the fix for the negative response MIME type.
    • Adjusted API documentation to specify "text/plain" as the content type for certain error responses.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

The changes update the negative response MIME type for the deprecated arrayResultHandler to text/plain in both documentation and code. The OpenAPI specification for the /v1/user/list endpoint's error responses is also updated to use text/plain. A changelog entry for version 24.7.2 documents these adjustments.

Changes

Cohort / File(s) Change Summary
Changelog Update
CHANGELOG.md
Added entry for version 24.7.2, documenting the fix for the negative response MIME type.
OpenAPI Spec Error Response Update
example/example.documentation.yaml
Changed the "400" error response content type for /v1/user/list GET and HEAD methods from application/json to text/plain.
Result Handler MIME Type Fix
express-zod-api/src/result-handler.ts
Modified the negative property of arrayResultHandler to include both a schema and a mimeType of text/plain.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~6 minutes

Suggested labels

enhancement, documentation

Poem

A changelog grows, a MIME type mends,
Error responses now make amends.
From JSON to plain, the message is clear,
In docs and code, improvements appear.
A rabbit hops by, quite pleased with the fix—
Simpler responses, no more MIME tricks!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

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

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-neg-arr-rh-mime

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

ok

@coveralls-official
Copy link

Coverage Status

coverage: 100.0%. remained the same
when pulling 70a97b4 on fix-neg-arr-rh-mime
into 77e378e on master.

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: 0

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

7-8: Minor grammar touch-up for clarity

Consider replacing “Should have been” with “It should be” (or “It should have been”) so the sentence reads more naturally.

-  - Should have been `text/plain`.
+  - It should have been `text/plain`.
example/example.documentation.yaml (1)

458-465: HEAD responses generally shouldn’t declare a body
HEAD must not send a payload, yet the spec advertises text/plain.
If the implementation indeed returns an empty body (typical), consider dropping the entire content block to avoid misleading clients.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 77e378e and 70a97b4.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • example/example.documentation.yaml (2 hunks)
  • express-zod-api/src/result-handler.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
express-zod-api/src/result-handler.ts (4)

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.

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: #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/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.

CHANGELOG.md (1)

Learnt from: RobinTail
PR: #2546
File: express-zod-api/tests/form-schema.spec.ts:31-31
Timestamp: 2025-05-27T19:27:13.492Z
Learning: Zod version 3.25.0 and later expose the Zod v4 API through the special import paths "zod/v4" and "zod/v4/core", allowing v4 features like .loose() to be used even when the package.json dependency shows a 3.x version.

⏰ 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). (1)
  • GitHub Check: report
🔇 Additional comments (2)
express-zod-api/src/result-handler.ts (1)

172-175: LGTM! Metadata now aligns with implementation behavior.

The change correctly updates the negative response metadata to explicitly specify text/plain MIME type, which matches the actual handler implementation that uses .type("text/plain") and .send() on lines 182-183. This ensures proper OpenAPI documentation generation.

example/example.documentation.yaml (1)

442-449: Confirm text/plain only for deprecated arrayResultHandler endpoints
The switch to text/plain for the GET /v1/user/list 400-response is correct. All other 4xx responses still use application/json, which is expected for endpoints that return structured error objects.

Please double-check that no other endpoints backed by the now-deprecated arrayResultHandler still expose errors as application/json. You can search your codebase for the handler’s usage and cross-reference those routes in your documentation.

• example/example.documentation.yaml lines 422–426 & 442–449 (GET /v1/user/list) – now text/plain
• Other negative responses (e.g. POST /v1/user/create 400/409, HEAD/GET /v1/user/retrieve 4xx) – remain application/json
• If any of those belong to arrayResultHandler, update their docs to text/plain

@RobinTail
Copy link
Owner Author

@coderabbitai

458-465: HEAD responses generally shouldn’t declare a body

No body for a successfully handled request (status code 200).
But if there was an error while handling the request (status code 400), then it can be body of the response to explain the error. Isn't it?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Tip

For best results, initiate chat on the files or code changes.

@RobinTail You raise a good question about HEAD response behavior! However, according to the HTTP specification, HEAD responses should never include a response body, regardless of the status code - whether it's a successful 200 response or an error response like 400.

Here's how HEAD method works:

  • HEAD responses must return the same headers that a GET request would return (including Content-Type, Content-Length, etc.)
  • But the response body must always be empty, even for error responses
  • This allows clients to get metadata about the resource without transferring the actual content

So for a 400 error:

  • GET would return: headers + error message body
  • HEAD would return: same headers (indicating there would be an error message) + empty body

The headers themselves (like Content-Type: text/plain) communicate that there would be an error message, but the actual error text shouldn't be included in the HEAD response body.

This behavior is consistent across all HTTP status codes - HEAD responses should always have empty bodies, but the headers should reflect what a corresponding GET request would return.

@RobinTail
Copy link
Owner Author

Ok. Thanx. I will address it in another PR then, @coderabbitai

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Tip

For best results, initiate chat on the files or code changes.

@RobinTail That sounds like a great approach! Keeping the current PR focused on the MIME type fix and addressing the HEAD response body issue separately makes perfect sense.

Would you like me to create a GitHub issue to track the HEAD response body improvement for your future PR? This would help ensure it doesn't get forgotten and provide a place to discuss the implementation details.

@RobinTail RobinTail merged commit e46e167 into master Jul 29, 2025
13 checks passed
@RobinTail RobinTail deleted the fix-neg-arr-rh-mime branch July 29, 2025 20:33
RobinTail added a commit that referenced this pull request Jul 29, 2025
)

Fixes #2858 

Noticed by @coderabbitai in
#2857 (comment)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants