Download the PHP package openapi-tools/generator-schema without Composer

On this page you can find all versions of the php package openapi-tools/generator-schema. 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 generator-schema

generator-schema

FileGenerator for OpenAPI Tools that turns gathered schema metadata into PHP source files: readonly value objects, contract interfaces, throwable error wrappers, and property caster attributes for union-typed fields.

Continuous Integration Latest Stable Version Total Downloads License

Requirements

Installation

Where it fits

This package runs during step 4 of the OpenAPI Tools pipeline — after gatherer has built a representation and class names have been resolved with Representation::namespace():

Register Schema before generator-hydrator. Hydrators reflect on the schema classes this generator emits, and the generator run loop include_onces each written file so later generators can depend on freshly emitted types.

Components

Class Purpose
Schema Entry-point FileGenerator; delegates to the internal generators below
Internal\Contract Emits deduplicated contract interfaces with @property PHPDoc
Internal\Error Emits one final \Error subclass per schema
Internal\Schema Emits readonly schema classes, alias classes, and union caster attributes
Internal\Schema\SingleCastUnionToType PropertyCaster for a single union-typed property
Internal\Schema\MultipleCastUnionToType PropertyCaster for an array whose items are a union

Type resolution and PHPDoc formatting delegate to generator-utils (PropertyTypeResolver, UnionTypeUtils, DocBlockBuilder).

Usage

Schema takes a shared nikic/php-parser BuilderFactory and is attached to a package's generators list:

A full configuration example lives in openapi-tools/generator. At minimum you need gathering with schema aliasing enabled when your spec contains structurally identical inline objects:

Direct invocation

Useful in tests and custom tooling:

Generation order

Schema::generate() yields files in a fixed order for every schema in the representation:

  1. Contracts — one interface per unique contract, deduplicated by FQCN across all schemas.
  2. Errors — one \Error subclass at {namespace}\Schema\Error\{SchemaName}.
  3. Schema classes — the readonly value object, any alias classes, and per-property union caster attributes.

Union caster classes are emitted as part of step 3 when a property needs them.

Output layout

Given namespace ApiClients\Client\Example and a component schema named Basic:

Relative path Kind
Contract/Basic.php Interface with @property lines
Schema/Basic.php Final readonly schema class
Schema/Error/Basic.php Final error class
Schema/AliasAbstract/T{hash}/…php Abstract base when aliases exist
Schema/{AliasName}.php Final readonly alias extending the abstract base
Internal/Attribute/CastUnionToType/Single/…php Union property caster
Internal/Attribute/CastUnionToType/Multiple/…php Array-of-union property caster

The {hash} in alias abstract class names is derived from the schema's serialized JSON so structurally identical schemas share one abstract base.

Generated code

Contract interfaces

Interfaces carry @property PHPDoc from the contract properties gathered for that shape. The interface body is empty; schemas implement it:

Schema classes

Every schema class is readonly, implements its contract(s), and exposes metadata through constants:

Constant Visibility Purpose
SCHEMA_JSON private Pretty-printed JSON Schema fragment for runtime validation
SCHEMA_TITLE public OpenAPI title
SCHEMA_DESCRIPTION public OpenAPI description
SCHEMA_EXAMPLE_DATA private Pretty-printed example payload assembled during gathering

Constructor parameters are public promoted properties. Property names in PHP may differ from JSON keys — when they do, EventSauce ObjectHydrator #[MapFrom('json_key')] is attached.

Downstream code (webhook middleware, validators) reads SCHEMA_JSON for JSON Schema validation without shipping a separate schema file.

Nested objects and arrays

OpenAPI shape Generated PHP
Property referencing another component schema Constructor parameter typed to that schema class
array of schema objects #[CastListToType(OtherSchema::class)] on the parameter
Scalar / simple union Native PHP union type on the parameter (string\|int\|float)
Object union (no discriminator) Generated PropertyCaster attribute class on the parameter
Array of object union items Pair of Single + Multiple caster classes

For scalar unions such as Jira-style issue field values, duplicate type tokens are collapsed so you get string\|int\|float, not string\|int\|float\|int:

Object unions without discriminator

When a property resolves to multiple object schemas, the generator emits a PropertyCaster that fingerprints incoming arrays by sorted key names (and enum values when present), then hydrates the matching schema class:

Caster classes live under Internal\Attribute\CastUnionToType\ and are referenced as parameter attributes on the schema constructor.

Schema aliases

When registry records structurally identical inline schemas as aliases (useAliasesForDuplication: true), the generator:

  1. Moves the shared implementation into an abstract readonly class under Schema\AliasAbstract\.
  2. Emits one final readonly alias class per registered name, each extending the abstract base.

The canonical class name from gathering becomes the last alias; the abstract base holds the constructor, constants, and union casters.

Error classes

Each schema gets a final error class extending \Error. Instances carry the HTTP status code and a hydrated copy of the schema:

These are used for error responses registered during gathering (ThrowableSchema in the registry). The representation also tracks an errorClassNameAliased path for deduplicated error shapes; this generator emits the primary Schema\Error\{Name} class.

Supported patterns

Behaviour is locked down through shared fixtures in openapi-tools/test-data. Each YAML file has a matching assertion class under tests/DataTests/.

Fixture What it exercises
Basic Minimal object, $ref, UUID format, response headers
ExampleData Scalars, formats, patterns, arrays, nullable unions, example constants
Aliases Structurally identical inline objects → abstract base + alias classes
NestedSchema Inline nested objects without $ref
NestedReferenceSchema Nested objects via component $ref
TripleNestedSchema Deep nesting with $ref on nested schema keyword
DoubleUseOfTypes OpenAPI 3.1 type array combined with anyOf on one property

Run the suite:

For the full fixture roadmap and situation coverage matrix, see test-data/src/DataSets/PLAN.md.

Related packages

Package Relationship
contract FileGenerator and Package interfaces
representation Input model (Namespaced\Schema, Contract, Property)
gatherer Builds the representation this generator consumes
registry Schema deduplication and alias registration during gathering
generator-utils AST builders and type resolution helpers
generator-hydrator Typically runs after this package
generator CLI and run loop that orchestrates all generators

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT)

Copyright (c) 2026 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of generator-schema with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-json Version ^8.4
eventsauce/object-hydrator Version ^1.5
nikic/php-parser Version ^5.0
openapi-tools/contract Version ^0.1.0
openapi-tools/generator-utils Version ^0.1.0
openapi-tools/representation Version ^0.1.0
openapi-tools/utils Version ^0.1.0
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 openapi-tools/generator-schema contains the following files

Loading the files please wait ...