Add class-level Definition and AdditionalProperty attributes #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for class-level schema definition through two new attributes:
New Features
Definition Attribute: A class-level attribute that provides core schema metadata:
title
: Schema titledescription
: Schema descriptionid
: Schema $idschemaVersion
: Schema version ($schema)AdditionalProperty Attribute: A repeatable class-level attribute for adding any custom schema properties:
name
: Property namevalue
: Property value (supports scalar, array, and object values)Schema Class Updates:
Benefits
Example Usage
Support for PHP union types using oneOf in JSON Schema
This PR adds support for PHP 8.0+ union types (like
string|int|bool
) to the JSON Schema Generator. The implementation represents union types in JSON Schema using the standardoneOf
construct.Problem
Previously, the library couldn't properly handle PHP union types (
string|int
), which are a key feature of modern PHP typing. When generating JSON schemas from classes with union types, the schema wouldn't accurately represent these polymorphic types.Solution
UnionType
class to represent PHP union typesTypeParser
to extract and parse PHP reflection typesProperty
class to serialize union types usingoneOf
Generator
properly handles all union type scenariosExamples
PHP class with union types:
Generated JSON Schema: