Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(openapi): new module for checking backwards incompatible changes to OpenAPI contracts #10812

Merged
merged 1 commit into from
Sep 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public OpenApiContractApplicationService() {
public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
}

public JHipsterModule buildBackwardsCompatibilityCheckModule(JHipsterModuleProperties properties) {
return factory.buildBackwardsCompatibilityCheckModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,29 @@ private MavenPlugin openApiPluginManagement(JHipsterModuleProperties properties)
)
.build();
}

public JHipsterModule buildBackwardsCompatibilityCheckModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return moduleBuilder(properties)
.mavenPlugins()
.pluginManagement(openApiBackwardsCompatPluginManagement())
.plugin(openApiBackwardsCompatPlugin().build())
.and()
.build();
//@formatter:on
}

private MavenPlugin openApiBackwardsCompatPluginManagement() {
return openApiBackwardsCompatPlugin()
.versionSlug("openapi-backwards-compat-maven-plugin")
.configuration("<openApiSourceDir>${project.build.directory}</openApiSourceDir>")
.addExecution(pluginExecution().goals("backwards-compatibility-check"))
.build();
}

private MavenPluginOptionalBuilder openApiBackwardsCompatPlugin() {
return mavenPlugin().groupId("io.kemtoa.openapi").artifactId("openapi-backwards-compat-maven-plugin");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ JHipsterModuleResource openApiContractModule(OpenApiContractApplicationService o
.tags("server", "spring", "spring-boot", "documentation", "swagger", "openapi")
.factory(openApiContract::buildModule);
}

@Bean
JHipsterModuleResource openApiBackwardsCompatibilityCheckModule(OpenApiContractApplicationService openApiContract) {
return JHipsterModuleResource.builder()
.slug(OPENAPI_BACKWARDS_COMPATIBILITY_CHECK)
.propertiesDefinition(JHipsterModulePropertiesDefinition.EMPTY)
.apiDoc("Spring Boot - OpenAPI", "Check backwards incompatible changes to OpenAPI contract during build")
.organization(JHipsterModuleOrganization.builder().addDependency(OPENAPI_CONTRACT).build())
.tags("server", "spring", "spring-boot", "documentation", "swagger", "openapi")
.factory(openApiContract::buildBackwardsCompatibilityCheckModule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
NEO4J("neo4j"),
NEO4J_MIGRATIONS("neo4j-migrations"),
OPENAPI_CONTRACT("openapi-contract"),
OPENAPI_BACKWARDS_COMPATIBILITY_CHECK("openapi-backwards-compatibility-check"),
OPTIONAL_TYPESCRIPT("optional-typescript"),
PAGINATION_DOMAIN("pagination-domain"),
PLAYWRIGHT_COMPONENT_TESTS("playwright-component-tests"),
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<failsafe-plugin.version>3.5.0</failsafe-plugin.version>
<asciidoctor-maven-plugin.version>3.0.0</asciidoctor-maven-plugin.version>
<openapi-maven-plugin.version>0.0.20</openapi-maven-plugin.version>
<openapi-backwards-compat-maven-plugin.version>1.0.1</openapi-backwards-compat-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -400,6 +401,11 @@
<artifactId>openapi-maven-plugin</artifactId>
<version>${openapi-maven-plugin.version}</version>
</dependency>
<dependency>
<groupId>io.kemtoa.openapi</groupId>
<artifactId>openapi-backwards-compat-maven-plugin</artifactId>
<version>${openapi-backwards-compat-maven-plugin.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
5 changes: 5 additions & 0 deletions src/test/features/server/springboot/openapi-contract.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ Feature: OpenAPI contract generation
When I apply "openapi-contract" module to default project with maven file
| packageName | tech.jhipster.chips |
Then I should have "openapi-maven-plugin" in "pom.xml"

Scenario: Should apply OpenAPI backwards compatibility check module
When I apply "openapi-backwards-compatibility-check" module to default project with maven file
| packageName | tech.jhipster.chips |
Then I should have "openapi-backwards-compat-maven-plugin" in "pom.xml"
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OpenApiContractModuleFactoryTest {
private static final OpenApiContractModuleFactory factory = new OpenApiContractModuleFactory();

@Test
void shouldBuildModuleOnProjectWithoutDefaultGoal() {
void shouldBuildOpenApiContractModule() {
JHipsterModuleProperties properties = propertiesBuilder(tmpDirForTest()).basePackage("tech.jhipster.jhlitest").build();

JHipsterModule module = factory.buildModule(properties);
Expand Down Expand Up @@ -72,4 +72,43 @@ void shouldBuildModuleOnProjectWithoutDefaultGoal() {
"""
);
}

@Test
void shouldBuildOpenApiBackwardsCompatibilityCheckModule() {
JHipsterModuleProperties properties = propertiesBuilder(tmpDirForTest()).build();

JHipsterModule module = factory.buildBackwardsCompatibilityCheckModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
.containing(
// language=xml
"""
<plugin>
<groupId>io.kemtoa.openapi</groupId>
<artifactId>openapi-backwards-compat-maven-plugin</artifactId>
</plugin>\
"""
)
.containing(
// language=xml
"""
<plugin>
<groupId>io.kemtoa.openapi</groupId>
<artifactId>openapi-backwards-compat-maven-plugin</artifactId>
<version>${openapi-backwards-compat-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>backwards-compatibility-check</goal>
</goals>
</execution>
</executions>
<configuration>
<openApiSourceDir>${project.build.directory}</openApiSourceDir>
</configuration>
</plugin>\
"""
);
}
}
1 change: 1 addition & 0 deletions tests-ci/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ elif [[ $application == 'fullapp' ]]; then
"spring-boot-async" \
"spring-boot-devtools" \
"openapi-contract" \
"openapi-backwards-compatibility-check" \
"logstash" \
"jib" \
"dockerfile-${java_build_tool}" \
Expand Down