-
-
Notifications
You must be signed in to change notification settings - Fork 943
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
feat(helpers): add support for complex intermediate types #2550
feat(helpers): add support for complex intermediate types #2550
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## next #2550 +/- ##
==========================================
- Coverage 99.57% 99.57% -0.01%
==========================================
Files 2806 2807 +1
Lines 250195 250374 +179
Branches 1104 1135 +31
==========================================
+ Hits 249130 249300 +170
- Misses 1037 1046 +9
Partials 28 28
|
Does eval need to be public? It seems it could be an internal helper method. I don't think library users would normally have any need to use it? |
No, it doesnt need to be public. But it covers some usecases, that fake cannot because it is bound to be a string, whereas eval can return anything. The eval function is useful for tools like:
That wish to generate any data based on a schema definition, a jsdoc annotation, or a I'm fine with exposing it in a separate PR. |
I think there might be logic in making it private first just because then we don't need to worry about any breaking changes, or publicly documenting it. Once we are clear it is stable and useful for third parties it could be exposed. |
I agree with the publicly documenting part, but the expectations (except for the entrypoint parameters) are already defined by |
Well if it's public that cannot be changed to private at "any time" only on a semver major release 😀 |
I have to agree with @matthewmayer here. While there might be a use case for this method, I think it will be a really niche one. Even if not, we don't lose anything by making it internal for now. While, as already said, we might have some maintainable burdens when making it public first. |
Sorry, there might have been some miscommunication here. I hid away the method now, so it does not cause any further confusion during reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
faker.helpers.fake("{{person.first_name()}}")
used to work but now throws. Maybe add a test to explicitly check for this?
In general due to subtle behavior changes like this i feel this should be considered breaking. I can imagine there are example in the wild of faker.helpers.fake("{{person.first_name()}}")
instead of the correct faker.helpers.fake("{{person.firstName()}}")
which will break.
To not introduce breaking changes, could we ignore parenthesis for now? |
Done |
Fixes #1850
Supersedes #2381
This PR adds a new intermediate method
faker.helpers.eval
that replaces the entire fake pattern placeholder resolution that was previously located inside thefake
method.I extracted the resolution part in its own method because it would otherwise get too long/complex to read.
faker.helpers.fake("{{person.firstName}})
->faker.helpers.eval("person.firstName") -> faker.person.firstName()
The eval function is now also cable to resolve expressions that contain more than the previous two parts.
This is needed because of methods such as
faker.airline.airline()
that return complex objects.