From: Aurelien Poscia Date: Wed, 8 Jun 2022 09:01:18 +0000 (+0200) Subject: SONAR-16364 Do not return rule descriptions in case the field is not requested X-Git-Tag: 9.5.0.56709~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ce2bdbc131e978ee12a8e526f1beec05273c34d7;p=sonarqube.git SONAR-16364 Do not return rule descriptions in case the field is not requested --- 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", "<div>desc2</div>", Severity.BLOCKER, VULNERABILITY); - assertThat(resultRule.getDescriptionSectionsList()).hasSize(1); - assertThat(resultRule.getDescriptionSectionsList().get(0)) - .extracting(r -> r.getKey(), r -> r.getContent()) - .containsExactly(DEFAULT_KEY, "<div>desc2</div>"); + assertThat(resultRule.getDescriptionSections().getDescriptionSectionsList()) + .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent) + .containsExactly(tuple(DEFAULT_KEY, "<div>desc2</div>")); } @Test @@ -397,7 +396,7 @@ public class ShowActionTest { + "

How can you fix it?

" + "
I don't want to fix

"); - assertThat(resultRule.getDescriptionSectionsList()) + assertThat(resultRule.getDescriptionSections().getDescriptionSectionsList()) .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent) .containsExactlyInAnyOrder( tuple(ROOT_CAUSE_SECTION_KEY, "
Root is Root
"), @@ -425,7 +424,7 @@ public class ShowActionTest { assertThat(resultRule.getHtmlDesc()).contains("toto is toto"); 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, "toto is toto")); } 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;