Skip to content

QueryParameter schema default override false sent value #7354

@alamirault

Description

@alamirault

API Platform version(s) affected: 4.1.21

Description
With this parameters configuration, if API endpoint is called with '/api/my_resources?booleanParameter=false', parameter value is true. Expected is to be false

#[ApiResource(
    operations: [
        new GetCollection(
            parameters: [
                'booleanParameter' => new QueryParameter(
                    schema: [
                        'type' => 'boolean',
                        'default' => true, <---------- Override value when value is false
                    ],
                    castToNativeType: true,
                ),
            ],
        ),
    ]
)]

How to reproduce
Simple reproducer: https://github.com/alamirault/api-platform-query-parameter-default

Possible Solution

ParameterProvider should maybe updated to not override sent values

if (($default = $parameter->getSchema()['default'] ?? false) && ($value instanceof ParameterNotFound || !$value)) {
$value = $default;
}

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