softspring / form-schema
Extracts JSON-schema-like metadata from Symfony forms
Requires
- php: >=8.4
- symfony/config: ^6.4 || ^7.4 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.4 || ^8.0
- symfony/form: ^6.4.24 || ^7.4 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.4 || ^8.0
- symfony/validator: ^6.4.24 || ^7.4 || ^8.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.50
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- rector/rector: ^2.3
- symfony/yaml: ^6.4 || ^7.4 || ^8.0
This package is auto-updated.
Last update: 2026-06-05 08:20:58 UTC
README
softspring/form-schema extracts JSON-schema-like metadata from Symfony forms.
This package is still in active development. Its public API, extracted schema shape, and extension points may change before the first stable release.
What It Provides
- Schema extraction from a Symfony
FormInterface, form type class, or form type instance. - Field extractors for scalar fields, compound fields, collections, choices, and buttons.
- Support for explicit
json_schemaandjson_schemeform options. - Basic metadata extraction from labels, help text, defaults, and Symfony validator constraints.
- A Symfony bundle that registers the extractor services and field extractor tags.
Installation
composer require softspring/form-schema:^6.0@dev
If Symfony Flex does not register the bundle automatically, add it manually:
// config/bundles.php return [ Softspring\Component\FormSchema\SfsFormSchemaBundle::class => ['all' => true], ];
Basic Usage
Inject SchemaExtractor and extract a schema from a form type:
use Softspring\Component\FormSchema\Schema\SchemaExtractor; final class ExampleService { public function __construct(private SchemaExtractor $schemaExtractor) { } public function schema(): array { return $this->schemaExtractor->extract(ExampleFormType::class); } }
You can also pass a resolved FormInterface when the form must be created with application-specific options.
Custom Field Extractors
Create a service implementing FieldSchemaExtractorInterface and tag it with softspring.form_schema.field_extractor.
Extractors are evaluated in service order. Return true from supports() only for the fields your extractor owns.
Contributing
See CONTRIBUTING.md.
Report issues and send Pull Requests
Security
See SECURITY.md.
License
This package is free and released under the AGPL-3.0 license.