Skip to content

QueryParameter with custom constraints results in error "This value should be of type string." #7157

Closed
@Jontsa

Description

@Jontsa

API Platform version(s) affected: 4.1.9

Description

Upgrading to api-platform/core 4.1.9 breaks query parameters with custom constraints that worked with 4.1.8. It looks like it is caused by PR #7134. QueryParameter with custom constraint results in "This value should be of type string." error unless you add the new nativeType parameter.

How to reproduce

#[ApiResource(
    operations: [
        new GetCollection(
            provider: MyProvider::class,
            parameters: [
                'country' => new QueryParameter(schema: ['type' => 'string'], constraints: [new Country()]),
            ],
        ),
    ],
)]
final readonly class MyResource
{
}

To make it work again, you need to remove constraints -parameter or add nativeType parameter: new Type\BuiltinType(TypeIdentifier::STRING).

Possible Solution

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions