@@ -4413,6 +4413,76 @@ public void generateSortValidationDoesNotGenerateValidSortFileWhenBeanValidation
44134413 assertFileNotContains (petApi .toPath (), "@ValidSort" );
44144414 }
44154415
4416+ @ Test
4417+ public void generateSortValidationWorksForArraySortEnum () throws Exception {
4418+ Map <String , Object > additionalProperties = new HashMap <>();
4419+ additionalProperties .put (USE_TAGS , "true" );
4420+ additionalProperties .put (INTERFACE_ONLY , "true" );
4421+ additionalProperties .put (SKIP_DEFAULT_INTERFACE , "true" );
4422+ additionalProperties .put (GENERATE_SORT_VALIDATION , "true" );
4423+
4424+ Map <String , File > files = generateFromContract ("src/test/resources/3_0/spring/petstore-sort-validation.yaml" , additionalProperties );
4425+
4426+ File petApi = files .get ("PetApi.kt" );
4427+ String content = Files .readString (petApi .toPath ());
4428+
4429+ // findPetsWithArraySortEnum: sort is type:array, items have inline enum → @ValidSort applied with Kotlin [] syntax
4430+ int methodStart = content .indexOf ("fun findPetsWithArraySortEnum(" );
4431+ Assert .assertTrue (methodStart >= 0 , "findPetsWithArraySortEnum method should exist" );
4432+ String paramBlock = content .substring (methodStart , Math .min (content .length (), methodStart + 500 ));
4433+ Assert .assertTrue (paramBlock .contains ("@ValidSort(allowedValues = [\" id,asc\" , \" id,desc\" , \" name,asc\" , \" name,desc\" ])" ),
4434+ "@ValidSort with all four enum values should appear on the pageable parameter" );
4435+ Assert .assertTrue (paramBlock .contains ("pageable: Pageable" ),
4436+ "findPetsWithArraySortEnum should have a pageable: Pageable parameter" );
4437+ }
4438+
4439+ @ Test
4440+ public void generateSortValidationWorksForArraySortRefEnum () throws Exception {
4441+ Map <String , Object > additionalProperties = new HashMap <>();
4442+ additionalProperties .put (USE_TAGS , "true" );
4443+ additionalProperties .put (INTERFACE_ONLY , "true" );
4444+ additionalProperties .put (SKIP_DEFAULT_INTERFACE , "true" );
4445+ additionalProperties .put (GENERATE_SORT_VALIDATION , "true" );
4446+
4447+ Map <String , File > files = generateFromContract ("src/test/resources/3_0/spring/petstore-sort-validation.yaml" , additionalProperties );
4448+
4449+ File petApi = files .get ("PetApi.kt" );
4450+ String content = Files .readString (petApi .toPath ());
4451+
4452+ // findPetsWithArraySortRefEnum: sort is type:array, items $ref to PetSort enum → @ValidSort with PetSort values
4453+ int methodStart = content .indexOf ("fun findPetsWithArraySortRefEnum(" );
4454+ Assert .assertTrue (methodStart >= 0 , "findPetsWithArraySortRefEnum method should exist" );
4455+ String paramBlock = content .substring (methodStart , Math .min (content .length (), methodStart + 500 ));
4456+ Assert .assertTrue (paramBlock .contains ("@ValidSort(allowedValues = [\" id,asc\" , \" id,desc\" , \" createdAt,asc\" , \" createdAt,desc\" ])" ),
4457+ "@ValidSort with PetSort enum values should appear on the pageable parameter" );
4458+ }
4459+
4460+ @ Test
4461+ public void generateSortValidationWorksForExternalParamRefArraySort () throws Exception {
4462+ Map <String , Object > additionalProperties = new HashMap <>();
4463+ additionalProperties .put (USE_TAGS , "true" );
4464+ additionalProperties .put (INTERFACE_ONLY , "true" );
4465+ additionalProperties .put (SKIP_DEFAULT_INTERFACE , "true" );
4466+ additionalProperties .put (GENERATE_SORT_VALIDATION , "true" );
4467+
4468+ Map <String , File > files = generateFromContract ("src/test/resources/3_0/spring/petstore-sort-validation.yaml" , additionalProperties );
4469+
4470+ File petApi = files .get ("PetApi.kt" );
4471+ String content = Files .readString (petApi .toPath ());
4472+
4473+ // findPetsWithExternalParamRefArraySort: sort param $ref to external components file,
4474+ // which defines type:array with items $ref to PetSortEnum in the same external file
4475+ int methodStart = content .indexOf ("fun findPetsWithExternalParamRefArraySort(" );
4476+ Assert .assertTrue (methodStart >= 0 , "findPetsWithExternalParamRefArraySort method should exist" );
4477+ String paramBlock = content .substring (methodStart , Math .min (content .length (), methodStart + 500 ));
4478+ Assert .assertTrue (paramBlock .contains ("@ValidSort(allowedValues = [" ),
4479+ "@ValidSort should appear when sort param is resolved from an external $ref parameter" );
4480+ Assert .assertTrue (paramBlock .contains ("\" name,asc\" " ) || paramBlock .contains ("\" id,asc\" " ),
4481+ "@ValidSort should contain the enum values from the external PetSortEnum schema" );
4482+ Assert .assertTrue (paramBlock .contains ("pageable: Pageable" ),
4483+ "findPetsWithExternalParamRefArraySort should have a pageable: Pageable parameter" );
4484+ }
4485+
44164486 // ========== PAGEABLE DEFAULTS TESTS ==========
44174487
44184488 @ Test
0 commit comments