Faker: Use $uniqueFaker for attributes listed in x-indexes unique constraints
Problem
When an attribute appears in an x-indexes entry that defines a unique constraint
(e.g. unique:table,column), the faker stub generator uses the plain $faker instance
for that attribute. This causes duplicate values during fake data generation, which
violates the unique constraint and leads to database errors at runtime.
Expected Behavior
If an attribute is referenced in any x-indexes entry that starts with unique:, the
generator should automatically use $uniqueFaker instead of $faker in the generated
faker stub — unless the spec already provides an explicit x-faker value that already
uses $uniqueFaker.
Example
x-indexes:
- 'unique:leads,creditor_number'
properties:
creditor_number:
type: integer
minimum: 10000
maximum: 99999
Expected generated faker stub:
$model->creditor_number = $uniqueFaker->numberBetween(10000, 99999);
Actual (broken) generated faker stub:
$model->creditor_number = $faker->numberBetween(10000, 99999);
Note on composite unique indexes
The issue also applies to composite unique indexes (e.g. unique:lead_mails,lead_id,mail).
For composite indexes, at least the varying part of the key (typically the second or third
column) should use $uniqueFaker — or the full combination should be guaranteed unique.
Faker: Use
$uniqueFakerfor attributes listed inx-indexesunique constraintsProblem
When an attribute appears in an
x-indexesentry that defines a unique constraint(e.g.
unique:table,column), the faker stub generator uses the plain$fakerinstancefor that attribute. This causes duplicate values during fake data generation, which
violates the unique constraint and leads to database errors at runtime.
Expected Behavior
If an attribute is referenced in any
x-indexesentry that starts withunique:, thegenerator should automatically use
$uniqueFakerinstead of$fakerin the generatedfaker stub — unless the spec already provides an explicit
x-fakervalue that alreadyuses
$uniqueFaker.Example
Expected generated faker stub:
Actual (broken) generated faker stub:
Note on composite unique indexes
The issue also applies to composite unique indexes (e.g.
unique:lead_mails,lead_id,mail).For composite indexes, at least the varying part of the key (typically the second or third
column) should use
$uniqueFaker— or the full combination should be guaranteed unique.