Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Nov 14, 2024

fixes #1717

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • packages/plugins/openapi/tests/baseline/rpc-3.0.0-omit.baseline.yaml is excluded by !**/*.yaml
  • packages/plugins/openapi/tests/baseline/rpc-3.1.0-omit.baseline.yaml is excluded by !**/*.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

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

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the RESTfulOpenAPIGenerator and RPCOpenAPIGenerator classes by updating their constructors to accept a PluginOptions parameter, which includes an omitInputDetails option. This option allows for more concise OpenAPI specifications by controlling the inclusion of detailed input types. Error handling is improved to throw a PluginError for unsupported options. Additionally, test cases are updated to reflect the new configuration options, ensuring that the generated OpenAPI specifications are validated correctly.

Changes

File Path Change Summary
packages/plugins/openapi/src/rest-generator.ts Updated constructor to accept PluginOptions. Improved error handling for unsupported options.
packages/plugins/openapi/src/rpc-generator.ts Updated constructor to accept PluginOptions. Added omittableRef method for input type handling. Improved error handling for omitInputDetails.
packages/plugins/openapi/tests/openapi-rpc.test.ts Updated plugin declaration to include omitInputDetails. Adjusted test cases for new flag.

Assessment against linked issues

Objective Addressed Explanation
Provide a way to configure the depth of types generated by the OpenAPI plugin to limit schema size. (#1717)

Possibly related PRs


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

🧹 Outside diff range and nitpick comments (3)
packages/plugins/openapi/tests/openapi-rpc.test.ts (2)

19-24: Well-implemented loop for testing omitInputDetails

The loop effectively tests both states of the omitInputDetails option. Consider adding a brief comment above the loop to explain its purpose for future maintainability.


105-111: Robust baseline comparison logic

The dynamic selection of baseline files based on the omitInputDetails flag ensures accurate testing against expected outputs. Ensure that the baseline files are regularly updated to reflect changes in the plugin's behavior.

packages/plugins/openapi/src/rpc-generator.ts (1)

39-45: Simplify type validation for omitInputDetails option

The current type check for omitInputDetails can be streamlined. Since this.getOption<boolean>('omitInputDetails', false) should always return a boolean, the check for undefined may be unnecessary.

Consider simplifying the validation logic:

this.omitInputDetails = this.getOption<boolean>('omitInputDetails', false);
- if (this.omitInputDetails !== undefined && typeof this.omitInputDetails !== 'boolean') {
+ if (typeof this.omitInputDetails !== 'boolean') {
    throw new PluginError(name, `Invalid option value for "omitInputDetails", boolean expected`);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 04184b9 and 7c2db91.

⛔ Files ignored due to path filters (2)
  • packages/plugins/openapi/tests/baseline/rpc-3.0.0-omit.baseline.yaml is excluded by !**/*.yaml
  • packages/plugins/openapi/tests/baseline/rpc-3.1.0-omit.baseline.yaml is excluded by !**/*.yaml
📒 Files selected for processing (3)
  • packages/plugins/openapi/src/rest-generator.ts (2 hunks)
  • packages/plugins/openapi/src/rpc-generator.ts (19 hunks)
  • packages/plugins/openapi/tests/openapi-rpc.test.ts (2 hunks)
🔇 Additional comments (26)
packages/plugins/openapi/tests/openapi-rpc.test.ts (4)

99-101: Clear conditional logging for test configurations

The logging statement effectively communicates the current configuration of the test, which aids in debugging and tracking test executions.


113-120: Comprehensive validation of the OpenAPI specification

The use of OpenAPIParser.validate along with specific checks for tags and paths ensures that the generated specification meets the expected standards and behaviors.


125-129: Proper handling and validation of deprecated API paths

The tests correctly verify the documentation of deprecated paths, ensuring that they are accurately represented in the OpenAPI specification.


130-132: Correct exclusion of ignored models from the OpenAPI paths

The tests ensure that models marked to be ignored are not included in the generated OpenAPI documentation, maintaining its relevance and cleanliness.

packages/plugins/openapi/src/rest-generator.ts (3)

10-11: Imports are correctly added for new functionality.

The addition of PluginError and PluginOptions is necessary for handling the new plugin options and error management in the constructor.


37-42: Constructor updated to handle new plugin options effectively.

The constructor now properly handles the omitInputDetails option by throwing a PluginError if it is used for the REST flavor. This ensures that the plugin's behavior is consistent with its intended use case.


37-42: Effective integration of new plugin options within the existing architecture.

The changes are well integrated, maintaining the existing functionality while extending the constructor to handle new configuration options appropriately.

packages/plugins/openapi/src/rpc-generator.ts (19)

3-3: Import necessary modules from '@zenstackhq/sdk'

The import statement correctly adds PluginError, PluginOptions, and other required modules for the new functionality.


26-26: Define ANY_OBJECT constant for generic object reference

Introducing the ANY_OBJECT constant enhances readability and supports the new omitInputDetails option effectively.


37-37: Add omitInputDetails property to control input detail omission

The class property omitInputDetails is appropriately declared to store the new plugin option.


166-168: Use omittableRef to conditionally reference input types

Applying this.omittableRef to select, include, and data correctly adjusts input references based on the omitInputDetails option.


192-193: Handle createMany inputs with omittableRef

Consistently using this.omittableRef for data ensures that input details are omitted when specified.


222-224: Update findUnique operation to respect omitInputDetails

The inputs for select, include, and where are appropriately modified to use this.omittableRef, aligning with the new option.


245-247: Adjust findFirst inputs using omittableRef

Consistent application of this.omittableRef enhances maintainability and ensures correct behavior based on the option.


268-270: Modify findMany operation inputs with omittableRef

Updating select, include, and where with this.omittableRef correctly implements the input detail omission.


292-295: Update updateOne operation to use omittableRef

The changes ensure that select, include, where, and data inputs respect the omitInputDetails setting.


317-318: Apply omittableRef to updateMany operation inputs

Using this.omittableRef for where and data maintains consistency across operations.


340-344: Refactor upsert operation inputs with omittableRef

The inputs for select, include, where, create, and update are correctly adjusted to handle input omission.


366-368: Ensure deleteOne operation inputs use omittableRef

Updating the input references aligns the deleteOne operation with the omitInputDetails functionality.


389-389: Modify deleteMany operation to respect omitInputDetails

Applying this.omittableRef to the where input ensures consistent behavior when omitting input details.


410-411: Adjust count operation inputs with omittableRef

Using this.omittableRef for select and where inputs correctly implements the new option.


440-442: Update aggregate operation inputs to handle input omission

Consistently applying this.omittableRef to where and orderBy supports the omitInputDetails option.


466-468: Apply omittableRef to groupBy operation inputs

The inputs where, orderBy, and by are appropriately modified, ensuring consistent handling of input details.


602-614: Use omittableRef in aggregate field definitions

Modifying _count, _min, _max, _sum, and _avg with this.omittableRef aligns aggregate operations with the new option.


632-638: Add catch-all object schema when omitInputDetails is enabled

Defining the ANY_OBJECT schema provides a generic object type, effectively reducing the size of the generated OpenAPI specification.


847-853: Implement omittableRef method for conditional references

The omittableRef method correctly returns a reference to ANY_OBJECT when omitInputDetails is true, improving performance for large models.

@ymc9 ymc9 merged commit 3134f0d into dev Nov 14, 2024
13 checks passed
@ymc9 ymc9 deleted the feat/openapi-omit-details branch November 14, 2024 04:48
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.

2 participants