Api Platform Resourcesのロゴ

Api Platform Resources

コミュニティ
fatonh
api-platform-resources

Use when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.

概要

公開者fatonh
リポジトリsymfony-skills
スキル名api-platform-resources
スター
36
フォーク
3
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    fatonhがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルApi Platform ResourcesをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/fatonh/symfony-skills/tree/main/skills/api-platform-resources
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fatonh/symfony-skills.git /tmp/symfony-skills
mkdir -p .claude/skills
cp -r /tmp/symfony-skills/skills/api-platform-resources .claude/skills/api-platform-resources
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでApi Platform Resourcesを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にApi Platform Resourcesを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Api Platform Resourcesは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

API Platform 4 Resources

Prefer DTO resources over exposing entities

Exposing a Doctrine entity directly as #[ApiResource] couples your public API to your schema and leaks persistence concerns. For anything beyond a trivial CRUD prototype, expose a DTO resource backed by a state provider (read) and state processor (write).

php
// ✅ GOOD — a resource DTO, decoupled from the entity
#[ApiResource(
    shortName: 'Order',
    operations: [
        new Get(provider: OrderItemProvider::class),
        new GetCollection(provider: OrderCollectionProvider::class),
        new Post(processor: CreateOrderProcessor::class, input: CreateOrderInput::class),
    ],
    normalizationContext: ['groups' => ['order:read']],
)]
final class OrderResource
{
    public function __construct(
        #[ApiProperty(identifier: true)]
        #[Groups(['order:read'])]
        public string $id,

        #[Groups(['order:read'])]
        public string $status,

        /** @var LineItemResource[] */
        #[Groups(['order:read'])]
        public array $items = [],
    ) {}
}
php
// ❌ BAD — Doctrine entity as the API resource: schema is now your public contract
#[ApiResource]
#[ORM\Entity]
class Order { /* every column auto-exposed, lazy associations serialized, N+1 */ }

If you do expose entities (small internal apps), always scope fields with serialization groups and disable the operations you don't want.

State processors (write side)

A processor receives the input DTO and performs the use case — usually by delegating to an application service / Messenger bus.

php
// ✅ GOOD
/** @implements ProcessorInterface<CreateOrderInput, OrderResource> */
final class CreateOrderProcessor implements ProcessorInterface
{
    public function __construct(private readonly OrderService $orders) {}

    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): OrderResource
    {
        $order = $this->orders->createOrder($data);   // $data is the validated CreateOrderInput

        return OrderResource::fromEntity($order);
    }
}

State providers (read side)

php
// ✅ GOOD — provider returns the read model, not the entity
/** @implements ProviderInterface<OrderResource> */
final class OrderItemProvider implements ProviderInterface
{
    public function __construct(private readonly OrderRepository $orders) {}

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?OrderResource
    {
        $order = $this->orders->find(Uuid::fromString($uriVariables['id']));

        return $order ? OrderResource::fromEntity($order) : null;
    }
}

Use the built-in Pagination in collection providers; don't return unbounded arrays.

Validation

Put Symfony Validator constraints on the input DTO. API Platform validates automatically before the processor runs and returns RFC 9457 problem+json on failure.

php
final class CreateOrderInput
{
    #[Assert\NotBlank]
    #[Assert\Email]
    public string $customerEmail;

    /** @var CreateLineInput[] */
    #[Assert\Valid]
    #[Assert\Count(min: 1)]
    public array $items = [];
}

Operations & security

  • Declare operations explicitly; don't accept the default full CRUD set unless you mean it.
  • Authorize per-operation with security:
php
new Post(security: "is_granted('ROLE_USER')"),
new Delete(security: "is_granted('ORDER_DELETE', object)"),  // voter on the object

Filters & pagination

php
#[ApiResource(
    operations: [new GetCollection()],
    paginationItemsPerPage: 20,
    paginationMaximumItemsPerPage: 100,
)]
#[ApiFilter(SearchFilter::class, properties: ['status' => 'exact', 'customerEmail' => 'partial'])]
#[ApiFilter(OrderFilter::class, properties: ['createdAt' => 'DESC'])]
final class OrderResource { /* ... */ }

For large datasets, see doctrine-query-optimization — switch collection providers to keyset pagination.

Versioning & errors

  • Version through the path prefix or a vendor media type; keep order:read / order:write groups stable.
  • Don't hand-build error responses — API Platform emits RFC 9457 problem+json (see problem-details-rfc9457). Throw domain exceptions mapped to status codes.

Gotchas

  • Agent slaps #[ApiResource] on a Doctrine entity — prefer a DTO resource with provider/processor for non-trivial APIs.
  • Agent leaves all CRUD operations enabled by default — declare only the operations you intend to expose.
  • Agent forgets serialization #[Groups] — every property gets exposed, including sensitive ones.
  • Agent puts business logic in the processor — delegate to an application service; the processor just adapts.
  • Agent returns the entity from a provider — return the resource DTO.
  • Agent disables pagination or returns findAll() from a collection provider — keep pagination on.
  • Agent hand-rolls error JSON — let API Platform produce problem+json; throw mapped exceptions.
  • Agent uses API Platform 2/3 annotations (@ApiResource) — use PHP 8 attributes and the v4 metadata classes (ApiPlatform\Metadata\*).

よくある質問

AIスキル「Api Platform Resources」では何ができますか?

Use when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.

TypingMindでApi Platform Resourcesを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Api Platform Resourcesはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにApi Platform Resourcesをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/fatonh/symfony-skills/tree/main/skills/api-platform-resourcesを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Api Platform Resourcesを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Api Platform Resourcesは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもApi Platform Resourcesを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Api Platform Resources」は無料ですか?

はい。fatonhがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇