cognesy / instructor-schema
TypeInfo-first schema package for Instructor
v2.0.0
2026-03-13 19:49 UTC
Requires
- php: ^8.3
- cognesy/instructor-pipeline: ^2.0
- cognesy/instructor-utils: ^2.0
- symfony/property-info: ^7.3 || ^8.0
- symfony/type-info: ^7.3 || ^8.0
Requires (Dev)
- icanhazstring/composer-unused: ^0.9.0
- jetbrains/phpstorm-attributes: ^1.2
- maglnet/composer-require-checker: ^4.16
- pestphp/pest: ^2.34
- phpstan/phpstan: ^1.11
- roave/security-advisories: dev-latest
- symfony/var-dumper: ^7.3
- vimeo/psalm: ^6.0
- dev-main
- v2.0.0
- v1.22.0
- v1.21.0
- v1.20.0
- v1.19.0
- v1.18.4
- v1.18.3
- v1.18.2
- v1.18.1
- v1.18.0
- v1.17.0
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.0
- v1.11.0
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.1-RC13
- v1.0.0
- v1.0.0-RC22
- v1.0.0-RC21
- v1.0.0-RC20
- v1.0.0-RC19
- v1.0.0-RC18
- v1.0.0-RC17
- v1.0.0-RC16
- v1.0.0-RC15
- v1.0.0-RC14
- v1.0.0-RC13
- v1.0.0-RC12
- v1.0.0-RC11
- v1.0.0-RC10
- v1.0.0-RC9
- 1.0.0-RC8
- 1.0.0-RC7
- 1.0-rc4
- 1.0-rc3
This package is auto-updated.
Last update: 2026-03-13 19:49:41 UTC
README
packages/schema provides schema mapping and JSON Schema rendering/parsing for Instructor.
Main entry points
Cognesy\Schema\SchemaBuilder- fluent builder for runtime object schemas.Cognesy\Schema\SchemaFactory- buildSchemaobjects from PHP types, classes, objects, or JSON Schema providers.Cognesy\Schema\CallableSchemaFactory- buildSchemafrom callable signatures.Cognesy\Schema\TypeInfo- type normalization and helpers based on Symfony TypeInfo.Cognesy\Schema\JsonSchemaRenderer- renderSchemato JSON Schema.Cognesy\Schema\JsonSchemaParser- parse JSON Schema intoObjectSchema.
Quick start
<?php use Cognesy\Schema\SchemaFactory; $factory = SchemaFactory::default(); $schema = $factory->schema(User::class); $jsonSchema = $factory->toJsonSchema($schema);
Build schemas directly
<?php use Cognesy\Schema\SchemaBuilder; $schema = SchemaBuilder::define('user') ->string('name', 'User name') ->int('age', required: false) ->collection('tags', 'string', required: false) ->schema();
Nullable and default metadata
<?php use Cognesy\Schema\SchemaFactory; use Symfony\Component\TypeInfo\Type; $factory = SchemaFactory::default(); $nickname = $factory->propertySchema( type: Type::string(), name: 'nickname', description: 'Optional nickname', nullable: true, hasDefaultValue: true, defaultValue: null, );
nullable, hasDefaultValue, and defaultValue are preserved when converting:
- PHP reflection ->
Schema Schema-> JSON Schema- JSON Schema ->
Schema
Enum values are preserved as declared (string-backed and int-backed enums are both supported in JSON Schema output).
Parse JSON Schema
<?php use Cognesy\Schema\JsonSchemaParser; $parser = new JsonSchemaParser(); $objectSchema = $parser->fromJsonSchema($jsonSchemaArray);
Tests
./vendor/bin/pest packages/schema/tests --compact