Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schema): fix AcceptMime decorator behavior #2997

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

Romakita
Copy link
Collaborator

@Romakita Romakita commented Feb 25, 2025

Summary by CodeRabbit

  • Documentation

    • Added a new section explaining how to configure accepted MIME types for HTTP endpoints with an illustrative example.
  • New Features

    • Improved MIME type handling to enable endpoints to properly process form URL-encoded data.
    • Enhanced API specifications with updated request payload validation and a new data model.

Copy link

coderabbitai bot commented Feb 25, 2025

Walkthrough

This pull request introduces documentation and code updates related to the @@AcceptMime@@ decorator. The documentation now includes a detailed "Accept Mime" section with a TypeScript example. In the source code, a new Model class is added and a test method’s signature is updated to accept this model. The internal logic of the AcceptMime decorator is modified to use Consumes instead of Produces, and the OpenAPI specification is updated with a new components section and request body schema referencing the Model.

Changes

File(s) Changes Summary
docs/docs/controllers.md Added a new "Accept Mime" section in the documentation detailing the usage of the @@AcceptMime@@ decorator with an example GET endpoint accepting "application/x-www-form-urlencoded".
packages/specs/.../acceptMime.* - Introduced a new Model class with an id property.
- Updated the Test class method signature to test(@BodyParams() model: Model).
- Revised the AcceptMime decorator to use Consumes instead of Produces.
- Updated the OpenAPI spec with a new Model schema and modified requestBody.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Router
    participant Controller
    participant Decorator

    Client->>Router: Send HTTP GET request
    Router->>Controller: Route request to endpoint
    Controller->>Decorator: Execute @@AcceptMime@@ decorator logic
    Note right of Decorator: Applies Consumes with specified MIME types
    Controller-->>Router: Process request using AcceptMime metadata
    Router-->>Client: Return JSON response
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c3d056d and 695cee7.

📒 Files selected for processing (3)
  • docs/docs/controllers.md (2 hunks)
  • packages/specs/schema/src/decorators/operations/acceptMime.spec.ts (2 hunks)
  • packages/specs/schema/src/decorators/operations/acceptMime.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: test-third-parties (20.12.2)
  • GitHub Check: test-specs (20.12.2)
  • GitHub Check: test-security (20.12.2)
  • GitHub Check: test-platform (20.12.2)
  • GitHub Check: test-orm (20.12.2)
  • GitHub Check: test-core (20.12.2)
  • GitHub Check: test-graphql (20.12.2)
  • GitHub Check: lint (20.12.2)
  • GitHub Check: CodeQL-Build
🔇 Additional comments (7)
docs/docs/controllers.md (1)

269-287: Excellent addition: New Accept Mime documentation.

This is a useful addition that provides clear documentation on the AcceptMime decorator's functionality. The example accurately demonstrates how to use this decorator to specify the MIME types a controller can consume.

One suggestion: Consider explicitly stating how AcceptMime affects the behavior of @BodyParams() to make the relationship clearer for users.

packages/specs/schema/src/decorators/operations/acceptMime.ts (3)

3-3: Fixed AcceptMime usage to correctly use Consumes instead of Produces.

This change properly aligns the decorator's implementation with its intended purpose - to specify what a controller accepts rather than what it produces.


13-13: Updated documentation example to match implementation.

The example now correctly shows the decorator accepting "application/x-www-form-urlencoded" instead of "application/json", which better illustrates its purpose.


24-24:

✅ Verification successful

Implementation now correctly uses Consumes.

The implementation correctly uses Consumes instead of Produces, which matches the decorator's name and purpose.

Before merging, verify that this change doesn't break existing code that might rely on the previous behavior:


🏁 Script executed:

#!/bin/bash
# Search for existing uses of AcceptMime in the codebase
rg "AcceptMime\(" --type ts

Length of output: 2745


Verified Implementation: The AcceptMime decorator now appropriately applies Consumes.
I confirmed via a codebase search that all instances of @AcceptMime—across docs, tests, and middleware—remain aligned with the updated behavior. The change from using Produces to Consumes (with the associated StoreSet("acceptMimes", mimes)) correctly reflects the decorator’s purpose, and no evidence was found that this update adversely affects any dependent code.

  • The usage in files such as test suites and docs reflects the new behavior.
  • The decorator’s implementation now clearly matches its intended semantic, and all references in the repository are consistent with this approach.

Approved for merging.

packages/specs/schema/src/decorators/operations/acceptMime.spec.ts (3)

1-9: Added Model class for testing body parameters.

The addition of the Model class provides a proper test case for using the AcceptMime decorator with body parameters.


16-16: Updated test method to accept a Model parameter.

This change ensures the test properly validates the decorator's behavior with body parameters.


25-52:

❓ Verification inconclusive

Updated expected OpenAPI specification to include request body.

The test now correctly expects a components section with the Model schema and a requestBody that references this schema.

However, there's a potential inconsistency: the test specifies AcceptMime("application/json") but the documentation example uses "application/x-www-form-urlencoded". Consider either:

  1. Updating the test to use "application/x-www-form-urlencoded" to match the documentation, or
  2. Verifying that the OpenAPI spec correctly includes this mime type in the appropriate location.

🏁 Script executed:

#!/bin/bash
# Check if the test validates that the AcceptMime decorator properly sets the consumes field
rg -A 10 "consumes|content-type|Content-Type|application/json" packages/specs/schema/src/decorators/operations/acceptMime.spec.ts

Length of output: 876


Clarification on AcceptMime Decorator and MIME Type Consistency

The test now correctly validates that the @AcceptMime("application/json") decorator produces the expected OpenAPI spec—specifically, the generated requestBody correctly references the Model schema under "application/json". However, there's a potential inconsistency: while the test uses "application/json", the documentation example refers to "application/x-www-form-urlencoded". Please review and decide on one of the following approaches:

  • Option 1: Update the test (and the decorator) to use "application/x-www-form-urlencoded" if that’s the intended content type.
  • Option 2: Update the documentation/example to consistently use "application/json" as implemented in the test.

Locations to double-check:

  • packages/specs/schema/src/decorators/operations/acceptMime.spec.ts for test verification.
  • Any documentation or example files that reference the MIME type to ensure consistency.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@Romakita Romakita merged commit ae72964 into production Feb 25, 2025
12 checks passed
@Romakita Romakita deleted the fix-accept-mimes-decorators branch February 25, 2025 09:39
@Romakita
Copy link
Collaborator Author

🎉 This PR is included in version 8.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant