diff --git a/tests/Issues/Issue/Issue133Test.php b/tests/Issues/Issue/Issue133Test.php new file mode 100644 index 0000000..02960f7 --- /dev/null +++ b/tests/Issues/Issue/Issue133Test.php @@ -0,0 +1,67 @@ +modifyModelGenerator = static function (ModelGenerator $modelGenerator): void { + $modelGenerator->addPostProcessor(new EnumPostProcessor( + implode(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), 'PHPModelGeneratorTest', 'Enum']), + 'Enum', + true, + )); + }; + + $className = $this->generateClassFromFile('oneOfWithMetricIdConflict.json'); + + // Create a valid instance matching the second oneOf branch (vendor scope) + // metric_id "custom_metric" satisfies minLength/pattern but NOT the enum in branch 1 + $object = new $className([ + 'committed_metrics' => [ + ['scope' => 'standard', 'metric_id' => 'custom_metric'], + ], + ]); + + // Serialize back to array - this should work but currently fails + // because the merged metric_id property loses its validators + $serialized = $object->toArray(); + + $this->assertSame( + ['committed_metrics' => [['scope' => 'standard', 'metric_id' => 'custom_metric']]], + $serialized, + ); + } +} diff --git a/tests/Schema/Issues/133/oneOfWithMetricIdConflict.json b/tests/Schema/Issues/133/oneOfWithMetricIdConflict.json new file mode 100644 index 0000000..ed6402e --- /dev/null +++ b/tests/Schema/Issues/133/oneOfWithMetricIdConflict.json @@ -0,0 +1,58 @@ +{ + "type": "object", + "properties": { + "committed_metrics": { + "type": "array", + "items": { + "type": "object", + "discriminator": { + "propertyName": "scope" + }, + "oneOf": [ + { + "properties": { + "scope": { + "type": "string", + "const": "vendor" + }, + "metric_id": { + "enum": [ + "impressions", + "spend", + "clicks", + "ctr" + ] + } + }, + "required": [ + "scope", + "metric_id" + ] + }, + { + "properties": { + "scope": { + "type": "string", + "const": "standard" + }, + "metric_id": { + "type": "string", + "minLength": 1, + "maxLength": 64, + "pattern": "^[a-z][a-z0-9_]*$" + } + }, + "required": [ + "scope", + "metric_id" + ] + } + ] + }, + "minItems": 1 + } + }, + "required": [ + "committed_metrics" + ] +}