Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.4.1-beta-2] - 2026-05-28

### Added

- Add OpenAPI language support without YAML and JSON conflicts.

## [1.4.1-beta-1] - 2026-05-26

### Changed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>sonaropenapi-rules-community</artifactId>
<version>1.4.1-beta-1</version>
<version>1.4.1-beta-2</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube OpenAPI Community Rules</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package apiaddicts.sonar.openapi;

import org.sonar.api.ExtensionPoint;
import org.sonar.api.scanner.ScannerSide;
import org.apiaddicts.apitools.dosonarapi.api.OpenApiCustomRuleRepository;
import apiaddicts.sonar.openapi.checks.RulesLists;
import org.sonarsource.api.sonarlint.SonarLintSide;

import java.util.List;

import static apiaddicts.sonar.openapi.OpenAPICustomRulesDefinition.OPENAPI_REPOSITORY_KEY;

@SonarLintSide
@ScannerSide
@ExtensionPoint
public class OpenAPICustomOpenApiRuleRepository implements OpenApiCustomRuleRepository {
@Override
public String repositoryKey() {
return OPENAPI_REPOSITORY_KEY;
}

@Override
public List<Class<?>> checkClasses() {
return RulesLists.getAllChecks();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public void define(Context context) {
OpenAPICustomRulesDefinition.class,
// batch extensions -> objects are instantiated during code analysis
OpenAPICustomRuleRepository.class,
OpenAPICustomJsonRuleRepository.class
OpenAPICustomJsonRuleRepository.class,
OpenAPICustomOpenApiRuleRepository.class
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public void define(Context context) {
addBaseRules(jsonProfile, CheckList.JSON_REPOSITORY_KEY);
addRepositoryRules(jsonProfile, OpenAPICustomRulesDefinition.JSON_REPOSITORY_KEY, RulesLists.getAllChecks());
jsonProfile.done();

NewBuiltInQualityProfile openapiProfile = context.createBuiltInQualityProfile(OPENAPI_WAY, CheckList.OPENAPI_LANGUAGE);
addBaseRules(openapiProfile, CheckList.OPENAPI_REPOSITORY_KEY);
addRepositoryRules(openapiProfile, OpenAPICustomRulesDefinition.OPENAPI_REPOSITORY_KEY, RulesLists.getAllChecks());
openapiProfile.done();
}

private void addBaseRules(NewBuiltInQualityProfile profile, String repositoryKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class OpenAPICustomRulesDefinition implements RulesDefinition {
public static final String YAML_REPOSITORY_KEY = "openapi-custom-yaml";
public static final String JSON_REPOSITORY_KEY = "openapi-custom-json";
public static final String OPENAPI_REPOSITORY_KEY = "openapi-custom";
private static final String REPOSITORY_NAME = "OpenAPI Custom";
private static final String ROOT_RESOURCE_FOLDER = "org/sonar/l10n/openapi/rules/openapi/";
private static final String SECURITY_GROUP = "security";
Expand All @@ -34,6 +35,7 @@ public void define(Context context) {
I18nContext.initializeFromUserLanguage();
populateRepository(context, YAML_REPOSITORY_KEY, "yaml");
populateRepository(context, JSON_REPOSITORY_KEY, "json");
populateRepository(context, OPENAPI_REPOSITORY_KEY, "openapi");
}

private void populateRepository(Context context, String key, String language) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package apiaddicts.sonar.openapi;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;

public class OpenAPICustomOpenApiRuleRepositoryTest {

@Test
public void testRepositoryKey() {
OpenAPICustomOpenApiRuleRepository repository = new OpenAPICustomOpenApiRuleRepository();
assertThat(repository.repositoryKey()).isEqualTo("openapi-custom");
}

@Test
public void testCheckClassesNotEmpty() {
OpenAPICustomOpenApiRuleRepository repository = new OpenAPICustomOpenApiRuleRepository();
assertThat(repository.checkClasses()).isNotEmpty();
}

@Test
public void testCheckClassesSameAsAllChecks() {
OpenAPICustomOpenApiRuleRepository repository = new OpenAPICustomOpenApiRuleRepository();
OpenAPICustomRuleRepository yamlRepo = new OpenAPICustomRuleRepository();
assertThat(repository.checkClasses()).isEqualTo(yamlRepo.checkClasses());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public void testDefine() {
};
Plugin.Context context = new Plugin.Context(runtime);
plugin.define(context);
assertThat(context.getExtensions()).hasSize(4);
assertThat(context.getExtensions()).hasSize(5);
assertThat(context.getExtensions()).contains(
OpenAPICustomProfileDefinition.class,
OpenAPICustomRulesDefinition.class,
OpenAPICustomRuleRepository.class,
OpenAPICustomJsonRuleRepository.class);
OpenAPICustomJsonRuleRepository.class,
OpenAPICustomOpenApiRuleRepository.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ public void testDefine() {
assertThat(jsonProfile.name()).isEqualTo(OpenAPICustomProfileDefinition.OPENAPI_WAY);
assertThat(jsonProfile.rules()).hasSize(expectedSize);
assertThat(jsonProfile.rules().stream().noneMatch(r -> r.ruleKey().equals("OAR112"))).isTrue();

BuiltInQualityProfile openapiProfile = context.profile("openapi", OpenAPICustomProfileDefinition.OPENAPI_WAY);
assertThat(openapiProfile).isNotNull();
assertThat(openapiProfile.language()).isEqualTo("openapi");
assertThat(openapiProfile.name()).isEqualTo(OpenAPICustomProfileDefinition.OPENAPI_WAY);
assertThat(openapiProfile.rules()).hasSize(expectedSize);
assertThat(openapiProfile.rules().stream().noneMatch(r -> r.ruleKey().equals("OAR112"))).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public void testRepository() {
assertThat(jsonRepository.name()).isEqualTo("OpenAPI Custom");
assertThat(jsonRepository.language()).isEqualTo("json");
assertThat(jsonRepository.rules()).hasSize(RulesLists.getAllChecks().size());

Repository openapiRepository = context.repository(OpenAPICustomRulesDefinition.OPENAPI_REPOSITORY_KEY);
assertThat(openapiRepository.name()).isEqualTo("OpenAPI Custom");
assertThat(openapiRepository.language()).isEqualTo("openapi");
assertThat(openapiRepository.rules()).hasSize(RulesLists.getAllChecks().size());
}

@Test
Expand Down