Skip to content

fix(codegen): refuse custom Validates attrs in polyparity exporter#70

Open
davidwyly wants to merge 1 commit into
masterfrom
codex/fix-polyparityexporter-to-handle-custom-validators
Open

fix(codegen): refuse custom Validates attrs in polyparity exporter#70
davidwyly wants to merge 1 commit into
masterfrom
codex/fix-polyparityexporter-to-handle-custom-validators

Conversation

@davidwyly

Copy link
Copy Markdown
Owner

Motivation

  • The PolyparityExporter previously omitted unknown validation attributes from the generated YAML, which can silently diverge from the PHP Binder that executes any attribute implementing Validates; this creates a risk when generated specs are used as enforcement points in other runtimes.

Description

  • Updated src/Rxn/Framework/Codegen/PolyparityExporter.php to use Rxn\Framework\Http\Binding\Validates and make refuse() explicitly detect attributes that implement Validates and throw a RuntimeException instead of returning null.
  • Preserved the existing refusal behavior for known unsupported built-ins (Pattern, Uuid, Json, Date, StartsWith, EndsWith).
  • Added a regression test testRefusesCustomValidatesAttribute() to src/Rxn/Framework/Tests/Codegen/PolyparityExporterTest.php that asserts the exporter refuses DTOs using a custom Validates attribute.

Testing

  • Added a unit test PolyparityExporterTest::testRefusesCustomValidatesAttribute() covering the new refusal behavior; the test is included in the repo but was not executed successfully in this environment.
  • Attempted to run phpunit directly (php -d zend.assertions=1 ./vendor/bin/phpunit src/Rxn/Framework/Tests/Codegen/PolyparityExporterTest.php) and via composer test, but both attempts failed because phpunit is not available in the execution environment (phpunit: not found).
  • No other automated test failures were observed locally in this environment (test tooling unavailable to run the full suite).

Codex Task

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens the PolyparityExporter so it no longer silently drops custom validation attributes that implement Validates, preventing generated polyparity YAML specs from diverging from PHP Binder behavior.

Changes:

  • Detect attributes implementing Rxn\Framework\Http\Binding\Validates during export and throw a RuntimeException instead of omitting them.
  • Preserve existing “refuse” behavior for known unsupported built-in attributes (e.g., Pattern, Uuid, Json, Date, StartsWith, EndsWith).
  • Add a regression test asserting refusal for DTOs using a custom Validates attribute.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Rxn/Framework/Codegen/PolyparityExporter.php Refuses export when encountering custom Validates attributes to avoid silently divergent specs.
src/Rxn/Framework/Tests/Codegen/PolyparityExporterTest.php Adds a unit test covering refusal behavior for a custom Validates attribute.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessageMatches('/CustomValidatesAttribute.*custom validator/i');
$exporter->emit(Fixture\CustomUnsupportedDto::class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants