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
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ class SpringDocKotlinConfiguration() {
.addDeprecatedType(Deprecated::class.java)
}

@Bean
@Lazy(false)
fun kotlinRequiredPropertyCustomizer(objectMapperProvider: ObjectMapperProvider): KotlinRequiredPropertyCustomizer {
return KotlinRequiredPropertyCustomizer(objectMapperProvider)
}

@ConditionalOnClass(name = ["kotlin.reflect.full.KClasses"])
class KotlinReflectDependingConfiguration {

Expand All @@ -98,6 +92,12 @@ class SpringDocKotlinConfiguration() {
fun kotlinModelConverter(objectMapperProvider: ObjectMapperProvider): KotlinInlineClassUnwrappingConverter {
return KotlinInlineClassUnwrappingConverter(objectMapperProvider)
}
@Bean
@Lazy(false)
@ConditionalOnMissingBean
fun kotlinRequiredPropertyCustomizer(objectMapperProvider: ObjectMapperProvider): KotlinRequiredPropertyCustomizer {
return KotlinRequiredPropertyCustomizer(objectMapperProvider)
}

@Bean
@ConditionalOnProperty(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.springdoc.core.configuration;

import org.junit.jupiter.api.Test;
import org.springdoc.core.customizers.KotlinRequiredPropertyCustomizer;
import org.springdoc.core.properties.SpringDocConfigProperties;

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;

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

/**
* Regression test for GitHub issue #54.
*
* <p>The {@code kotlinRequiredPropertyCustomizer} bean must only be created when
* {@code kotlin-reflect} is on the classpath. Previously it was declared directly in
* {@link SpringDocKotlinConfiguration} (gated only by kotlin-stdlib presence), which forced a
* {@code NoClassDefFoundError: kotlin/reflect/full/KClasses} for pure-Java projects that have
* kotlin-stdlib but not kotlin-reflect on the classpath.</p>
*/
class SpringDocKotlinConfigurationTest {

private final WebApplicationContextRunner runner = new WebApplicationContextRunner()
.withPropertyValues("springdoc.api-docs.enabled=true")
.withConfiguration(AutoConfigurations.of(
WebMvcAutoConfiguration.class,
SpringDocConfiguration.class,
SpringDocConfigProperties.class,
SpringDocKotlinConfiguration.class));

@Test
void kotlinRequiredPropertyCustomizerRegisteredWhenKotlinReflectPresent() {
runner.run(context -> assertThat(context).hasBean("kotlinRequiredPropertyCustomizer"));
}

@Test
void kotlinRequiredPropertyCustomizerNotRegisteredWhenKotlinReflectAbsent() {
runner.withClassLoader(new FilteredClassLoader("kotlin.reflect.full.KClasses"))
.run(context -> assertThat(context).doesNotHaveBean(KotlinRequiredPropertyCustomizer.class));
}
}
Loading