swagger-api / swagger-api/swagger-codegen
[PHP] [SymfonyServerCodegen] Bug: Validator ignore all annotation-asserts for Models
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
subj.
Swagger-codegen version
2.4.1
Swagger declaration file content or url
definitions:
FiltersRow:
type: object
properties:
script:
type: string
arguments:
type: string
pattern: '^[a-z0-9-_ ]*$'
class FiltersRow
{
/**
* @var string|null
* @SerializedName("arguments")
* @Assert\Type("string")
* @Type("string")
* @Assert\Regex("/^[a-z0-9-_ ]*$/")
*/
protected $arguments;
But all @Assert* skipping because validator configured without AnnotationMapping and pass overwrited $asserts array to $this->validate() in controller.
Suggest a fix/enhancement
For enable validator annotation-asserts need:
- replace in php-symfony/validation/SymfonyValidator.mustache
from $this->validator = Validation::createValidator();
to: $this->validator = (new ValidatorBuilder())->enableAnnotationMapping()->getValidator();
- in php-symfony/api_input_validation.mustache need dont generate $asserts array and dont pass $asserts to
$response = $this->validate(${{paramName}});for models with annotaions-asserts only.
Maybe there is a more correct way. I do not know.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect php-symfony/validation/SymfonyValidator.mustache and php-symfony/api_input_validation.mustache first, then compare the generated Symfony validator and controller behavior for the FiltersRow example. Confirm how annotation mapping and the generated $asserts argument interact. Done means model @Assert annotations are honored during validation without incorrectly overwriting or bypassing them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100