diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDoc.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDoc.java
index dea3ff5ba8f..e18fb08f02a 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDoc.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDoc.java
@@ -4,8 +4,6 @@
public class SpringDoc {
- private static final String SPRING_DOC_VERSION = "1.6.4";
-
private SpringDoc() {}
public static Dependency springDocDependency() {
@@ -16,8 +14,4 @@ public static Dependency springDocDependency() {
.version("\\${springdoc-openapi-ui.version}")
.build();
}
-
- public static String springDocVersion() {
- return SPRING_DOC_VERSION;
- }
}
diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainService.java
index d8456eb0384..ab94fdec490 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainService.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainService.java
@@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
+import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.domain.ProjectRepository;
@@ -49,8 +50,16 @@ public void initWithSecurityJWT(Project project) {
@Override
public void addSpringDocDependency(Project project) {
- buildToolService.addProperty(project, "springdoc-openapi-ui.version", SpringDoc.springDocVersion());
- buildToolService.addDependency(project, SpringDoc.springDocDependency());
+ this.buildToolService.getVersion(project, "springdoc-openapi")
+ .ifPresentOrElse(
+ version -> {
+ buildToolService.addProperty(project, "springdoc-openapi-ui.version", version);
+ buildToolService.addDependency(project, SpringDoc.springDocDependency());
+ },
+ () -> {
+ throw new GeneratorException("Springdoc Openapi version not found");
+ }
+ );
}
@Override
diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml
index 740b5662a19..1d65b5c3695 100644
--- a/src/main/resources/generator/dependencies/pom.xml
+++ b/src/main/resources/generator/dependencies/pom.xml
@@ -18,7 +18,7 @@
0.27.0
2.6.3
2021.0.0
- 1.6.4
+ 1.6.5
1.16.2
diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/application/SpringDocAssert.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/application/SpringDocAssert.java
index 2b493ef5c7a..f018a6689cf 100644
--- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/application/SpringDocAssert.java
+++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/application/SpringDocAssert.java
@@ -8,18 +8,13 @@
import tech.jhipster.lite.TestUtils;
import tech.jhipster.lite.generator.project.domain.DefaultConfig;
import tech.jhipster.lite.generator.project.domain.Project;
-import tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringDoc;
public class SpringDocAssert {
public static final String SPRING_DOC_CONFIG_JAVA_FILE_NAME = "SpringDocConfiguration.java";
public static void assertDependencies(Project project) {
- TestUtils.assertFileContent(
- project,
- POM_XML,
- List.of("" + SpringDoc.springDocVersion() + "")
- );
+ TestUtils.assertFileContent(project, POM_XML, List.of(""));
TestUtils.assertFileContent(
project,
POM_XML,
diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainServiceTest.java
index d8a3301a37e..5d58d08f3c5 100644
--- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainServiceTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringDocDomainServiceTest.java
@@ -1,14 +1,15 @@
package tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
import static tech.jhipster.lite.TestUtils.tmpProject;
import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringDocConstants.*;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
@@ -16,6 +17,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import tech.jhipster.lite.UnitTest;
+import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService;
import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency;
import tech.jhipster.lite.generator.project.domain.Project;
@@ -44,10 +46,11 @@ void shouldInitWithDefaultValues() {
Project project = tmpProject();
// When
+ when(buildToolService.getVersion(project, "springdoc-openapi")).thenReturn(Optional.of("0.0.0"));
springDocDomainService.init(project);
// Then
- verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "1.6.4");
+ verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "0.0.0");
ArgumentCaptor dependencyArgCaptor = ArgumentCaptor.forClass(Dependency.class);
verify(buildToolService).addDependency(eq(project), dependencyArgCaptor.capture());
assertThat(dependencyArgCaptor.getValue()).usingRecursiveComparison().isEqualTo(getExpectedDependency());
@@ -89,10 +92,11 @@ void shouldInitWithAdditionalConfigFromProject() {
project.getConfig().putAll(projectConfig);
// When
+ when(buildToolService.getVersion(project, "springdoc-openapi")).thenReturn(Optional.of("0.0.0"));
springDocDomainService.init(project);
// Then
- verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "1.6.4");
+ verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "0.0.0");
ArgumentCaptor dependencyArgCaptor = ArgumentCaptor.forClass(Dependency.class);
verify(buildToolService).addDependency(eq(project), dependencyArgCaptor.capture());
assertThat(dependencyArgCaptor.getValue()).usingRecursiveComparison().isEqualTo(getExpectedDependency());
@@ -113,6 +117,13 @@ void shouldInitWithAdditionalConfigFromProject() {
assertThat(project.getConfig()).containsAllEntriesOf(projectConfig);
}
+ @Test
+ void shouldNotAddSpringDocDependency() {
+ Project project = tmpProject();
+
+ assertThatThrownBy(() -> springDocDomainService.addSpringDocDependency(project)).isExactlyInstanceOf(GeneratorException.class);
+ }
+
private static Dependency getExpectedDependency() {
return Dependency
.builder()