0

I have an API working with API-platform 2.6 and I have some breaking changes on my API so I really need to have api/v2 but it looks like there is no versioning support in api-platform. Very simple example is a field that was not mandatory in V1 but it's required in V2.

Community
  • 1
  • 1
Rassoul
  • 174
  • 16

1 Answers1

0

APIP is recommending using a versionless api and use deprecated feild instead you can lear more about here https://api-platform.com/docs/core/deprecations/#deprecating-resources-and-properties-alternative-to-versioning

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

#[ApiResource(deprecationReason: "Create a Book instead")]
class Parchment
{
    // ...
}

You can also depracate a field like this

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;

#[ApiResource]
class Review
{
    // ...

    #[ApiProperty(deprecationReason: "Use the rating property instead")]
    public $letter;
    
    // ...
}
Youssef Saoubou
  • 591
  • 4
  • 11
  • I'm pretty sure i answer this post but i don't understand why it desapeared – Youssef Saoubou Dec 07 '21 at 15:28
  • Yes but it does not work for all situations. How to implement my question with deprecation? Let say there is a $property which was optional formerly, No I want to have the same $property as a required field, Consider that some clients are not sending it and I don't want to apply breaking changes for them, Just new clients which are going to use my API have to send $property from now on. Thanks. – Rassoul Dec 07 '21 at 18:21
  • 1
    For this case you can use validation groups foreach path v1 and v2 where in each one you can define your own validation rules https://api-platform.com/docs/core/validation/#using-validation-groups – Youssef Saoubou Dec 08 '21 at 07:34