JSON:API: `included` schema is `items: {anyOf: []}` when a relation points to a resource without operations (`NotExposed`)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 65/100
Línea de trabajo
The empty anyOf comes from JsonApi\JsonSchema\SchemaFactory::buildDefinitionPropertiesSchema(), which skips related classes with false === $hasOperations but still writes anyOf when no reference remains. Reproduce with the two resources in the issue and run bin/console api:openapi:export to inspect Book.jsonapi. Done when included.items is a valid schema (for example {"type": "object"}) or has no empty anyOf, and the exported spec passes validation.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
API Platform version(s) affected
4.4.4
Description
A resource has a relation to another resource whose only operation is NotExposed. The included property of the JSON:API document schema is then:
"included": { "type": "array", "items": { "anyOf": [] } }
JSON Schema requires anyOf to be a non-empty array, so the document is invalid. Spectral (oas3-schema) and code generators reject it.
The cause looks like JsonApi\JsonSchema\SchemaFactory::buildDefinitionPropertiesSchema(). It skips a related class when false === $hasOperations, but it still writes anyOf when no reference remains.
How to reproduce
#[ApiResource(operations: [new NotExposed()])]
final class Author
{
public function __construct(public int $id = 1, public string $name = 'Frank Herbert') {}
}
#[ApiResource(operations: [new Get(provider: [self::class, 'provide'])])]
final class Book
{
public function __construct(public int $id = 1, public string $title = 'Dune', public Author $author = new Author()) {}
public static function provide(): self { return new self(); }
}
The Book.jsonapi schema:
"included": {
"description": "Related resources requested via the \"include\" query parameter.",
"type": "array",
"items": { "anyOf": [] },
"readOnly": true
}
Expected: when no related class has a schema reference, included.items is {"type": "object"}, or the anyOf key is left out.
Additional Context
Checked on api-platform/core v4.4.4, Symfony 7.4, PHP 8.5, in an empty Symfony app. The code of JsonApi\JsonSchema\SchemaFactory on main is the same as in v4.4.4.
The app has only FrameworkBundle, TwigBundle and ApiPlatformBundle, with this config:
$c->extension('api_platform', [
'mapping' => ['paths' => ['%kernel.project_dir%/src/ApiResource']],
'formats' => ['jsonapi' => ['application/vnd.api+json']],
'docs_formats' => ['jsonopenapi' => ['application/vnd.openapi+json']],
'doctrine' => ['enabled' => false],
]);
The spec comes from bin/console api:openapi:export.
- Lenguaje dominante
- PHP
- Estrellas
- 2.6k
- Forks
- 989
- Merge medio
- 1 d 22 h
- PR fusionados (30 d)
- 100
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 3 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:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
api-platform/core#8699 ·
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
Todos los issues de api-platform/core
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
-
module: user interface priority: high severity: minor type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[Enhancement] Add a dark-bg Tailwind variantPosiblemente ocupada @bd-viget la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
vigetlabs/wordpress-site-starter#306 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Spomky-Labs/pwa-bundle#476 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día