aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2022-06-08 11:01:18 +0200
committersonartech <sonartech@sonarsource.com>2022-06-09 20:03:15 +0000
commitce2bdbc131e978ee12a8e526f1beec05273c34d7 (patch)
tree0e987271429eec2c548ba77f8c57cc2035e4b90e
parentcb8b5693d2b7c64f6ef69fc50040b9e2f81cdb33 (diff)
downloadsonarqube-ce2bdbc131e978ee12a8e526f1beec05273c34d7.tar.gz
sonarqube-ce2bdbc131e978ee12a8e526f1beec05273c34d7.zip
SONAR-16364 Do not return rule descriptions in case the field is not requested
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java11
-rw-r--r--sonar-ws/src/main/protobuf/ws-rules.proto6
3 files changed, 12 insertions, 9 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
index 959d1687705..bb4bda67f29 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
@@ -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();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
index 7e3f99087c3..6d4bddd79ff 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
@@ -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>"));
}
diff --git a/sonar-ws/src/main/protobuf/ws-rules.proto b/sonar-ws/src/main/protobuf/ws-rules.proto
index 76ee26ae340..072031faddd 100644
--- a/sonar-ws/src/main/protobuf/ws-rules.proto
+++ b/sonar-ws/src/main/protobuf/ws-rules.proto
@@ -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;