SortFilter generates unsupported array form for parameters
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- php
- Área
- api, backend-api-design
Línea de trabajo
Empieza leyendo SortFilter y OpenApiFilterTrait::getOpenApiParameters() y luego revisa las pruebas de los parámetros de consulta OpenAPI generados. El informe identifica castToArray como el probable origen del parámetro adicional con formato de array. Se considera terminado cuando la documentación ya no anuncia orderDate[] si el filtro rechaza esa entrada y pasan las pruebas pertinentes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
API Platform version(s) affected:
I have tested this on both api-platform/core 4.4.4 and api-platform/core 5.0.3
Description
When you add a SortFilter to an endpoint it generates 2 forms of the sortFilter for the given property. For example:
Let's create the following Collection endpoint:
#[ApiResource(
shortName: 'Party',
operations: [
new GetCollection(
'/activities/parties{._format}',
parameters: [
'orderDate' => new QueryParameter(
filter: new SortFilter(),
property: 'date',
),
]
),
],
openapi: new Operation(
tags: ['Activities'],
summary: 'Parties',
)
)]
This would result in the docs.jsonopenapi generating these two parameters for it:
{
"name": "orderDate",
"in": "query",
"description": "Party orderDate",
"required": false,
"deprecated": false,
"schema": {
"type": "string",
"enum": [
"asc",
"desc",
"ASC",
"DESC"
]
},
"style": "form",
"explode": true
},
{
"name": "orderDate[]",
"in": "query",
"description": "Party orderDate",
"required": false,
"deprecated": false,
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": [
"asc",
"desc",
"ASC",
"DESC"
]
}
},
The first works fine, but if you were to use ?orderDate[]= the endpoint will throw a constrain violation with code 422 saying the selected value is not valid. It seems Order filter creates the documentation for it but does not actually support this form of the filter (which makes sense to me as I cannot come up with a situation where you would want to be able to sort the same property in multiple directions).
How to reproduce
I think the previous header explains it adequately.
Possible Solution
One solution would be to overwrite the castToArray property of the parameter before passing it to OpenApiFilterTrait's getOpenApiParameters() method by altering the use statement in SortFilter to something like:
use OpenApiFilterTrait {
getOpenApiParameters as private traitGetOpenApiParameters;
}
and then setting castToArray to false if it was NULL by adding the following to SortFilter:
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
{
return $this->traitGetOpenApiParameters(
$parameter->withCastToArray(
$parameter->getCastToArray() ?? false,
)
);
}
- Lenguaje dominante
- PHP
- Estrellas
- 2.6k
- Forks
- 988
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 106
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api-platform/core
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Posiblemente ocupada @ousamabenyounes la tomó hace 4 días. Abierto
Dificultad 2/5 Menos de una hora Aptitud para principiantes 80/100
api-platform/core#8701 ·
Los mantenedores suelen responder en 1 día
-
[Json-Schema] Nested resources lost externalDoc and description dataPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
api-platform/core#8721 ·
Los mantenedores suelen responder en 1 día
-
JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` memberPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 50/100
api-platform/core#8704 ·
Los mantenedores suelen responder en 1 día
-
JSON:API: request documents with no `data`, no `type` or a wrong `type` are accepted with 201Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
api-platform/core#8703 ·
Los mantenedores suelen responder en 1 día
-
JSON:API: relations set through the constructor reject spec resource linkage (`relationships.<name>.data`)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
api-platform/core#8702 ·
Los mantenedores suelen responder en 1 día
Todos los issues de api-platform/core
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
verbb/formie#3033 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Type] Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Awaiting Triage enhancement / feature request
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
macOS
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
beyondcode/herd-community#1774 ·