Skip to content

Commit 93cfbdf

Browse files
committed
Update readme
1 parent 39720e4 commit 93cfbdf

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

README.md

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -793,34 +793,32 @@ final class ContactInfo
793793

794794
## Configuration Options
795795

796-
You can configure the generator behavior using the `GeneratorConfig` class and custom property data extractors:
797-
798796
```php
799797
use Spiral\JsonSchemaGenerator\Generator;
800-
use Spiral\JsonSchemaGenerator\GeneratorConfig;
801798
use Spiral\JsonSchemaGenerator\Validation\AttributeConstraintExtractor;
802799
use Spiral\JsonSchemaGenerator\Validation\PhpDocValidationConstraintExtractor;
803800
use Spiral\JsonSchemaGenerator\Validation\CompositePropertyDataExtractor;
804801

805-
// Basic configuration - enable/disable validation constraints
806-
$config = new GeneratorConfig(enableValidationConstraints: true);
807-
$generator = new Generator(config: $config);
802+
// Use default extractors (recommended for most cases)
803+
$generator = new Generator(
804+
propertyDataExtractor: CompositePropertyDataExtractor::createDefault(),
805+
);
808806

809807
// Advanced configuration - custom property data extractors
810808
$compositeExtractor = new CompositePropertyDataExtractor([
811809
new PhpDocValidationConstraintExtractor(),
812810
new AttributeConstraintExtractor(),
813811
]);
814812

815-
$generator = new Generator(propertyDataExtractor: $compositeExtractor);
816-
817-
// Use default extractors (recommended for most cases)
818-
$generator = new Generator(propertyDataExtractor: CompositePropertyDataExtractor::createDefault());
813+
$generator = new Generator(
814+
ropertyDataExtractor: $compositeExtractor,
815+
);
819816
```
820817

821818
#### Property Data Extractors
822819

823-
The generator uses a modular property data extractor system that allows you to customize how validation constraints are extracted from properties:
820+
The generator uses a modular property data extractor system that allows you to customize how validation constraints are
821+
extracted from properties:
824822

825823
**Available Extractors:**
826824

@@ -875,7 +873,13 @@ $generator = new Generator(
875873
propertyDataExtractor: CompositePropertyDataExtractor::createDefault()
876874
->withExtractor(new CustomConstraintExtractor())
877875
);
876+
```
877+
878+
## Integration with Valinor
878879

880+
The JSON Schema Generator works perfectly with the [Valinor PHP package](https://github.com/CuyZ/Valinor) for complete
881+
data mapping and validation workflows. Valinor can validate incoming data based on the same PHPDoc constraints that the
882+
generator uses to create JSON schemas.
879883

880884
### Installation
881885

@@ -897,12 +901,12 @@ declare(strict_types=1);
897901
namespace App;
898902

899903
use CuyZ\Valinor\Mapper\TreeMapper;
900-
use Spiral\JsonSchemaGenerator\Generator as JsonSchemaGenerator;
904+
use Spiral\JsonSchemaGenerator\Generator;
901905

902906
final readonly class SchemaMapper
903907
{
904908
public function __construct(
905-
private JsonSchemaGenerator $generator,
909+
private Generator $generator,
906910
private TreeMapper $mapper,
907911
) {}
908912

@@ -1031,33 +1035,6 @@ public function createUser(ServerRequestInterface $request): ResponseInterface
10311035
}
10321036
```
10331037

1034-
### Advanced Configuration
1035-
1036-
You can configure both packages to work optimally together:
1037-
1038-
```php
1039-
use CuyZ\Valinor\MapperBuilder;
1040-
use Spiral\JsonSchemaGenerator\Generator;
1041-
use Spiral\JsonSchemaGenerator\GeneratorConfig;
1042-
1043-
// Configure the JSON Schema Generator
1044-
$generatorConfig = new GeneratorConfig(
1045-
enableValidationConstraints: true // Enable PHPDoc constraint extraction
1046-
);
1047-
1048-
// Configure Valinor mapper with flexible options
1049-
$treeMapper = (new MapperBuilder())
1050-
->enableFlexibleCasting() // Allow flexible type casting
1051-
->allowPermissiveTypes() // Allow permissive type handling
1052-
->allowSuperfluousKeys() // Ignore extra keys in input
1053-
->build();
1054-
1055-
$mapper = new SchemaMapper(
1056-
generator: new Generator(config: $generatorConfig),
1057-
mapper: $treeMapper
1058-
);
1059-
```
1060-
10611038
### Error Handling
10621039

10631040
Both packages provide detailed error information:

0 commit comments

Comments
 (0)