ghandic/jsf

Option to prefer default values when available and/or example values, before random values

Closed this issue · 3 comments

I also would like to be able to apply defaults to the default generation.

Example from JSON Schema Faker, show the inputs and outputs:

image

You can see in the above example, that the generated sample is easy to read and understand. Whereas a randomly generated set of inputs would lose much valuable context.

The use case is that we define inputs for our application as JSON schema specifications, and we ask users to provide their input matching that specification. It is much preferrable to have those generated values defaulting to the actual default values: (1) becase it is easier to understand from a user perspective if they see 'items per batch' defaulting to something like 1000 and not 1235134523451345, and (2) because in those cases, deleting the defaults has the expected effect or basically not overriding them.

Another case would be an example URL value or an example region name. Seeing the example or default value gives a much stronger hint of what kind of inputs are actually required. (If you see us-east-1 as the default, you are going to feel comfortable providing us-west-2, and you probably won't mistakenly type US West (Oregon).)

As (apparently?) implemented in JSON Schema Faker, I could imagine adding a use_defaults and use_examples into the generate() method.

image

Happy to contribute if this is something I could help with.

Happy to have those options, PR welcome

I gave it a go: see PR #110

@simon-schoonjans - That PR looks great! I'm excited to try it out!

Will close this as resolved, and will circle back if I run into any issues.

Thanks so much!