Download the PHP package zeusi/json-schema-extractor without Composer

On this page you can find all versions of the php package zeusi/json-schema-extractor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-schema-extractor

JSON Schema Extractor

Packagist Version PHP CI PHPStan Coverage

JSON Schema Extractor generates JSON Schema documents from PHP DTOs by extracting native types, PHPDoc, validation constraints, and serialization metadata through a modular pipeline.

Typical use cases include:

Features

Installation

The core package has no mandatory dependencies. Some components need optional packages depending on the metadata source you want to use:

Install only the packages needed by the discoverers, enrichers, or serialization strategies you enable.

Quick Example

Given a small DTO:

Create an extractor:

The resulting schema includes native PHP types from reflection and PHPDoc information read by the enabled enricher, such as list item types and shaped array fields:

For executable examples, see bin/schema.php.

Architecture

Extraction is intentionally split into separate phases:

  1. Discover the PHP class model
  2. Enrich that PHP model with metadata from PHPDoc, attributes, validators, or custom sources
  3. Project the enriched PHP model into the serialized output shape
  4. Map the serialized output shape to JSON Schema

When instantiating SchemaExtractor, choose components according to the metadata you trust and the serializer you actually use at runtime.

Custom behavior can be added by implementing a discoverer, enricher, serialization strategy, or mapper.

Symfony Bundle

The Symfony bundle registers the built-in components as services. It reduces the boilerplate needed to define extractor pipelines, especially when using Symfony Serializer and Symfony Validator services. Each extractor must explicitly choose the serialization strategy that matches the JSON produced by the application.

See docs/symfony-bundle.md for bundle configuration and available Symfony integration details.

Components

Discoverer

ReflectionDiscoverer is the default and currently only discoverer. It creates the baseline PHP model by reading class properties and native PHP types through reflection, optionally using the class short name as the schema title.

To create a custom discoverer implement DiscovererInterface.

Enrichers

Enrichers mutate the PHP model before serialization projection. They should merge information where possible and avoid overwriting stronger information with weaker inferred metadata. They run sequentially, so their order can still matter when two enrichers write to the same part of the model.

Component Use it when Documentation
PhpStanEnricher To extract high-precision PHPDoc types, including shaped arrays, generics, ranges, and literal types. docs/enrichers/phpstan.md
PhpDocumentorEnricher To extract DocBlock summaries, descriptions, examples, deprecation, and PHPDoc types via phpdocumentor/reflection-docblock. docs/enrichers/phpdocumentor.md
SymfonyValidationEnricher You want Symfony Validator constraints reflected in the schema as requiredness, formats, limits, and collection shapes. docs/enrichers/symfony-validation.md

For a side-by-side capability matrix of the two PHPDoc enrichers, see docs/enrichers/phpdoc-enricher-comparison.md.

To create a custom enricher implement EnricherInterface.

Serialization Strategies

Serialization strategies convert the enriched PHP model into the JSON-facing payload consumed by the mapper. They are the right place for output field names, omitted fields, discriminator fields, root payload changes, and serializer-specific normalized types.

Component Use it when Documentation
JsonEncodeSerializationStrategy Your JSON payload follows PHP json_encode() behavior, including JsonSerializable return shapes when documented. docs/serialization/json-encode.md
SymfonySerializerStrategy Your JSON payload is produced by Symfony Serializer, including groups, serialized names, name converters, and known normalizers. docs/serialization/symfony-serializer.md

To create a custom serialization strategy implement SerializationStrategyInterface.

Mapper

StandardJsonSchemaMapper is the default and currently only mapper. It converts the serialized payload model to JSON Schema. By default, class-backed DTOs and enums are collected in reusable definitions and referenced with $ref. The emitted definition keyword follows the configured dialect: definitions for Draft-7 and $defs for Draft 2020-12.

Nested objects and complex structures are handled recursively. With ClassReferenceStrategy::Definitions, class-backed types are emitted once as reusable definitions and reused through $ref. Circular references are always broken with $ref.

Mapper-level schema policy is configured through StandardJsonSchemaMapperOptions:

The default dialect is Draft-7 and the root $schema keyword is omitted unless includeSchemaKeyword is enabled. If you prefer class-backed schemas to be expanded at the usage site, use ClassReferenceStrategy::Inline.

To create a custom mapper implement JsonSchemaMapperInterface.

Schema Semantics

additionalProperties

Class-based object schemas are strict by default: SchemaExtractorOptions defaults to additionalProperties: false. This is meant to make DTO-shaped schemas describe the known serialized payload, not an open-ended object.

You can override that default per class with #[AdditionalProperties(true)]. Inline object shapes can also carry their own additionalProperties value, for example shaped dictionaries or Symfony Validator Collection constraints.

Dictionary-style PHPDoc types such as array<string, T> are represented as JSON objects whose additionalProperties value is the schema for T.

required

required means that a field is expected to be present in the serialized payload. It does not mean that the field value cannot be null. The extractor does not infer required from PHP non-nullable types alone; enrichers and serialization strategies can mark fields as required or optional when their metadata describes payload presence.

Limitations

License

This project is licensed under the MIT License. See the LICENSE file for details.


All versions of json-schema-extractor with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zeusi/json-schema-extractor contains the following files

Loading the files please wait ...