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

Extract faker's providers into several sub-modules of their own #219

Merged
merged 43 commits into from
Feb 18, 2024

Conversation

serpro69
Copy link
Owner

@serpro69 serpro69 commented Feb 17, 2024

Close #217

And as an added bonus, closes #218 as well.

  • Update orchid documentation
  • Update contributing docs
  • Add readme to each module
    • Maven central badge
    • Dependency coordinates
  • Fix cli-bot native image reflect.json file
  • Move SlackEmoji to LoremFaker ?
    • don't forget about docs

BookFaker could try to resolve "#{Name.name}" in one of its functions,
which would try to lookup the `Name` provider that isn't available
in the BooksFaker.

In such cases we try to find the `Name` provider in the core `Faker`
implementation, and failing that thrown an exception to make the
error clearer.

We do not try to support CustomFaker -> AnotherCustomFaker calls,
e.g. BooksFaker -> MusicFaker.
Only CustomFaker -> Faker is supported, i.e. BooksFaker -> Faker.
Also make safer some provider implementations that utilize secondaryCategory
by allowing `YmlFakeDataProvider#resolve` to take Category as parameter instead of String
Use this to move all files with GAMES category:

grep -lRF 'override val yamlCategory = YamlCategory.GAMES' \
  core/src/main/kotlin/io/github/serpro69/kfaker/provider/ | \
  xargs -I {} mv {} provider/games/src/main/kotlin/io/github/serpro69/kfaker/games/provider/

Then move a couple more, which have their own primary category,
manually.
This included moving test files also, so had to add a
testImplementation dependency on 'core' to the
faker-provider-conventions plugin.

Integration tests were also failing, particularly those that are
used in docs, so needed to add some integrationImplementation
dependencies on a new module also.
Apparently they've started using Anchors and Aliases in yml files
upstream (see e.g. uk.yml -> male_first_name -> first_name).

Seems like jackson can't handle Anchors properly
(see FasterXML/jackson-dataformats-text#98)

As a workaround, we use snakeyaml to read .yml files to Map objects,
and then we use jackson to write them to .json files, since snakeyaml
seems to support anchors just fine without needing to jump through hoops.
Room and TheRoom have the same data/functions
This leaves the core Faker with only its own data generators.
@serpro69 serpro69 added enhancement 🚀 New feature or request core 🧬 Issue related to :core module labels Feb 17, 2024
@serpro69 serpro69 added the faker 💯 Issue related to :faker modules label Feb 17, 2024
@serpro69 serpro69 added this to the 2.0.0 milestone Feb 17, 2024
@serpro69 serpro69 merged commit 5d10c1d into master Feb 18, 2024
1 check passed
@serpro69 serpro69 deleted the multi-provider branch February 18, 2024 19:47
serpro69 added a commit that referenced this pull request Feb 18, 2024
Relates to changes introduced in #219, particularly fakerService
became publicly visible, which is not ideal.

To hide it we had to introduce another property in
UniqueProviderDelegate, since that was the only place where
compilation was failing. So instead of using fakerService from
thisRef, we make it constructor property and use it from there.

This of course also touched almost all data providers.

Not sure if this needs more testing though.
@serpro69
Copy link
Owner Author

This also adds support for #63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core 🧬 Issue related to :core module enhancement 🚀 New feature or request faker 💯 Issue related to :faker modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow creating custom fakers / generators Split core Faker into sub-fakers by categories
1 participant