public RuleRestResponse toRuleRestResponse(RuleInformation ruleInformation) {

    RuleRestResponse.Builder builder = RuleRestResponse.Builder.builder();
    RuleDto ruleDto = ruleInformation.ruleDto();
    builder
      .setId(ruleDto.getUuid())
      .setKey(ruleDto.getKey().toString())
      .setRepositoryKey(ruleDto.getRepositoryKey())
      .setName(ruleDto.getName())
      .setSeverity(ruleDto.getSeverityString())
      .setType(RuleTypeRestEnum.from(RuleType.valueOf(ruleDto.getType())))
      .setImpacts(toImpactRestResponse(ruleDto.getDefaultImpacts()))
      .setCleanCodeAttribute(CleanCodeAttributeRestEnum.from(ruleDto.getCleanCodeAttribute()))
      .setCleanCodeAttributeCategory(ofNullable(ruleDto.getCleanCodeAttribute())
        .map(CleanCodeAttribute::getAttributeCategory)
        .map(CleanCodeAttributeCategoryRestEnum::from)
        .orElse(null))
      .setStatus(RuleStatusRestEnum.from(ruleDto.getStatus()))
      .setExternal(ruleDto.isExternal())
      .setCreatedAt(toDateTime(ruleDto.getCreatedAt()))
      .setGapDescription(ruleDto.getGapDescription())
      .setHtmlNote(ofNullable(ruleDto.getNoteData()).map(n -> macroInterpreter.interpret(Markdown.convertToHtml(n))).orElse(null))
      .setMarkdownNote(ruleDto.getNoteData())
      .setEducationPrinciples(new ArrayList<>(ruleDto.getEducationPrinciples()))
      .setTemplate(ruleDto.isTemplate())
      .setTemplateId(ruleDto.getTemplateUuid())
      .setTags(new ArrayList<>(ruleDto.getTags()))
      .setSystemTags(new ArrayList<>(ruleDto.getSystemTags()))
      .setLanguageKey(ruleDto.getLanguage())
      .setLanguageName(getLanguageName(ruleDto.getLanguage()))
      .setParameters(toRuleParameterResponse(ruleInformation.params()));

    setDescriptionFields(builder, ruleDto);
    setRemediationFunctionFields(builder, ruleDto);

    if (ruleDto.isAdHoc()) {
      ofNullable(ruleDto.getAdHocName()).ifPresent(builder::setName);
      ofNullable(ruleDto.getAdHocDescription())
        .map(this::toDescriptionSectionResponse)
        .ifPresent(section -> builder.setDescriptionSections(List.of(section)));
      ofNullable(ruleDto.getAdHocSeverity()).ifPresent(builder::setSeverity);
      ofNullable(ruleDto.getAdHocType()).ifPresent(type -> builder.setType(RuleTypeRestEnum.from(RuleType.valueOf(type))));
    }
    return builder.build();
  }
@Test
  public void toRuleRestResponse_shouldReturnNullFields_whenRuleIsEmpty() {
    RuleDto dto = new RuleDto().setRuleKey("key").setRepositoryKey("repoKey").setStatus(RuleStatus.READY).setType(RuleType.BUG.getDbConstant());
    RuleRestResponse ruleRestResponse = ruleRestResponseGenerator.toRuleRestResponse(new RuleInformation(dto, List.of()));
    assertThat(ruleRestResponse.cleanCodeAttribute()).isNull();
    assertThat(ruleRestResponse.cleanCodeAttributeCategory()).isNull();
    assertThat(ruleRestResponse.htmlNote()).isNull();
  }