Skip to content

feat: support struct type providers & max field depth on struct - #80

Merged
bxcodec merged 2 commits into
go-faker:mainfrom
adrianiacobghiula:main
Sep 26, 2025
Merged

bxcodec merged 2 commits into
go-faker:mainfrom
adrianiacobghiula:main

Conversation

@adrianiacobghiula

@adrianiacobghiula adrianiacobghiula commented Sep 21, 2025 •

Copy link
Copy Markdown
Contributor

Allow users to register struct type providers, useful for types like Redefined time or big.Rat
Allow users to limit the struct field depth generator as time to generate large real-life complex objects takes a very long time, example of 4 objects added for testing with default generator conditions took more than 60 seconds

@adrianiacobghiula

Copy link
Copy Markdown
Contributor Author

@bxcodec any feedback on this PR ?

Comment thread faker.go Resolved
@bxcodec
bxcodec requested a review from Copilot September 25, 2025 14:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for struct type providers and field depth limiting to improve faker performance and flexibility. It allows users to register custom providers for specific struct types (like time.Time or big.Rat) and limit how deeply nested struct fields are populated to prevent long generation times for complex objects.

  • Adds StructTypeProviders map to register custom providers for specific struct types
  • Introduces MaxFieldDepthOption to control how deeply struct fields are populated
  • Updates struct generation logic to use type providers and respect field depth limits

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
pkg/options/options.go Adds struct type provider map, field depth option, and related configuration functions
pkg/errors/generic.go Adds error message for unsupported non-struct types
faker_test.go Adds comprehensive tests for struct type providers and field depth limiting
faker.go Updates struct generation to use type providers and implement field depth controls

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/options/options.go Resolved
Comment thread faker.go Resolved
Comment thread faker_test.go Resolved
Comment thread pkg/options/options.go Resolved
@bxcodec

bxcodec commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

please ignore AI review if doesn't make sense

@adrianiacobghiula

Copy link
Copy Markdown
Contributor Author

@bxcodec pushed a fix on the possible denominator can return 0 & answered all PR comments

@bxcodec bxcodec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to cook!

Image

Thanks for the PR, will be released in 4.7.0

@bxcodec bxcodec changed the title support struct type providers & max field depth on struct feat: support struct type providers & max field depth on struct Sep 26, 2025
@bxcodec
bxcodec merged commit 407dd00 into go-faker:main Sep 26, 2025
@bxcodec

bxcodec commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

Hey @adrianiacobghiula

I just merged, I just realized, we should have added a small documentation about how to use the new feature.

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.

3 participants