Array of Instances in Annotations
See original GitHub issueI have two objects.
Order and OrderItems. One order contains mutliple orderItems.
How can I define this relation without using doctrine (defining a ManyToOne relation), that swagger graphs the right attributes?
My Order entity:
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* collectionOperations={
* "post"={
* "method"="POST",
* "path"="/orders/check",
* "controller"=App\Controller\Order\CheckOrderController::class,
* "denormalization_context"={"groups"={"check_order"}}
* }
* },
* itemOperations={}
* )
*/
class Order
{
/**
* @var float
* @Groups({"check_order"})
*/
private $price;
/**
* @var OrderItem[] <-- does not work
* @Groups({"check_order"})
*/
private $orderItems = [];
// ...
}
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource()
*/
class OrderItem
{
/**
* @var string
* @Groups({"check_order"})
*/
private $productId;
/**
* @var string
* @Groups({"check_order"})
*/
private $title;
// ...
}
Here the swagger preview:
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Java Annotation - array of Objects or toString values
I need to write an Annotation to exclude certain values from a result set. Background: Distinct values are selected from fields and are ......
Read more >How to Add Type and Repeating Annotations to Code in Java 8
Notice the @Repeatable annotation indicates repeating instances of musical instrument can be stored in a collection (e.g., an array) returned by the value ......
Read more >How to Create Array of Objects in Java? - GeeksforGeeks
An Array of Objects is created using the Object class, and we know Object class is the root class of all Classes. We...
Read more >Allow specifying array annotation attribute single value without ...
Kotlin should allow specifying annotation attribute single value without arrayOf() . I thought initially that Kotlin did not handle that use case like...
Read more >Array types - Documentation - Psalm
In Psalm this annotation is equivalent to @psalm-return array<array-key, ... the key offsets are known: array shapes, also known as "object-like arrays".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I found a workaround that works in my case using swagger_context.
Lodging Entity:
Manager Entity:
Result:
Without Doctrine it doesn’t work, I’ve just tried it. Thank you anyway.