Evolving the API

Class lifetime

A resource or a request that exists only in some revisions.

A whole resource type can be added or retired in a revision. The class implements HasLifetime; its fields keep their own history inside that lifetime.

app/Http/Resources/PodcastResource.php
use Ark4ne\ApiRevisions\Definition\Lifetime;
use Ark4ne\ApiRevisions\Schema\HasLifetime;

final class PodcastResource extends JsonResource implements
    Revisioned,
    HasLifetime
{
    use RevisionedResource;

    public static function revisionedLifetime(): Lifetime
    {
        return Lifetime::since(ApiRevision::Spring26);
    }
}
LifetimeExists
Lifetime::since(A)from A included
Lifetime::until(B)up to B included
Lifetime::since(A)->withUntil(B)from A to B, both included

Outside its lifetime

The class has no shape outside its lifetime: rendering or validating it there throws a DefinitionException. Answer 404 to those clients before you get there:

use Ark4ne\ApiRevisions\Schema\ClassLifetime;

abort_unless(
    ClassLifetime::exists(PodcastResource::class, ApiRevision::current()),
    404,
);

Nesting it

A Schema::resource(PodcastResource::class) field carries the same bounds:

'podcast' => Schema::resource(PodcastResource::class)
    ->since(ApiRevision::Spring26),

Visible in a revision where the class does not exist, it is the check error resource-absent.

Tooling

The check, revision:cache, revision:export, the lock and assertRendersAtEveryRevision() skip the revisions the class does not exist in. A lock file lists the classes existing at its revision. The changelog says "The class is added." in its first revision, and "The class is removed." in the one after its last.