@@ -1343,6 +1343,158 @@ public void shouldNotUseTagsForClassname() throws IOException {
13431343 assertThat(notExisting).isNull();
13441344 }
13451345
1346+ @Test
1347+ public void useTags_false_groupsByFirstPathSegment_springHttpInterface() {
1348+ SpringCodegen codegen = new SpringCodegen();
1349+ codegen.setLibrary(SPRING_HTTP_INTERFACE);
1350+ codegen.additionalProperties().put(USE_TAGS, "false");
1351+ codegen.processOpts();
1352+
1353+ CodegenOperation co = new CodegenOperation();
1354+ co.operationId = "findByStatus";
1355+ co.path = "/pet/findByStatus";
1356+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1357+
1358+ codegen.addOperationToGroup("Pet", "/pet/findByStatus", new Operation(), co, groups);
1359+
1360+ assertTrue(groups.containsKey("pet"));
1361+ assertEquals(co.baseName, "pet");
1362+ }
1363+
1364+ @Test
1365+ public void useTags_true_groupsByTag_springHttpInterface() {
1366+ SpringCodegen codegen = new SpringCodegen();
1367+ codegen.setLibrary(SPRING_HTTP_INTERFACE);
1368+ codegen.additionalProperties().put(USE_TAGS, "true");
1369+ codegen.processOpts();
1370+
1371+ CodegenOperation co = new CodegenOperation();
1372+ co.operationId = "findByStatus";
1373+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1374+
1375+ codegen.addOperationToGroup("Pet", "/pet/findByStatus", new Operation(), co, groups);
1376+
1377+ assertTrue(groups.containsKey("Pet"));
1378+ }
1379+
1380+ @Test
1381+ public void useTags_false_groupsByFirstPathSegment_sanitizesInvalidIdentifierChars_springHttpInterface() {
1382+ SpringCodegen codegen = new SpringCodegen();
1383+ codegen.setLibrary(SPRING_HTTP_INTERFACE);
1384+ codegen.additionalProperties().put(USE_TAGS, "false");
1385+ codegen.processOpts();
1386+
1387+ CodegenOperation co = new CodegenOperation();
1388+ co.operationId = "dummy";
1389+ co.path = "/another-fake/dummy";
1390+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1391+
1392+ codegen.addOperationToGroup("$another-fake?", "/another-fake/dummy", new Operation(), co, groups);
1393+
1394+ // the first path segment "another-fake" must be sanitized into a valid Java identifier
1395+ // (no hyphen) instead of being used as-is, which previously produced e.g.
1396+ // "AnotherFakeApi another-fakeHttpProxy()" - invalid Java syntax.
1397+ assertTrue(groups.containsKey("anotherFake"));
1398+ assertEquals(co.baseName, "anotherFake");
1399+ }
1400+
1401+ @Test
1402+ public void useTags_false_pathGroupsRemainDistinctAndOperationIdsUnique_springHttpInterface() {
1403+ SpringCodegen codegen = new SpringCodegen();
1404+ codegen.setLibrary(SPRING_HTTP_INTERFACE);
1405+ codegen.additionalProperties().put(USE_TAGS, "false");
1406+ codegen.processOpts();
1407+
1408+ CodegenOperation first = new CodegenOperation();
1409+ first.operationId = "dummy";
1410+ first.path = "/another-fake/dummy";
1411+ CodegenOperation duplicate = new CodegenOperation();
1412+ duplicate.operationId = "dummy";
1413+ duplicate.path = "/another-fake/other";
1414+ CodegenOperation colliding = new CodegenOperation();
1415+ colliding.operationId = "dummy";
1416+ colliding.path = "/another_fake/dummy";
1417+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1418+
1419+ codegen.addOperationToGroup("First", "/another-fake/dummy", new Operation(), first, groups);
1420+ codegen.addOperationToGroup("Second", "/another-fake/other", new Operation(), duplicate, groups);
1421+ codegen.addOperationToGroup("Third", "/another_fake/dummy", new Operation(), colliding, groups);
1422+
1423+ assertTrue(groups.containsKey("anotherFake"));
1424+ assertTrue(groups.containsKey("anotherFake2"));
1425+ assertEquals(duplicate.operationId, "dummy_0");
1426+ assertEquals(colliding.baseName, "anotherFake2");
1427+ }
1428+
1429+ @Test
1430+ public void useTags_false_groupsRootOperationsAndPrefixesDigitLeadingPath_springHttpInterface() {
1431+ SpringCodegen codegen = new SpringCodegen();
1432+ codegen.setLibrary(SPRING_HTTP_INTERFACE);
1433+ codegen.additionalProperties().put(USE_TAGS, "false");
1434+ codegen.processOpts();
1435+
1436+ CodegenOperation rootGet = new CodegenOperation();
1437+ rootGet.operationId = "getRoot";
1438+ rootGet.path = "/";
1439+ CodegenOperation rootPost = new CodegenOperation();
1440+ rootPost.operationId = "postRoot";
1441+ rootPost.path = "/";
1442+ CodegenOperation digitLeading = new CodegenOperation();
1443+ digitLeading.operationId = "getPets";
1444+ digitLeading.path = "/123/pets";
1445+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1446+
1447+ codegen.addOperationToGroup("Root", "/", new Operation(), rootGet, groups);
1448+ codegen.addOperationToGroup("Root", "/", new Operation(), rootPost, groups);
1449+ codegen.addOperationToGroup("Pets", "/123/pets", new Operation(), digitLeading, groups);
1450+
1451+ assertEquals(groups.get("default").size(), 2);
1452+ assertTrue(groups.containsKey("class123"));
1453+ assertEquals(digitLeading.baseName, "class123");
1454+ assertEquals(codegen.toApiName(digitLeading.baseName), "Class123Api");
1455+ }
1456+
1457+ @Test
1458+ public void useTags_false_pathGroupsWithEmptySanitizedNamesRemainDistinct_springHttpInterface() {
1459+ SpringCodegen codegen = new SpringCodegen();
1460+ codegen.setLibrary(SPRING_HTTP_INTERFACE);
1461+ codegen.additionalProperties().put(USE_TAGS, "false");
1462+ codegen.processOpts();
1463+
1464+ CodegenOperation first = new CodegenOperation();
1465+ first.operationId = "first";
1466+ first.path = "/@/first";
1467+ CodegenOperation second = new CodegenOperation();
1468+ second.operationId = "second";
1469+ second.path = "/!/second";
1470+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1471+
1472+ codegen.addOperationToGroup("First", "/@/first", new Operation(), first, groups);
1473+ codegen.addOperationToGroup("Second", "/!/second", new Operation(), second, groups);
1474+
1475+ assertTrue(groups.containsKey("path"));
1476+ assertTrue(groups.containsKey("path2"));
1477+ assertEquals(codegen.toApiName(second.baseName), "Path2Api");
1478+ }
1479+
1480+ @Test
1481+ public void useTags_false_preservesRawPathGroupName_springCloud() {
1482+ SpringCodegen codegen = new SpringCodegen();
1483+ codegen.setLibrary(SPRING_CLOUD_LIBRARY);
1484+ codegen.additionalProperties().put(USE_TAGS, "false");
1485+ codegen.processOpts();
1486+
1487+ CodegenOperation co = new CodegenOperation();
1488+ co.operationId = "dummy";
1489+ co.path = "/another-fake/dummy";
1490+ Map<String, List<CodegenOperation>> groups = new HashMap<>();
1491+
1492+ codegen.addOperationToGroup("AnotherFake", "/another-fake/dummy", new Operation(), co, groups);
1493+
1494+ assertTrue(groups.containsKey("another-fake"));
1495+ assertEquals(co.baseName, "another-fake");
1496+ }
1497+
13461498 @Test
13471499 public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_issue14723() throws IOException {
13481500 File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
0 commit comments