@@ -1785,4 +1785,93 @@ public function testNormalizeWithSubResource()
1785
1785
1786
1786
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation ));
1787
1787
}
1788
+
1789
+ public function testNormalizeWithPropertySwaggerContext ()
1790
+ {
1791
+ $ documentation = new Documentation (new ResourceNameCollection ([Dummy::class]), 'Test API ' , 'This is a test API. ' , '1.2.3 ' , ['jsonld ' => ['application/ld+json ' ]]);
1792
+
1793
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
1794
+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, [])->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' ]));
1795
+
1796
+ $ dummyMetadata = new ResourceMetadata ('Dummy ' , 'This is a dummy. ' , 'http://schema.example.com/Dummy ' , ['get ' => ['method ' => 'GET ' ]]);
1797
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
1798
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn ($ dummyMetadata );
1799
+
1800
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
1801
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'id ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_INT ), 'This is an id. ' , true , false ));
1802
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'name ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_STRING ), 'This is a name. ' , true , true , true , true , false , false , null , null , ['swagger_context ' => ['type ' => 'string ' , 'enum ' => ['one ' , 'two ' ], 'example ' => 'one ' ]]));
1803
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
1804
+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
1805
+
1806
+ $ operationMethodResolverProphecy = $ this ->prophesize (OperationMethodResolverInterface::class);
1807
+ $ operationMethodResolverProphecy ->getItemOperationMethod (Dummy::class, 'get ' )->shouldBeCalled ()->willReturn ('GET ' );
1808
+
1809
+ $ operationPathResolver = new CustomOperationPathResolver (new OperationPathResolver (new UnderscorePathSegmentNameGenerator ()));
1810
+
1811
+ $ normalizer = new DocumentationNormalizer (
1812
+ $ resourceMetadataFactoryProphecy ->reveal (),
1813
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
1814
+ $ propertyMetadataFactoryProphecy ->reveal (),
1815
+ $ resourceClassResolverProphecy ->reveal (),
1816
+ $ operationMethodResolverProphecy ->reveal (),
1817
+ $ operationPathResolver
1818
+ );
1819
+
1820
+ $ expected = [
1821
+ 'swagger ' => '2.0 ' ,
1822
+ 'basePath ' => '/app_dev.php/ ' ,
1823
+ 'info ' => [
1824
+ 'title ' => 'Test API ' ,
1825
+ 'description ' => 'This is a test API. ' ,
1826
+ 'version ' => '1.2.3 ' ,
1827
+ ],
1828
+ 'paths ' => new \ArrayObject ([
1829
+ '/dummies/{id} ' => [
1830
+ 'get ' => new \ArrayObject ([
1831
+ 'tags ' => ['Dummy ' ],
1832
+ 'operationId ' => 'getDummyItem ' ,
1833
+ 'produces ' => ['application/ld+json ' ],
1834
+ 'summary ' => 'Retrieves a Dummy resource. ' ,
1835
+ 'parameters ' => [
1836
+ [
1837
+ 'name ' => 'id ' ,
1838
+ 'in ' => 'path ' ,
1839
+ 'type ' => 'string ' ,
1840
+ 'required ' => true ,
1841
+ ],
1842
+ ],
1843
+ 'responses ' => [
1844
+ 200 => [
1845
+ 'description ' => 'Dummy resource response ' ,
1846
+ 'schema ' => ['$ref ' => '#/definitions/Dummy ' ],
1847
+ ],
1848
+ 404 => ['description ' => 'Resource not found ' ],
1849
+ ],
1850
+ ]),
1851
+ ],
1852
+ ]),
1853
+ 'definitions ' => new \ArrayObject ([
1854
+ 'Dummy ' => new \ArrayObject ([
1855
+ 'type ' => 'object ' ,
1856
+ 'description ' => 'This is a dummy. ' ,
1857
+ 'externalDocs ' => ['url ' => 'http://schema.example.com/Dummy ' ],
1858
+ 'properties ' => [
1859
+ 'id ' => new \ArrayObject ([
1860
+ 'type ' => 'integer ' ,
1861
+ 'description ' => 'This is an id. ' ,
1862
+ 'readOnly ' => true ,
1863
+ ]),
1864
+ 'name ' => new \ArrayObject ([
1865
+ 'type ' => 'string ' ,
1866
+ 'description ' => 'This is a name. ' ,
1867
+ 'enum ' => ['one ' , 'two ' ],
1868
+ 'example ' => 'one ' ,
1869
+ ]),
1870
+ ],
1871
+ ]),
1872
+ ]),
1873
+ ];
1874
+
1875
+ $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
1876
+ }
1788
1877
}
0 commit comments