@@ -3961,6 +3961,54 @@ public void springPaginatedWithSpringDocPrependsToExistingAnnotation() throws Ex
39613961 assertFileContains (petApi .toPath (), "@Parameter(hidden = true) pageable: Pageable" );
39623962 }
39633963
3964+ @ Test
3965+ public void springPaginatedWithSpringDocPrependsToExistingAnnotationArray () throws Exception {
3966+ Map <String , Object > additionalProperties = new HashMap <>();
3967+ additionalProperties .put (USE_TAGS , "true" );
3968+ additionalProperties .put (DOCUMENTATION_PROVIDER , "springdoc" );
3969+ additionalProperties .put (INTERFACE_ONLY , "true" );
3970+ additionalProperties .put (SKIP_DEFAULT_INTERFACE , "true" );
3971+
3972+ Map <String , File > files = generateFromContract ("src/test/resources/3_0/spring/petstore-with-spring-pageable.yaml" , additionalProperties );
3973+
3974+ File petApi = files .get ("PetApi.kt" );
3975+ String content = Files .readString (petApi .toPath ());
3976+
3977+ // Verify that PageableAsQueryParam is imported
3978+ assertFileContains (petApi .toPath (), "import org.springdoc.core.converters.models.PageableAsQueryParam" );
3979+
3980+ // Find the findPetsByStatus method
3981+ int findPetsByStatusStart = content .indexOf ("fun findPetsByStatus(" );
3982+ Assert .assertTrue (findPetsByStatusStart > 0 , "findPetsByStatus method should exist" );
3983+
3984+ // Check the annotations appear before the method in the correct order
3985+ String methodBlock = content .substring (Math .max (0 , findPetsByStatusStart - 1500 ), findPetsByStatusStart );
3986+
3987+ int pageableAsQueryParamPos = methodBlock .lastIndexOf ("@PageableAsQueryParam" );
3988+ int validatedPos = methodBlock .lastIndexOf ("@org.springframework.validation.annotation.Validated" );
3989+ int preAuthorizePos = methodBlock .lastIndexOf ("@org.springframework.security.access.prepost.PreAuthorize" );
3990+ int requestMappingPos = methodBlock .lastIndexOf ("@RequestMapping" );
3991+
3992+ Assert .assertTrue (pageableAsQueryParamPos > 0 , "@PageableAsQueryParam should be present before findPetsByStatus method" );
3993+ Assert .assertTrue (validatedPos > 0 , "@Validated should be present before findPetsByStatus method" );
3994+ Assert .assertTrue (preAuthorizePos > 0 , "@PreAuthorize should be present before findPetsByStatus method" );
3995+
3996+ // Verify @PageableAsQueryParam comes first (prepended to the array)
3997+ Assert .assertTrue (pageableAsQueryParamPos < validatedPos ,
3998+ "@PageableAsQueryParam should be prepended (appear before) @Validated annotation" );
3999+
4000+ // Verify the original array order is preserved after @PageableAsQueryParam
4001+ Assert .assertTrue (validatedPos < preAuthorizePos ,
4002+ "@Validated should appear before @PreAuthorize (original array order preserved)" );
4003+
4004+ // Verify all annotations come before @RequestMapping
4005+ Assert .assertTrue (preAuthorizePos < requestMappingPos ,
4006+ "All annotations should appear before @RequestMapping" );
4007+
4008+ // Verify the Pageable parameter still has @Parameter(hidden = true)
4009+ assertFileContains (petApi .toPath (), "@Parameter(hidden = true) pageable: Pageable" );
4010+ }
4011+
39644012 @ Test
39654013 public void springPaginatedMixedOperations () throws Exception {
39664014 Map <String , Object > additionalProperties = new HashMap <>();
0 commit comments