Skip to content

OpenApiFactory auto-generates string schema type for foo[] filters. #7657

@VincentLanglet

Description

@VincentLanglet

API Platform version(s) affected: 4.2

In the same context than #7656 and #7634, I encounter some issue with the default implementation from OpenApiFilterTrait::getOpenApiParameters @soyuka @vinceAmstoutz about the schema.

I dunno if it's a bug or something I wrongly understand since I found test about it in ApiPlatform code base.

Description

For a "basic" filter

'brand' => new QueryParameter(filter: new ExactFilter()),

ApiPlatform seems to expect

{
    "name": "brand[]",
    "in": "query",
    "description": "",
    "required": false,
    "deprecated": false,
    "schema": {
        "type": "string"
    },
    "style": "deepObject",
    "explode": true
},

according to

'default behavior (no castToArray, no schema) should use array notation' => [
'parameterName' => 'brand',
'shouldHaveArrayNotation' => true,
'expectedStyle' => 'deepObject',
'expectedExplode' => true,
'expectedSchemaType' => 'string',
],

But since it's an array notation brand[], I would have expect a default schema of something like

"schema": { "type": "array", "items": "string" },

because the brand filter can be used in the following way /foo?brand[]=brand1&brand[]=brand2 and because of the name brand[] (and not brand)

Do I misunderstand when an array schema or is there some confusion in ApiPlatform code about [] suffix in the filter name vs the schema... ?

Additional Context

The "default" schema of string is coming from these lines

$defaultSchema = ['type' => 'string'];
if (null !== $p->getDefault()) {
$defaultSchema['default'] = $p->getDefault();
}
$defaultParameter = new Parameter(
$key,
$in,
$p->getDescription() ?? "$resourceShortName $key",
$p->getRequired() ?? false,
false,
null,
$p->getSchema() ?? $defaultSchema,
);

and here, the [] name is generated, without adding any schema
return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions