]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16364 Do not return rule descriptions in case the field is not requested
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Wed, 8 Jun 2022 09:01:18 +0000 (11:01 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Jun 2022 20:03:15 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
sonar-ws/src/main/protobuf/ws-rules.proto

index 959d168770589f6bf38357962b8e8a140dd1ac16..bb4bda67f29609c80627dfe106a096346e337c8b 100644 (file)
@@ -163,7 +163,7 @@ public class RuleMapper {
 
     if (shouldReturnField(fieldsToReturn, FIELD_DESCRIPTION_SECTIONS) && adHocDescription != null) {
       ruleResponse.clearDescriptionSections();
-      ruleResponse.addDescriptionSectionsBuilder()
+      ruleResponse.getDescriptionSectionsBuilder().addDescriptionSectionsBuilder()
         .setKey(RuleDescriptionSectionDto.DEFAULT_KEY)
         .setContent(macroInterpreter.interpret(adHocDescription));
     }
@@ -339,7 +339,7 @@ public class RuleMapper {
 
     if (shouldReturnField(fieldsToReturn, FIELD_DESCRIPTION_SECTIONS)) {
       for (var section : ruleDto.getRuleDescriptionSectionDtos()) {
-        ruleResponse.addDescriptionSectionsBuilder()
+        ruleResponse.getDescriptionSectionsBuilder().addDescriptionSectionsBuilder()
           .setKey(section.getKey())
           .setContent(retrieveDescriptionContent(ruleDto.getDescriptionFormat(), section))
           .build();
index 7e3f99087c308df54c2d75d18adf2ab6b4003acc..6d4bddd79ff07d327b3b67331e38f7c6e2db755c 100644 (file)
@@ -354,10 +354,9 @@ public class ShowActionTest {
       .extracting(Rule::getName, Rule::getHtmlDesc, Rule::getSeverity, Rule::getType)
       .containsExactlyInAnyOrder("adhoc name", "&lt;div&gt;desc2&lt;/div&gt;", Severity.BLOCKER, VULNERABILITY);
 
-    assertThat(resultRule.getDescriptionSectionsList()).hasSize(1);
-    assertThat(resultRule.getDescriptionSectionsList().get(0))
-      .extracting(r -> r.getKey(), r -> r.getContent())
-      .containsExactly(DEFAULT_KEY, "&lt;div&gt;desc2&lt;/div&gt;");
+    assertThat(resultRule.getDescriptionSections().getDescriptionSectionsList())
+      .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent)
+      .containsExactly(tuple(DEFAULT_KEY, "&lt;div&gt;desc2&lt;/div&gt;"));
   }
 
   @Test
@@ -397,7 +396,7 @@ public class ShowActionTest {
           + "<h2>How can you fix it?</h2>"
           + "<div>I don't want to fix</div><br/>");
 
-    assertThat(resultRule.getDescriptionSectionsList())
+    assertThat(resultRule.getDescriptionSections().getDescriptionSectionsList())
       .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent)
       .containsExactlyInAnyOrder(
         tuple(ROOT_CAUSE_SECTION_KEY, "<div>Root is Root</div>"),
@@ -425,7 +424,7 @@ public class ShowActionTest {
     assertThat(resultRule.getHtmlDesc()).contains("<strong>toto is toto</strong>");
     assertThat(resultRule.getMdDesc()).contains("*toto is toto*");
 
-    assertThat(resultRule.getDescriptionSectionsList())
+    assertThat(resultRule.getDescriptionSections().getDescriptionSectionsList())
       .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent)
       .contains(tuple(DEFAULT_KEY, "<strong>toto is toto</strong>"));
   }
index 76ee26ae340c246d96b2ca1f7fe84452445dd78c..072031faddd5b02a6714dddf9a6793f8de40dd1a 100644 (file)
@@ -122,7 +122,11 @@ message Rule {
   optional sonarqube.ws.commons.RuleScope scope = 46;
   optional bool isExternal = 47;
   optional DeprecatedKeys deprecatedKeys = 48;
-  repeated DescriptionSection descriptionSections = 49;
+  optional DescriptionSections descriptionSections = 49;
+
+  message DescriptionSections {
+    repeated DescriptionSection descriptionSections = 1;
+  }
 
   message DescriptionSection {
     required string key = 1;