fix(codegen): refuse custom Validates attrs in polyparity exporter#70
Open
davidwyly wants to merge 1 commit into
Open
fix(codegen): refuse custom Validates attrs in polyparity exporter#70davidwyly wants to merge 1 commit into
davidwyly wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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\Validatesduring export and throw aRuntimeExceptioninstead 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
Validatesattribute.
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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PolyparityExporterpreviously omitted unknown validation attributes from the generated YAML, which can silently diverge from the PHPBinderthat executes any attribute implementingValidates; this creates a risk when generated specs are used as enforcement points in other runtimes.Description
src/Rxn/Framework/Codegen/PolyparityExporter.phptouse Rxn\Framework\Http\Binding\Validatesand makerefuse()explicitly detect attributes that implementValidatesand throw aRuntimeExceptioninstead of returningnull.Pattern,Uuid,Json,Date,StartsWith,EndsWith).testRefusesCustomValidatesAttribute()tosrc/Rxn/Framework/Tests/Codegen/PolyparityExporterTest.phpthat asserts the exporter refuses DTOs using a customValidatesattribute.Testing
PolyparityExporterTest::testRefusesCustomValidatesAttribute()covering the new refusal behavior; the test is included in the repo but was not executed successfully in this environment.phpunitdirectly (php -d zend.assertions=1 ./vendor/bin/phpunit src/Rxn/Framework/Tests/Codegen/PolyparityExporterTest.php) and viacomposer test, but both attempts failed becausephpunitis not available in the execution environment (phpunit: not found).Codex Task