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

[Bug fix] Issue 301: Metadata() is not reflected when setting the Default() in goa design. #304

Merged
merged 1 commit into from May 9, 2024

Conversation

nao1215
Copy link
Collaborator

@nao1215 nao1215 commented May 3, 2024

The bug details are documented in Issue #301.
I am wrote unit tests and integration tests for the scope of the bug fix.

This PR affects the entire Finalize() code generated by goa.
After this PR is merged, type information will always be provided for the local variables generated within Finalize(), like this:

func (ut *issue301Type) Finalize() {
	var defaultPrimitiveTypeNumber float64 = 3.140000
	if ut.PrimitiveTypeNumber == nil {
		ut.PrimitiveTypeNumber = &defaultPrimitiveTypeNumber
	}
	var defaultPrimitiveTypeTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
	if ut.PrimitiveTypeTime == nil {
		ut.PrimitiveTypeTime = &defaultPrimitiveTypeTime
	}
	var defaultUserDefinitionType design.SecuritySchemeKind = 10
	if ut.UserDefinitionType == nil {
		ut.UserDefinitionType = &defaultUserDefinitionType
	}
}

Previously, local variable type information was omitted in Finalize().

Summary by CodeRabbit

  • New Features
    • Enhanced code generation to automatically set default values for user-defined types.
    • Introduced a new API resource with detailed action definitions and default parameters.
  • Tests
    • Added integration tests to validate the correct generation of default values in user-defined types.
  • Documentation
    • Updated API documentation to include new resource details and payload attributes.

Copy link

coderabbitai bot commented May 3, 2024

Walkthrough

The recent changes enhance the code generation capabilities for user-defined types in Go, particularly focusing on setting default values and handling metadata effectively. This is achieved through modifications in test suites, design specifications, and the code generation logic itself.

Changes

Files Summary of Changes
_integration_tests/... Added tests for setting default values in user-defined types and verifying code blocks in generated files.
_integration_tests/issue301/design/design.go Defined an API with resources and actions, including payload attributes with default values.
goagen/codegen/finalizer.go Enhanced handling of default values in code generation, especially for non-datetime types.
goagen/codegen/finalizer_test.go Updated tests to include new contexts and assignment codes for different data types.

Possibly related issues

🐰✨
A hop, a skip, in the code we weave,
New defaults set, in Go we believe.
From tests to design, changes are made,
In user types and finals, our efforts displayed.
Celebrate the craft, with code so bright,
Happy coding to all, and to all a good byte!
🌟🐇


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5fc402f and 119870d.
Files selected for processing (4)
  • _integration_tests/integration_test.go (1 hunks)
  • _integration_tests/issue301/design/design.go (1 hunks)
  • goagen/codegen/finalizer.go (2 hunks)
  • goagen/codegen/finalizer_test.go (3 hunks)
Additional comments not posted (7)
_integration_tests/issue301/design/design.go (3)

8-12: The API definition is clear and concise, providing necessary details such as title, host, and scheme.


14-20: The resource definition correctly sets up the action, routing, payload, and response. This setup is crucial for testing the new functionality.


22-39: The payload definition includes user-defined and primitive types with default values and metadata. Ensure that the metadata and default values are consistent with the intended types and values.

goagen/codegen/finalizer.go (2)

28-28: The addition of "gotypedef" to the function map is a crucial enhancement for handling type definitions more explicitly in the code generation process.


167-167: The modification in the assignment template to handle non-datetime types more effectively is a significant improvement. It ensures that the default values are set correctly for various data types.

goagen/codegen/finalizer_test.go (1)

165-184: The addition of a new testing context for objects with user-defined types is essential for ensuring that the new functionality works as expected. This test validates the handling of metadata and default values in user-defined types.

_integration_tests/integration_test.go (1)

170-211: The new integration test function TestIssue301 is well-structured and checks the correct generation of code for setting default values. It is crucial to ensure that the expected code blocks are present in the generated files, which this test adequately checks.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

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

@nao1215 nao1215 requested a review from shogo82148 May 3, 2024 05:49
Copy link
Owner

@shogo82148 shogo82148 left a comment

Choose a reason for hiding this comment

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

ヨシッ

@shogo82148 shogo82148 merged commit 6aa6aca into shogo82148:main May 9, 2024
17 checks passed
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.

None yet

2 participants