Skip to content

[Swagger] [Question] [Potential PR] nested object that are not ressources  #2147

Description

@jcotineauCoffreo

Hello everyone, i am opening this issue as a question and an hypothetic PR.

I've faced an issue while using api-platform, quite the same as #285 which is closed now.
to fix it i changed the behavior of the DocumentNormalizer and the SerializerPropertyMetadataFactory so that nested object that are not resource are still displayed in the swagger document; but i am not sure if this changes in behavior still match the philosophy of api-platform.

So here come the example :
I have a TimeRecord, WHICH IS a resource
And two other classes NbHours and Extras that ARE NOT resources

/**
 * Class TimeRecord.
 * @ApiResource
 */
class TimeRecord
{
    /**
     * @var string
     */
    public $id;

    /**
     * @var string
     */
    public $date;

    /**
     * @var string
     */
    public $comment;

    /**
     * @var \App\Entity\NbHours
     */
    public $nbHours;

    /**
     * @var \App\Entity\Extras
     */
    public $extras;

    /**
     * TimeRecord constructor.
     */
    public function __construct()
    {
    }
}

/**
 * Class NbHours.
 */
class NbHours
{
    /**
     * @var int
     */
    public $day = 0;

    /**
     * @var int
     */
    public $night = 0;

    /**
     * NbHours constructor.
     */
    public function __construct()
    {
    }
}

With the default configuration my TimeRecord model with be displayed like this :
timerecordmodel

With the modifications I've done it will display this :
timerercordmodelfixed

Same example with the json returned from operations
Before the modifications :
jsonreturned

After the modifications :
jsonreturnedfixed

I've seen this issue many times and it seemed great to me to have a complete model of an object based on the serialization groups and property types even for non-resource object.

I am a trainee and i have not a lot of knowledge, neither in api-platform nor swagger nor symfony, but i'll be very happy to contribute to this project.

Please excuse me for my poor english,
I am looking forward to hearing from you soon on this subject.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions