Skip to content

Commit 3824e66

Browse files
committed
fix(kotlin-spring): declare springdoc version property regardless of useSwaggerUI
The springdoc-openapi.version Maven property was only declared when useSwaggerUI=true, but the springdoc core dependency (used when useSwaggerUI=false) also references it, causing an undefined property.
1 parent 319c257 commit 3824e66

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom-sb4.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<name>{{artifactId}}</name>
77
<version>{{artifactVersion}}</version>
88
<properties>{{#reactive}}
9-
<kotlinx-coroutines.version>1.10.1</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
10-
<springdoc-openapi.version>2.8.6</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
9+
<kotlinx-coroutines.version>1.10.1</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}
10+
<springdoc-openapi.version>2.8.6</springdoc-openapi.version>{{/springDocDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
1111
<swagger-ui.version>5.17.14</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
1212
<swagger-annotations.version>1.6.6</swagger-annotations.version>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
1313
<swagger-annotations.version>2.2.28</swagger-annotations.version>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}

modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/pom-sb4.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<version>{{artifactVersion}}</version>
99
<properties>{{#reactive}}
1010
<kotlinx-coroutines.version>1.10.1
11-
</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
11+
</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}
1212
<springdoc-openapi.version>2.8.6
13-
</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
13+
</springdoc-openapi.version>{{/springDocDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
1414
<swagger-ui.version>5.17.14
1515
</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
1616
<swagger-annotations.version>1.6.6

modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/pom-sb4.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<version>{{artifactVersion}}</version>
99
<properties>{{#reactive}}
1010
<kotlinx-coroutines.version>1.10.1
11-
</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
11+
</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}
1212
<springdoc-openapi.version>2.8.6
13-
</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
13+
</springdoc-openapi.version>{{/springDocDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
1414
<swagger-ui.version>5.17.14
1515
</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
1616
<swagger-annotations.version>1.6.6

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures;
2323
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.AnnotationLibrary;
2424
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DocumentationProvider;
25+
import org.openapitools.codegen.languages.features.SwaggerUIFeatures;
2526
import org.testng.Assert;
2627
import org.testng.annotations.DataProvider;
2728
import org.testng.annotations.Test;
@@ -4935,6 +4936,37 @@ public void shouldDefaultToJackson3WhenSpringBoot4Enabled() throws IOException {
49354936
assertFileNotContains(pomPath, "com.fasterxml.jackson.module");
49364937
assertFileNotContains(pomPath, "jackson-datatype-jsr310");
49374938
}
4939+
4940+
@Test
4941+
public void shouldDeclareSpringdocVersionWhenSwaggerUIDisabled() throws IOException {
4942+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
4943+
output.deleteOnExit();
4944+
String outputPath = output.getAbsolutePath().replace('\\', '/');
4945+
4946+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml");
4947+
final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
4948+
codegen.setOpenAPI(openAPI);
4949+
codegen.setOutputDir(output.getAbsolutePath());
4950+
4951+
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true");
4952+
codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.SPRINGDOC.toCliOptValue());
4953+
codegen.additionalProperties().put(SwaggerUIFeatures.USE_SWAGGER_UI, false);
4954+
4955+
ClientOptInput input = new ClientOptInput();
4956+
input.openAPI(openAPI);
4957+
input.config(codegen);
4958+
4959+
DefaultGenerator generator = new DefaultGenerator();
4960+
generator.setGenerateMetadata(false);
4961+
generator.opts(input).generate();
4962+
4963+
Path pomPath = Paths.get(outputPath + "/pom.xml");
4964+
String pomContent = new String(Files.readAllBytes(pomPath), StandardCharsets.UTF_8);
4965+
String propertiesBlock = pomContent.substring(
4966+
pomContent.indexOf("<properties>"),
4967+
pomContent.indexOf("</properties>"));
4968+
assertThat(propertiesBlock).contains("<springdoc-openapi.version>");
4969+
}
49384970
}
49394971

49404972

0 commit comments

Comments
 (0)