]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16614 add to api/rules/search and api/rules/show payload, the subfield key...
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Thu, 7 Jul 2022 08:36:32 +0000 (10:36 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 8 Jul 2022 20:02:48 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/rule/ws/search-example.json
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/rule/ws/show-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
sonar-ws/src/main/protobuf/ws-rules.proto

index 682fc6a3efac3f2a705fa27c3eeca7da8857b248..196cf330a26fb0a5e44d23b7c26786df42e05a8f 100644 (file)
@@ -435,7 +435,10 @@ public class RuleMapper {
 
   private static Optional<Rules.Rule.DescriptionSection.Context> toProtobufContext(@Nullable RuleDescriptionSectionContextDto context) {
     return Optional.ofNullable(context)
-      .map(c -> newBuilder().setDisplayName(c.getDisplayName()).build());
+      .map(c -> newBuilder()
+        .setKey(c.getKey())
+        .setDisplayName(c.getDisplayName())
+        .build());
   }
 
   private static boolean isRemediationFunctionOverloaded(RuleDto rule) {
index 830e47115653d853105d8b259d07014174c93253..cc1dfc766223c51c2066477c08045c2e90bab96a 100644 (file)
           "key": "how_to_fix",
           "content": "<h2>Recommended Secure Coding Practices</h2><ul><li> activate Spring Security's CSRF protection. </li></ul>",
           "context": {
-            "displayName": "Spring"
+            "displayName": "Spring",
+            "key": "spring"
           }
         },
         {
           "key": "how_to_fix",
           "content": "<h2>Recommended Secure Coding Practices</h2><ul><li> activate hibernate protection. </li></ul>",
           "context": {
-            "displayName": "Hibernate"
+            "displayName": "Hibernate",
+            "key": "hibernate"
           }
         }
       ],
index efdc0860facc4be493d2c643fa31be64536e1669..ea42b51a8427b5d7ab52bfd8d4a069f9d5cb34a5 100644 (file)
             "key": "how_to_fix",
             "content": "<h2>Recommended Secure Coding Practices</h2><ul><li> activate Spring Security's CSRF protection. </li></ul>",
             "context": {
-                "displayName": "Spring"
+                "displayName": "Spring",
+                "key": "spring"
             }
         },
         {
             "key": "how_to_fix",
             "content": "<h2>Recommended Secure Coding Practices</h2><ul><li> activate hibernate protection. </li></ul>",
             "context": {
-                "displayName": "Hibernate"
+                "displayName": "Hibernate",
+                "key": "hibernate"
             }
         }
     ],
index de9ff93ddda2f2a6be542ba68bd4746c0e1b012d..a4b683a504005bf59ee402b86579a80c778f3535 100644 (file)
@@ -97,6 +97,7 @@ import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVATION;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_COMPARE_TO_PROFILE;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_RULE_KEY;
+import static org.sonarqube.ws.Rules.Rule.DescriptionSection.Context.newBuilder;
 
 public class SearchActionTest {
 
@@ -500,10 +501,11 @@ public class SearchActionTest {
       .build();
   }
 
-  private static Rule.DescriptionSection toProtobufDto(RuleDescriptionSectionDto s) {
-    Rule.DescriptionSection.Builder builder = Rule.DescriptionSection.newBuilder().setKey(s.getKey()).setContent(s.getContent());
-    if (s.getContext() != null) {
-      builder.setContext(Rule.DescriptionSection.Context.newBuilder().setDisplayName(s.getContext().getDisplayName()).build());
+  private static Rule.DescriptionSection toProtobufDto(RuleDescriptionSectionDto section) {
+    Rule.DescriptionSection.Builder builder = Rule.DescriptionSection.newBuilder().setKey(section.getKey()).setContent(section.getContent());
+    if (section.getContext() != null) {
+      RuleDescriptionSectionContextDto context = section.getContext();
+      builder.setContext(newBuilder().setKey(context.getKey()).setDisplayName(context.getDisplayName()).build());
     }
     return builder.build();
   }
index 2645ff9c9904ddf35f95900f85f175dfb18fbfd1..54b5775528a458961cd8c96eaa60e8879657fdb3 100644 (file)
@@ -394,13 +394,13 @@ public class ShowActionTest {
     assertThat(resultRule.getMdDesc()).isEqualTo(resultRule.getHtmlDesc());
 
     assertThat(resultRule.getDescriptionSections().getDescriptionSectionsList())
-      .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent, section -> section.getContext().getDisplayName())
+      .extracting(Rule.DescriptionSection::getKey, Rule.DescriptionSection::getContent, section -> section.getContext().getKey(), section -> section.getContext().getDisplayName())
       .containsExactlyInAnyOrder(
-        tuple(ROOT_CAUSE_SECTION_KEY, "<div>Root is Root</div>", ""),
-        tuple(ASSESS_THE_PROBLEM_SECTION_KEY, "<div>This is not a problem</div>", ""),
-        tuple(HOW_TO_FIX_SECTION_KEY, "<div>I don't want to fix</div>", ""),
-        tuple(RESOURCES_SECTION_KEY, "<div>I want to fix with Spring</div>", section4context1.getContext().getDisplayName()),
-        tuple(RESOURCES_SECTION_KEY, "<div>I want to fix with Servlet</div>", section4context2.getContext().getDisplayName())
+        tuple(ROOT_CAUSE_SECTION_KEY, "<div>Root is Root</div>", "", ""),
+        tuple(ASSESS_THE_PROBLEM_SECTION_KEY, "<div>This is not a problem</div>", "", ""),
+        tuple(HOW_TO_FIX_SECTION_KEY, "<div>I don't want to fix</div>", "", ""),
+        tuple(RESOURCES_SECTION_KEY, "<div>I want to fix with Spring</div>", section4context1.getContext().getKey(), section4context1.getContext().getDisplayName()),
+        tuple(RESOURCES_SECTION_KEY, "<div>I want to fix with Servlet</div>", section4context2.getContext().getKey(), section4context2.getContext().getDisplayName())
       );
   }
 
index fb943a1d97ed70e7a73914aec48604e245641a6e..e1772529d3c8fc575416214ae3cf6e67f2d46ad3 100644 (file)
@@ -135,6 +135,7 @@ message Rule {
 
     message Context {
       required string displayName = 1;
+      required string key = 2;
     }
   }