specter-php icon indicating copy to clipboard operation
specter-php copied to clipboard

Add nullable properties to json spec

Open craig-davis opened this issue 8 years ago • 0 comments

Feature

Allow nullable properties in a Specter file, with syntax influenced by the nullable type RFC. In the example below, the jobTitle is considered nullable.

{
  "__specter": "Sample customer record",
  "id": "@randomDigitNotNull@",
  "fname": "@firstName@",
  "lname": "@lastName@",
  "company": "@company@",
  "jobTitle": "?@jobTitle@"
}

Implementation

For property values prepended with a question mark ?, the generator will return either the result of the faker generator or a null value for some percentage of the results. The result must respect the seed value so that the results are repeatable. For string values, the return should be a null rather than an empty string.

The percentage of null returns is up for debate. I think 25% is a reasonable starting point.

Scope

This does not implement optional properties - where a property 'jobTitle' might be missing from the result altogether. This only addresses optional values.

craig-davis avatar Jun 11 '16 14:06 craig-davis