@@ -32,11 +32,35 @@ public static function fromShorthand(array $shorthand, ?string $name = null): Ty
3232 public static function fromDefinition (array $ definition , ?string $ name = null ): TypeSet
3333 {
3434 if (! isset ($ definition ['type ' ])) {
35- if (isset ($ definition ['$ref ' ])) {
36- return new TypeSet (ReferenceType::fromDefinition ($ definition , $ name ));
35+ switch (true ) {
36+ case isset ($ definition ['$ref ' ]):
37+ return new TypeSet (ReferenceType::fromDefinition ($ definition , $ name ));
38+ case isset ($ definition ['anyOf ' ]):
39+ $ definition ['type ' ] = AnyOfType::type ();
40+ break ;
41+ case isset ($ definition ['oneOf ' ]):
42+ $ definition ['type ' ] = OneOfType::type ();
43+ break ;
44+ case isset ($ definition ['allOf ' ]):
45+ $ definition ['type ' ] = AllOfType::type ();
46+ break ;
47+ case isset ($ definition ['not ' ]):
48+ $ definition ['type ' ] = NotType::type ();
49+ break ;
50+ case isset ($ definition ['const ' ]):
51+ $ definition ['type ' ] = ConstType::type ();
52+ break ;
53+ case isset ($ definition ['patternProperties ' ])
54+ || isset ($ definition ['properties ' ])
55+ || isset ($ definition ['additionalProperties ' ])
56+ || isset ($ definition ['required ' ]):
57+ $ definition ['type ' ] = ObjectType::type ();
58+ break ;
59+ case \count ($ definition ) === 0 :
60+ return new TypeSet (MixedType::fromDefinition ($ definition , $ name ));
61+ default :
62+ throw new \RuntimeException (\sprintf ('The "type" is missing in schema definition for "%s" ' , $ name ));
3763 }
38-
39- throw new \RuntimeException (\sprintf ('The "type" is missing in schema definition for "%s" ' , $ name ));
4064 }
4165
4266 $ definitionTypes = (array ) $ definition ['type ' ];
@@ -67,6 +91,21 @@ public static function fromDefinition(array $definition, ?string $name = null):
6791 case 'array ' :
6892 $ types [] = ArrayType::fromDefinition ($ definition , $ name );
6993 break ;
94+ case 'oneOf ' :
95+ $ types [] = OneOfType::fromDefinition ($ definition , $ name );
96+ break ;
97+ case 'anyOf ' :
98+ $ types [] = AnyOfType::fromDefinition ($ definition , $ name );
99+ break ;
100+ case 'allOf ' :
101+ $ types [] = AllOfType::fromDefinition ($ definition , $ name );
102+ break ;
103+ case 'not ' :
104+ $ types [] = NotType::fromDefinition ($ definition , $ name );
105+ break ;
106+ case 'const ' :
107+ $ types [] = ConstType::fromDefinition ($ definition , $ name );
108+ break ;
70109 case 'null ' :
71110 case 'Null ' :
72111 case 'NULL ' :
@@ -84,7 +123,9 @@ public static function fromDefinition(array $definition, ?string $name = null):
84123 }
85124
86125 foreach ($ types as $ type ) {
87- $ type ->setNullable ($ isNullable );
126+ if ($ type instanceof NullableAware) {
127+ $ type ->setNullable ($ isNullable );
128+ }
88129 }
89130
90131 return new TypeSet (...$ types );
0 commit comments