@@ -431,13 +431,43 @@ $schema = SchemaFactory::object('config')
431431 // Control number of properties
432432 ->minProperties(1)
433433 ->maxProperties(10)
434- ->additionalProperties(false);
434+ // Control additional properties
435+ ->additionalProperties(false); // Disallow additional properties
436+
437+ // Or validate additional properties against a schema
438+ $schema = SchemaFactory::object('config')
439+ ->properties(
440+ SchemaFactory::string('name')->required(),
441+ SchemaFactory::string('type')->required(),
442+ )
443+ ->additionalProperties(
444+ SchemaFactory::string()->minLength(3)
445+ );
435446```
436447
437448``` php
438449// Property names must be alphabetic
439450$schema->isValid(['123' => 'value']); // false
440451$schema->isValid(['validKey' => 'value']); // true
452+
453+ // Additional properties must match schema
454+ $schema->isValid([
455+ 'name' => 'config1',
456+ 'type' => 'test',
457+ 'extra' => 'valid', // valid: string with length >= 3
458+ ]); // true
459+
460+ $schema->isValid([
461+ 'name' => 'config1',
462+ 'type' => 'test',
463+ 'extra' => 'no', // invalid: string too short
464+ ]); // false
465+
466+ $schema->isValid([
467+ 'name' => 'config1',
468+ 'type' => 'test',
469+ 'extra' => 123, // invalid: wrong type
470+ ]); // false
441471```
442472
443473Objects also support pattern-based property validation using ` patternProperties ` :
@@ -918,6 +948,43 @@ $schema->toJson();
918948}
919949```
920950
951+ ### From an Backed Enum
952+
953+ ``` php
954+ use Cortex\JsonSchema\SchemaFactory;
955+
956+ /**
957+ * This is the description of the enum
958+ */
959+ enum PostType: int
960+ {
961+ case Article = 1;
962+ case News = 2;
963+ case Tutorial = 3;
964+ }
965+
966+ // Build the schema from the enum
967+ $schema = SchemaFactory::fromEnum(PostType::class);
968+
969+ // Convert to JSON Schema
970+ $schema->toJson();
971+ ```
972+
973+ ``` json
974+ {
975+ "$schema" : " http://json-schema.org/draft-07/schema#" ,
976+ "type" : " object" ,
977+ "description" : " This is the description of the enum" ,
978+ "properties" : {
979+ "PostType" : {
980+ "type" : " integer" ,
981+ "enum" : [1 , 2 , 3 ]
982+ }
983+ },
984+ "required" : [" PostType" ]
985+ }
986+ ```
987+
921988## Credits
922989
923990- [ Sean Tymon] ( https://github.com/tymondesigns )
0 commit comments