Skip to content

feat(jsonschema): generate schemas with symfony/json-schema - #8683

Draft
soyuka wants to merge 14 commits into
api-platform:mainfrom
soyuka:feat/json-schema-kernel
Draft

soyuka wants to merge 14 commits into
api-platform:mainfrom
soyuka:feat/json-schema-kernel

Conversation

@soyuka

@soyuka soyuka commented Oct 14, 2026

Copy link
Copy Markdown
Member
Q A
Branch? main
Tickets ∅
License MIT
Doc PR todo

Follows symfony/symfony#66685, the JsonSchema component got merged in 8.2 and it was seeded from our json-schema engine. This PR lets API Platform generate its schemas through Symfony\Component\JsonSchema\SchemaGenerator instead of our own SchemaFactory, without Operation leaking into the generation.

It's opt-in for 5.1:

api_platform:
    json_schema:
        generator: true

symfony/json-schema needs PHP 8.4 so it's only suggested, the old factory stays the default and enabling the option without the component throws a LogicException.

How it plugs in:

  • GeneratorSchemaFactory replaces the base api_platform.json_schema.schema_factory, the Hydra/HAL/JSON:API/MCP decorators stay on top.
  • The generator is built once, per-call state (schema type, format, partial, version, property options, declared groups...) travels in Configuration::$context.
  • Our extensions: resource as IRI resolver, ApiProperty provider/enricher, partial update and nested operation definition processors, Hydra item wrapping as a definition processor. Names come from ApiPlatformDefinitionPolicy so they don't change (declared group order is kept, .partial, .jsonMergePatch, _noid).
  • App definition processors join our generator only with #[AsJsonSchemaDefinitionProcessor], FrameworkBundle 8.2 autoconfigures the bare Symfony interfaces for its own generator ([FrameworkBundle][JsonSchema] Add JsonSchemaBundle symfony/symfony#66929) and we don't want those running on resources.

Tests: GoldenSchemaTest pins 46 cases (json, jsonld, jsonhal, jsonapi, mcp, input/output, partial, merge-patch, dialects...) and asserts the old buildSchema() and the new generate() produce the same document. A new phpunit-json-schema-generator CI job installs symfony/json-schema:8.2.x-dev and runs the goldens plus the JSON Schema / OpenAPI functional tests with the generator on.

Draft until these 5.0 fixes found along the way merge up, the goldens skip around them: #8643, #8644, #8652, #8653. Laravel wiring is a follow-up.

soyuka added 14 commits October 6, 2026 22:15
Work in progress for symfony/symfony#64279. Golden tests compare
buildSchema() with generate() on the spiked component
(json-schema-component @ 1e167b63d5f), which has to be autoloaded
locally for now.
Nested resources get the Hydra item wrapper and their operation
description from definition processors, the Hydra decorator keeps
the root envelope. jsonld_nested_output_dto stays skipped until the
5.0 nested output DTO fix is merged up.
api_platform.json_schema.generator (off by default) swaps the base
schema factory for the Symfony JsonSchema generator. Definition
processors are autoconfigured, the Hydra item processor is tagged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant