@@ -1971,4 +1971,103 @@ public function testNormalizeWithPropertySwaggerContext()
1971
1971
1972
1972
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
1973
1973
}
1974
+
1975
+ public function testNormalizeWithPaginationClientEnabled ()
1976
+ {
1977
+ $ documentation = new Documentation (new ResourceNameCollection ([Dummy::class]), 'Test API ' , 'This is a test API. ' , '1.2.3 ' , ['jsonld ' => ['application/ld+json ' ]]);
1978
+
1979
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
1980
+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, [])->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' ]));
1981
+
1982
+ $ dummyMetadata = new ResourceMetadata ('Dummy ' , 'This is a dummy. ' , 'http://schema.example.com/Dummy ' , [], ['get ' => ['method ' => 'GET ' , 'pagination_client_enabled ' => true ]]);
1983
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
1984
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn ($ dummyMetadata );
1985
+
1986
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
1987
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'id ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_INT ), 'This is an id. ' , true , false ));
1988
+ $ 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 ' ]]));
1989
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
1990
+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
1991
+
1992
+ $ operationMethodResolverProphecy = $ this ->prophesize (OperationMethodResolverInterface::class);
1993
+ $ operationMethodResolverProphecy ->getCollectionOperationMethod (Dummy::class, 'get ' )->shouldBeCalled ()->willReturn ('GET ' );
1994
+
1995
+ $ operationPathResolver = new CustomOperationPathResolver (new OperationPathResolver (new UnderscorePathSegmentNameGenerator ()));
1996
+
1997
+ $ normalizer = new DocumentationNormalizer (
1998
+ $ resourceMetadataFactoryProphecy ->reveal (),
1999
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
2000
+ $ propertyMetadataFactoryProphecy ->reveal (),
2001
+ $ resourceClassResolverProphecy ->reveal (),
2002
+ $ operationMethodResolverProphecy ->reveal (),
2003
+ $ operationPathResolver
2004
+ );
2005
+
2006
+ $ expected = [
2007
+ 'swagger ' => '2.0 ' ,
2008
+ 'basePath ' => '/app_dev.php/ ' ,
2009
+ 'info ' => [
2010
+ 'title ' => 'Test API ' ,
2011
+ 'description ' => 'This is a test API. ' ,
2012
+ 'version ' => '1.2.3 ' ,
2013
+ ],
2014
+ 'paths ' => new \ArrayObject ([
2015
+ '/dummies ' => [
2016
+ 'get ' => new \ArrayObject ([
2017
+ 'tags ' => ['Dummy ' ],
2018
+ 'operationId ' => 'getDummyCollection ' ,
2019
+ 'produces ' => ['application/ld+json ' ],
2020
+ 'summary ' => 'Retrieves the collection of Dummy resources. ' ,
2021
+ 'parameters ' => [
2022
+ [
2023
+ 'name ' => 'page ' ,
2024
+ 'in ' => 'query ' ,
2025
+ 'required ' => false ,
2026
+ 'type ' => 'integer ' ,
2027
+ 'description ' => 'The collection page number ' ,
2028
+ ],
2029
+ [
2030
+ 'name ' => 'pagination ' ,
2031
+ 'in ' => 'query ' ,
2032
+ 'required ' => false ,
2033
+ 'type ' => 'boolean ' ,
2034
+ 'description ' => 'Enable or disable pagination ' ,
2035
+ ]
2036
+ ],
2037
+ 'responses ' => [
2038
+ 200 => [
2039
+ 'description ' => 'Dummy collection response ' ,
2040
+ 'schema ' => [
2041
+ 'type ' => 'array ' ,
2042
+ 'items ' => ['$ref ' => '#/definitions/Dummy ' ],
2043
+ ],
2044
+ ],
2045
+ ],
2046
+ ]),
2047
+ ],
2048
+ ]),
2049
+ 'definitions ' => new \ArrayObject ([
2050
+ 'Dummy ' => new \ArrayObject ([
2051
+ 'type ' => 'object ' ,
2052
+ 'description ' => 'This is a dummy. ' ,
2053
+ 'externalDocs ' => ['url ' => 'http://schema.example.com/Dummy ' ],
2054
+ 'properties ' => [
2055
+ 'id ' => new \ArrayObject ([
2056
+ 'type ' => 'integer ' ,
2057
+ 'description ' => 'This is an id. ' ,
2058
+ 'readOnly ' => true ,
2059
+ ]),
2060
+ 'name ' => new \ArrayObject ([
2061
+ 'type ' => 'string ' ,
2062
+ 'description ' => 'This is a name. ' ,
2063
+ 'enum ' => ['one ' , 'two ' ],
2064
+ 'example ' => 'one ' ,
2065
+ ]),
2066
+ ],
2067
+ ]),
2068
+ ]),
2069
+ ];
2070
+
2071
+ $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
2072
+ }
1974
2073
}
0 commit comments