}
private void mapDescriptionFields(final MacroInterpreter macroInterpreter) {
- map("htmlDesc", new Mapper<RuleDoc, RuleMappingContext>() {
+ map("htmlDesc", new IndexMapper<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field(), RuleNormalizer.RuleField.HTML_DESCRIPTION.field()) {
@Override
public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) {
if (rule.markdownDescription() != null) {
*/
package org.sonar.server.rule.ws;
+import org.sonar.core.rule.RuleDto.Format;
+
import com.google.common.collect.ImmutableSet;
import org.junit.After;
import org.junit.Before;
result.assertJson(getClass(), "search_2_rules.json", false);
}
+ @Test
+ public void search_2_rules_with_field_selection() throws Exception {
+ ruleDao.insert(session, RuleTesting.newXooX1());
+ ruleDao.insert(session, RuleTesting.newXooX2().setDescription("A *Xoo* rule").setDescriptionFormat(Format.MARKDOWN));
+ session.commit();
+
+ MockUserSession.set();
+ WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(SearchOptions.PARAM_FIELDS, "name,htmlDesc,mdDesc");
+ WsTester.Result result = request.execute();
+
+ result.assertJson(getClass(), "search_2_rules_fields.json", false);
+ }
+
@Test
public void search_debt_rules() throws Exception {
insertDebtCharacteristics(session);
--- /dev/null
+{
+ "total": 2, "p": 1, "ps": 100,
+ "rules": [
+ {
+ "key": "xoo:x2",
+ "name": "Rule x2",
+ "mdDesc": "A *Xoo* rule",
+ "htmlDesc": "A <em>Xoo</em> rule"
+ },
+ {
+ "key": "xoo:x1",
+ "name": "Rule x1",
+ "htmlDesc": "Description x1",
+ }
+ ]}