#64279·symfony

[RFC] symfony/json-schema: TypeInfo → JSON Schema, for both API docs and AI tool schemas

Author: peter-siCreated May 19, 2026Updated Sep 24, 2026
LabelsRFC

The gap

"PHP class → JSON Schema" has been independently reimplemented across the ecosystem at least seven times: api-platform/json-schema, Limenius/Liform, cognesy/instructor-php, neuron-core/neuron-ai, the three parallel PHP MCP SDKs (php-mcp/server, the official modelcontextprotocol/php-sdk, logiscape/mcp-sdk-php), and most recently symfony/ai PR #1683 (Symfony\AI\Platform\Contract\JsonSchema\Factory, merged 2026-03-04). That PR explicitly declined to depend on api-platform/json-schema because it hard-requires api-platform/metadata: ^4.3 and won't accept a bare PHP class. Meanwhile the most-used PHP OpenAI client (openai-php/client, 25M+ downloads) ships zero schema generation — users hand-write parameters arrays. There is no shared primitive.

Proposal

A new Symfony\Component\JsonSchema, sibling to JsonStreamer.

  • Entry points: fromType(Type): array, fromClass(string): array. No Operation, no metadata factories — a bare type/class is enough.
  • Substrate: symfony/type-info (stable in 7.4) + symfony/property-info + optional symfony/serializer for groups/naming.
  • Symmetric: request and response shapes through one engine.
  • Two dialects via a switch — JSON Schema 2020-12 (AI tool calls, MCP, structured outputs) and OpenAPI 3.1 (API docs). Same generator, different serialization.
  • Out of scope: HTTP routing, OpenAPI document assembly, JSON-LD/HAL/JSON:API representations.

Day-one adopters

  • API Platform replaces its internal SchemaFactory, keeps its $format/JSON-LD layer on top.
  • symfony/ai deletes Contract\JsonSchema\Factory and depends on core (the architecture from #1683 fits directly).
  • The three PHP MCP SDKs consolidate onto a single engine instead of three.
  • Nelmio API Doc Bundle finally infers responses from controller return types instead of requiring #[OA\Response] on every endpoint.
  • AI client SDKs (starting with openai-php/client) can stop pushing hand-written JSON Schema onto users.

Why now

TypeInfo (7.4) describes types in code. JsonStreamer (7.3) encodes them at runtime. JsonSchema would describe them at the wire — the missing leg of the triangle. Without it, the next consumer (a JsonStreamer schema-export, the next AI SDK, growth of MCP tooling) becomes reimplementation #8.

Open questions

  • Default dialect: JSON Schema 2020-12 or draft-07?
  • Extract symfony/ai's Factory into the new component, or keep + alias?
  • Validator-constraint bridge in-tree, or as a separate symfony/json-schema-validator-bridge?

Happy to expand any section into a follow-up comment — extensibility interfaces, attribute design, migration sketches, full PHP example, performance considerations, semver path for symfony/ai.