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): add dereferencing for SchemaFromType #518

Merged

Conversation

superstas
Copy link
Contributor

@superstas superstas commented Jul 23, 2024

It fixes #517

Summary by CodeRabbit

  • New Features

    • Enhanced schema generation to better handle pointer types, preventing potential runtime errors.
    • Introduced a new schema transformer type, CustomSchemaPtr, allowing for modified schema descriptions.
  • Tests

    • Added a test case to validate the functionality of the new CustomSchemaPtr transformer, ensuring correct schema outputs.

Copy link

coderabbitai bot commented Jul 23, 2024

Warning

Rate limit exceeded

@danielgtaylor has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 17 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 5d90e4f and c27510d.

Walkthrough

The recent changes enhance schema generation and transformation within the codebase. The SchemaFromType function now correctly dereferences pointer types, improving type handling. Additionally, a new CustomSchemaPtr structure implements the huma.SchemaTransformer interface, enabling better schema descriptions. Corresponding tests ensure that these transformations are accurately reflected in the generated OpenAPI Specification, addressing previous issues related to missing descriptions.

Changes

Files Change Summary
schema.go Modified SchemaFromType to dereference pointer types, improving type handling during instance creation.
schema_test.go Introduced CustomSchemaPtr struct for schema transformation, including a new test case to verify its functionality.

Assessment against linked issues

Objective Addressed Explanation
Improve schema description generation (#517)
Ensure correct schema transformation for types

🐰 Hopping through the code so bright,
Pointers now dereference just right!
Schemas transform with a custom flair,
Descriptions added, we all rejoice in the air!
With tests in place, we bounce with glee,
Happy coding, as smooth as can be! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9bf5661 and 8065a91.

Files selected for processing (2)
  • schema.go (1 hunks)
  • schema_test.go (4 hunks)
Additional comments not posted (5)
schema.go (1)

650-651: LGTM! But verify the function usage in the codebase.

The addition of t = deref(t) ensures that pointer types are correctly dereferenced before further processing, improving robustness.

However, ensure that all function calls to SchemaFromType handle the dereferenced types correctly.

Verification successful

Verification successful!

The addition of t = deref(t) ensures that pointer types are correctly dereferenced before further processing, improving robustness. The function calls to SchemaFromType handle the dereferenced types correctly.

  • registry.go: The dereferenced type is managed appropriately after the call to SchemaFromType.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `SchemaFromType` handle the dereferenced types correctly.

# Test: Search for the function usage. Expect: Correct handling of dereferenced types.
rg --type go -A 5 $'SchemaFromType'

Length of output: 2396


Script:

#!/bin/bash
# Extract relevant code around the usage of SchemaFromType in registry.go to verify handling of dereferenced types.
rg --type go -A 10 -B 10 $'SchemaFromType' registry.go

Length of output: 393

schema_test.go (4)

76-77: Declare the interface implementation.

The declaration ensures that CustomSchemaPtr implements the huma.SchemaTransformer interface.


78-80: Define the CustomSchemaPtr struct.

The struct CustomSchemaPtr contains a single field Value of type string, annotated for JSON serialization.


82-85: Implement the TransformSchema method.

The method TransformSchema modifies the schema's description to "custom description" and returns the modified schema.


906-920: Add a new test case for CustomSchemaPtr.

The test case schema-transformer-for-ptr verifies the output of the TransformSchema method when invoked with an instance of CustomSchemaPtr.

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.83%. Comparing base (9bf5661) to head (8065a91).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #518   +/-   ##
=======================================
  Coverage   92.83%   92.83%           
=======================================
  Files          22       22           
  Lines        3838     3839    +1     
=======================================
+ Hits         3563     3564    +1     
  Misses        230      230           
  Partials       45       45           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8065a91 and 5d90e4f.

Files selected for processing (2)
  • schema.go (1 hunks)
  • schema_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • schema.go
  • schema_test.go

Copy link
Owner

@danielgtaylor danielgtaylor left a comment

Choose a reason for hiding this comment

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

Thanks!

@danielgtaylor danielgtaylor merged commit d2c5dde into danielgtaylor:main Jul 25, 2024
1 check passed
@superstas superstas deleted the fix/missed-description-with-ptr branch July 25, 2024 16:37
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.

Missed schema description on generation.
2 participants