Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metadata): providing parameter constraints skips automatic ones #6756

Merged
merged 2 commits into from
Oct 26, 2024

Conversation

GeLoLabs
Copy link
Contributor

@GeLoLabs GeLoLabs commented Oct 25, 2024

Q A
Branch? 4.0
Tickets -
License MIT
Doc PR -

Hello,

According to the documentation https://api-platform.com/docs/core/filters/#parameter-validation, we can read:

You can also use your own constraint by setting the constraints option on a Parameter. In that case we won’t setup the automatic validation for you and it’ll replace our defaults.

Then, given the following simplified resource definition:

#[Api\ApiResource(
    // ...
    parameters: [
        'channel' => new QueryParameter(required: true, constraints: [new ChannelConstraint()]),
    ],
)]

I would expect that the NotNull constraint automatically provided by the required parameter is not provided anymore as I define custom constraint.

If you mind why the required parameter is defined here, it's for forcing the required flag in the Open API documentation.

Here, a PR proposing a fix on the 4.0 branch, not sure if the bug is present on the 3.x branch or the main branch as my project use the 4.x branch currently and the class modified in this PR seems not existing on these branches.

If you agree about this fix, I can take some time to add tests about it.

@GeLoLabs GeLoLabs force-pushed the query-parameter-constraints branch 2 times, most recently from 3f8dbb2 to 483719f Compare October 25, 2024 15:17
@soyuka soyuka changed the title Don't setup the parameter automatic validation if constraints are provided fix(metadata): providing parameter constraints skips automatic ones Oct 26, 2024
@soyuka soyuka merged commit 4f65ef2 into api-platform:4.0 Oct 26, 2024
58 of 59 checks passed
@soyuka
Copy link
Member

soyuka commented Oct 26, 2024

Thanks!

@GeLoLabs
Copy link
Contributor Author

Thank you too for merging !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants