@@ -732,6 +732,100 @@ public function testNormalizeWithOnlyNormalizationGroups()
732
732
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation ));
733
733
}
734
734
735
+ public function testNormalizeWithSwaggerDefinitionName ()
736
+ {
737
+ $ documentation = new Documentation (new ResourceNameCollection ([Dummy::class]), 'Test API ' , 'This is a test API. ' , '1.2.3 ' , ['jsonld ' => ['application/ld+json ' ]]);
738
+
739
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
740
+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, [])->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' ]));
741
+
742
+ $ dummyMetadata = new ResourceMetadata (
743
+ 'Dummy ' ,
744
+ 'This is a dummy. ' ,
745
+ 'http://schema.example.com/Dummy ' ,
746
+ [
747
+ 'get ' => [
748
+ 'method ' => 'GET ' ,
749
+ 'normalization_context ' => [
750
+ DocumentationNormalizer::SWAGGER_DEFINITION_NAME => 'Read ' ,
751
+ ],
752
+ ],
753
+ ]
754
+ );
755
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
756
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn ($ dummyMetadata );
757
+
758
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
759
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'id ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_INT ), 'This is an id. ' , true , false ));
760
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
761
+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
762
+
763
+ $ operationMethodResolverProphecy = $ this ->prophesize (OperationMethodResolverInterface::class);
764
+ $ operationMethodResolverProphecy ->getItemOperationMethod (Dummy::class, 'get ' )->shouldBeCalled ()->willReturn ('GET ' );
765
+
766
+ $ operationPathResolver = new CustomOperationPathResolver (new OperationPathResolver (new UnderscorePathSegmentNameGenerator ()));
767
+
768
+ $ normalizer = new DocumentationNormalizer (
769
+ $ resourceMetadataFactoryProphecy ->reveal (),
770
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
771
+ $ propertyMetadataFactoryProphecy ->reveal (),
772
+ $ resourceClassResolverProphecy ->reveal (),
773
+ $ operationMethodResolverProphecy ->reveal (),
774
+ $ operationPathResolver
775
+ );
776
+
777
+ $ expected = [
778
+ 'swagger ' => '2.0 ' ,
779
+ 'basePath ' => '/app_dev.php/ ' ,
780
+ 'info ' => [
781
+ 'title ' => 'Test API ' ,
782
+ 'description ' => 'This is a test API. ' ,
783
+ 'version ' => '1.2.3 ' ,
784
+ ],
785
+ 'paths ' => new \ArrayObject ([
786
+ '/dummies/{id} ' => [
787
+ 'get ' => new \ArrayObject ([
788
+ 'tags ' => ['Dummy ' ],
789
+ 'operationId ' => 'getDummyItem ' ,
790
+ 'produces ' => ['application/ld+json ' ],
791
+ 'summary ' => 'Retrieves a Dummy resource. ' ,
792
+ 'parameters ' => [
793
+ [
794
+ 'name ' => 'id ' ,
795
+ 'in ' => 'path ' ,
796
+ 'type ' => 'string ' ,
797
+ 'required ' => true ,
798
+ ],
799
+ ],
800
+ 'responses ' => [
801
+ 200 => [
802
+ 'description ' => 'Dummy resource response ' ,
803
+ 'schema ' => ['$ref ' => '#/definitions/Dummy-Read ' ],
804
+ ],
805
+ 404 => ['description ' => 'Resource not found ' ],
806
+ ],
807
+ ]),
808
+ ],
809
+ ]),
810
+ 'definitions ' => new \ArrayObject ([
811
+ 'Dummy-Read ' => new \ArrayObject ([
812
+ 'type ' => 'object ' ,
813
+ 'description ' => 'This is a dummy. ' ,
814
+ 'externalDocs ' => ['url ' => 'http://schema.example.com/Dummy ' ],
815
+ 'properties ' => [
816
+ 'id ' => new \ArrayObject ([
817
+ 'type ' => 'integer ' ,
818
+ 'description ' => 'This is an id. ' ,
819
+ 'readOnly ' => true ,
820
+ ]),
821
+ ],
822
+ ]),
823
+ ]),
824
+ ];
825
+
826
+ $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
827
+ }
828
+
735
829
public function testNormalizeWithOnlyDenormalizationGroups ()
736
830
{
737
831
$ title = 'Test API ' ;
0 commit comments