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

Feature request: generate dummy documents for a collection based on aldeed's SimpleSchema #6

Open
yanndebelgique opened this issue Nov 4, 2014 · 9 comments

Comments

@yanndebelgique
Copy link

You would use it like this :

Fake.docs(SimpleSchema);

Would spit out a document based on the SimpleSchema object. That would be freakin awesome! 👍

@subhog
Copy link
Member

subhog commented Nov 4, 2014

Great idea, thanks!

@yanndebelgique
Copy link
Author

No problem! great work btw.
Can't wait to see what else you're going to build.

@Aralun
Copy link

Aralun commented Nov 5, 2014

Haha, I just came here to make this very suggestion!
The ability to mock up objects with SimpleSchema would be absolutely incredible.

I had some additional ideas about it, concerning field names... If a field key contains:

  • "name", generate something close to a name
  • "description", generate a random sentence
  • "birth", generate a Date not too far in the past (20-100 years?)
  • And so on and so forth...

If the field is a string without min or max values, generate a string of length between Fake.docsValues.minStringLength and Fake.docsVaues.maxStringLength, those global values could be re-assigned by the user of course!
Similarly for an array, generate between Fake.docsValues.minArrayLength and Fake.docsValues.maxArrayLength values in that array.
If a field is optional have a Fake.docsValues.optionalChance chance to fill it...

In the Fake.docs function, take a second argument: An options object which would use the following fields:

  • optionalChance : Number 0 = No optional values at all, 100 = All optional values are set
  • All the values in my last paragraph, such as minStringLength and maxArrayLength

I can't wait to have such a feature!

@kevohagan
Copy link

+1 on this , that would be very cool

@rhyslbw
Copy link

rhyslbw commented Jan 1, 2015

+1

1 similar comment
@AlexFrazer
Copy link

+1

@AlexFrazer
Copy link

The big problem here is dealing with regular expressions in an adequetly random fashion

@raiyankamal
Copy link

I did some initial research today to find out whether this feature is viable. I couldn't find any information on retrieving a list of keys and their types from the doc of simpleschema.

But It is possible to find a list of keys from a simpleSchema object: they are stored in an array named _schemaKeys. Then there is another field named _schema holding type and other information for those keys. One can loop through the keys, then read the type e.g. String, Number etc. from the _schema. However, I feel a bit uncomfortable about using these private variables. These undocumented variables may change or disappear altogether in a future version. An implementation based on these variables may need regular maintenance depending on how frequently simpleschema changes their private variable names and the data structure.

If anyone else has looked into it, please share your thoughts and comments on this. Thanks.

@raiyankamal
Copy link

I've added (limited) support for generating dummy documents according to a given SimpleSchema definition. Have a look at my pull request here: #20

Only Number, String and Boolean types are supported for the time being. Arrays will be added soon.

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

No branches or pull requests

7 participants