
org.apiaddicts.apitools.dosonarapi.checks.DescriptionDiffersSummaryCheck Maven / Gradle / Ivy
/*
* doSonarAPI: SonarQube OpenAPI Plugin
* Copyright (C) 2021-2022 Apiaddicts
* contacta AT apiaddicts DOT org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.apiaddicts.apitools.dosonarapi.checks;
import com.google.common.collect.Sets;
import com.sonar.sslr.api.AstNodeType;
import java.util.Set;
import org.sonar.check.Rule;
import org.apiaddicts.apitools.dosonarapi.api.OpenApiCheck;
import org.apiaddicts.apitools.dosonarapi.api.v2.OpenApi2Grammar;
import org.apiaddicts.apitools.dosonarapi.api.v3.OpenApi3Grammar;
import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode;
@Rule(key = DescriptionDiffersSummaryCheck.CHECK_KEY)
public class DescriptionDiffersSummaryCheck extends OpenApiCheck {
public static final String CHECK_KEY = "DescriptionDiffersSummary";
@Override
public Set subscribedKinds() {
return Sets.newHashSet(OpenApi2Grammar.OPERATION, OpenApi3Grammar.OPERATION);
}
@Override
protected void visitNode(JsonNode node) {
JsonNode summary = node.get("summary");
JsonNode description = node.get("description");
if (summary.isMissing() || description.isMissing()) {
return;
}
String summaryText = summary.stringValue().toLowerCase().trim();
String descriptionText = description.stringValue().toLowerCase().trim();
if (summaryText.equals(descriptionText)) {
addIssue("Description must differ from summary.", description.key());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy