-
-
Notifications
You must be signed in to change notification settings - Fork 933
Closed
Description
API Platform version(s) affected: 4.2.1
Description
Regarding this commit: 79edced
#6960
All base schemas and item properties are now shared.
Unfortunately, GetCollection on a serialization group that does not match any item operation does not include the HydraItemBaseSchema
How to reproduce
As example : https://github.com/vinise/apip-schema-reproducer
3 different ApiResource
- Car: simple Get
#[Get]
class Car
{
#[ApiProperty(identifier: true)]
public int $id;
public string $name;
}
Generate
"\/cars\/{id}" > ... > "application\/ld+json": {"schema": {"$ref": "#\/components\/schemas\/Car.jsonld"}}
...
"Car.jsonld": {
"allOf": [
{"$ref": "#\/components\/schemas\/HydraItemBaseSchema"},
{"type": "object", "properties": { "id": {"type": "integer"}, "name": {"type": "string"}}}
]
},
✅ HydraItemBaseSchema present
- Train: Get item with group + GetCollection using same group
#[GetCollection(
normalizationContext: ['groups' => ['train:read']],
)]
#[Get(
normalizationContext: ['groups' => ['train:read']],
)]
class Train
{
#[ApiProperty(identifier: true)]
#[Groups(['train:read'])]
public int $id;
#[Groups(['train:read'])]
public string $name;
}
Generate
"\/trains\/{id}" >...> "application\/ld+json": {"schema": {"$ref": "#/components/schemas/Train.jsonld-train.read"}}
"\/trains" >...> "application\/ld+json" > "member": {"type": "array","items": {"$ref": "#\/components\/schemas\/Train.jsonld-train.read"}}
...
"Train.jsonld-train.read": {
"allOf": [
{"$ref": "#\/components\/schemas\/HydraItemBaseSchema"},
{"type": "object", "properties": { "id": {"type": "integer"}, "name": {"type": "string"}}}
]
},
✅ Both operation share the same "item schema" => HydraItemBaseSchema present
- Boat: GetCollection ONLY with group
#[GetCollection(
formats: ['jsonld'],
normalizationContext: ['groups' => ['boat:read']],
)]
class Boat
{
#[ApiProperty(identifier: true)]
#[Groups(['boat:read'])]
public int $id;
#[Groups(['boat:read'])]
public string $name;
}
Generate
"\/boats" > ... > "application\/ld+json" > ... > "member": {"type": "array","items": {"$ref": "#\/components\/schemas\/Boat.jsonld-boat.read"}}
...
"Boat.jsonld-boat.read": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
❌ No separated item sharing the same groups => HydraItemBaseSchema not present
Metadata
Metadata
Assignees
Labels
No labels