@@ -140,6 +140,65 @@ public function it_supports_definition_of_objects_shorthand(): void
140140 $ this ->assertSame (['namespace ' => 'Order ' ], $ address ->custom ());
141141 }
142142
143+ /**
144+ * @test
145+ */
146+ public function it_supports_definition_of_objects_shorthand_type_ns (): void
147+ {
148+ $ json = \file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . '_files ' . DIRECTORY_SEPARATOR . 'schema_with_objects_shorthand_type_ns.json ' );
149+ $ decodedJson = \json_decode ($ json , true , 512 , \JSON_BIGINT_AS_STRING | \JSON_THROW_ON_ERROR );
150+
151+ $ typeSet = Type::fromShorthand ($ decodedJson );
152+
153+ $ this ->assertCount (1 , $ typeSet );
154+
155+ /** @var ObjectType $type */
156+ $ type = $ typeSet ->first ();
157+ $ this ->assertInstanceOf (ObjectType::class, $ type );
158+ $ this ->assertFalse ($ type ->additionalProperties ());
159+
160+ $ required = $ type ->required ();
161+ $ this ->assertCount (4 , $ required );
162+ $ this ->assertContains ('uuid ' , $ required );
163+ $ this ->assertContains ('salutation ' , $ required );
164+ $ this ->assertContains ('billing_address ' , $ required );
165+ $ this ->assertContains ('shipping_address ' , $ required );
166+
167+ $ properties = $ type ->properties ();
168+ $ this ->assertCount (4 , $ properties );
169+ $ this ->assertArrayHasKey ('uuid ' , $ properties );
170+ $ this ->assertArrayHasKey ('salutation ' , $ properties );
171+ $ this ->assertArrayHasKey ('shipping_address ' , $ properties );
172+ $ this ->assertArrayHasKey ('shipping_address ' , $ properties );
173+
174+ /** @var StringType $uuid */
175+ $ uuid = $ properties ['uuid ' ]->first ();
176+ $ this ->assertInstanceOf (StringType::class, $ uuid );
177+ $ this ->assertSame ('uuid ' , $ uuid ->format ());
178+ $ this ->assertSame (['namespace ' => '/ ' ], $ uuid ->custom ());
179+
180+ /** @var StringType $salutation */
181+ $ salutation = $ properties ['salutation ' ]->first ();
182+ $ this ->assertInstanceOf (StringType::class, $ salutation );
183+ $ this ->assertSame (['MR ' , 'MRS ' ], $ salutation ->enum ());
184+ $ this ->assertSame (['namespace ' => '/Contact ' ], $ salutation ->custom ());
185+
186+ /** @var ReferenceType $billingAddress */
187+ $ billingAddress = $ properties ['billing_address ' ]->first ();
188+ $ this ->assertInstanceOf (ReferenceType::class, $ billingAddress );
189+ $ this ->assertSame (['namespace ' => 'Order ' ], $ billingAddress ->custom ());
190+
191+ /** @var ArrayType $shippingAddress */
192+ $ shippingAddress = $ properties ['shipping_address ' ]->first ();
193+ $ this ->assertInstanceOf (ArrayType::class, $ shippingAddress );
194+ $ this ->assertSame ([], $ shippingAddress ->custom ());
195+
196+ /** @var ReferenceType $address */
197+ $ address = $ shippingAddress ->items ()[0 ]->first ();
198+ $ this ->assertInstanceOf (ReferenceType::class, $ address );
199+ $ this ->assertSame (['namespace ' => 'Order ' ], $ address ->custom ());
200+ }
201+
143202 /**
144203 * @test
145204 */
0 commit comments