Skip to content

Commit 65ace1a

Browse files
committed
Merge branch 'main' of https://github.com/viktor-berglund-mw/springdoc-openapi into viktor-berglund-mw-main
2 parents a714f41 + 813d196 commit 65ace1a

35 files changed

+1723
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package org.springdoc.core.configuration;
22

33
import com.fasterxml.jackson.module.kotlin.KotlinModule;
4-
import com.fasterxml.jackson.module.kotlin.KotlinModule.Builder;
4+
import org.springdoc.core.properties.SpringDocConfigProperties;
55
import org.springdoc.core.providers.ObjectMapperProvider;
66

7-
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
87
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
98
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
109
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
10+
import org.springframework.context.annotation.Bean;
1111
import org.springframework.context.annotation.Configuration;
1212
import org.springframework.context.annotation.Lazy;
13+
import org.springframework.context.annotation.Primary;
1314

1415
/**
1516
* The type Spring doc kotlin module configuration.
@@ -21,16 +22,19 @@
2122
@ConditionalOnClass(KotlinModule.class)
2223
@ConditionalOnExpression("${springdoc.api-docs.enabled:true} and ${springdoc.enable-kotlin:true}")
2324
@ConditionalOnWebApplication
24-
@ConditionalOnBean(SpringDocConfiguration.class)
2525
class SpringDocJacksonKotlinModuleConfiguration {
2626

2727
/**
28-
* Instantiates a new Spring doc kotlin module configuration.
28+
* Instantiates a new objectMapperProvider with a kotlin module.
2929
*
30-
* @param objectMapperProvider the object mapper provider
30+
* @param springDocConfigProperties the spring doc config properties
3131
*/
32-
public SpringDocJacksonKotlinModuleConfiguration(ObjectMapperProvider objectMapperProvider) {
33-
objectMapperProvider.jsonMapper()
34-
.registerModule(new Builder().build());
32+
33+
@Bean
34+
@Primary
35+
ObjectMapperProvider objectMapperProvider(SpringDocConfigProperties springDocConfigProperties) {
36+
ObjectMapperProvider mapperProvider = new ObjectMapperProvider(springDocConfigProperties);
37+
mapperProvider.jsonMapper().registerModule(new KotlinModule.Builder().build());
38+
return mapperProvider;
3539
}
3640
}

springdoc-openapi-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<module>springdoc-openapi-actuator-webflux-tests</module>
1919
<module>springdoc-openapi-actuator-webmvc-tests</module>
2020
<module>springdoc-openapi-kotlin-tests</module>
21+
<module>springdoc-openapi-kotlin-mvc-tests</module>
2122
<module>springdoc-openapi-hateoas-tests</module>
2223
<module>springdoc-openapi-data-rest-tests</module>
2324
</modules>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
######################
2+
# Project Specific
3+
######################
4+
/target/www/**
5+
/src/test/javascript/coverage/
6+
7+
######################
8+
# Node
9+
######################
10+
/node/
11+
node_tmp/
12+
node_modules/
13+
npm-debug.log.*
14+
/.awcache/*
15+
/.cache-loader/*
16+
17+
######################
18+
# SASS
19+
######################
20+
.sass-cache/
21+
22+
######################
23+
# Eclipse
24+
######################
25+
*.pydevproject
26+
.project
27+
.metadata
28+
tmp/
29+
tmp/**/*
30+
*.tmp
31+
*.bak
32+
*.swp
33+
*~.nib
34+
local.properties
35+
.classpath
36+
.settings/
37+
.loadpath
38+
.factorypath
39+
/src/main/resources/rebel.xml
40+
41+
# External tool builders
42+
.externalToolBuilders/**
43+
44+
# Locally stored "Eclipse launch configurations"
45+
*.launch
46+
47+
# CDT-specific
48+
.cproject
49+
50+
# PDT-specific
51+
.buildpath
52+
53+
######################
54+
# Intellij
55+
######################
56+
.idea/
57+
*.iml
58+
*.iws
59+
*.ipr
60+
*.ids
61+
*.orig
62+
classes/
63+
out/
64+
65+
######################
66+
# Visual Studio Code
67+
######################
68+
.vscode/
69+
70+
######################
71+
# Maven
72+
######################
73+
/log/
74+
/target/
75+
76+
######################
77+
# Gradle
78+
######################
79+
.gradle/
80+
/build/
81+
82+
######################
83+
# Package Files
84+
######################
85+
*.jar
86+
*.war
87+
*.ear
88+
*.db
89+
90+
######################
91+
# Windows
92+
######################
93+
# Windows image file caches
94+
Thumbs.db
95+
96+
# Folder config file
97+
Desktop.ini
98+
99+
######################
100+
# Mac OSX
101+
######################
102+
.DS_Store
103+
.svn
104+
105+
# Thumbnails
106+
._*
107+
108+
# Files that might appear on external disk
109+
.Spotlight-V100
110+
.Trashes
111+
112+
######################
113+
# Directories
114+
######################
115+
/bin/
116+
/deploy/
117+
118+
######################
119+
# Logs
120+
######################
121+
*.log*
122+
123+
######################
124+
# Others
125+
######################
126+
*.class
127+
*.*~
128+
*~
129+
.merge_file*
130+
131+
######################
132+
# Gradle Wrapper
133+
######################
134+
!gradle/wrapper/gradle-wrapper.jar
135+
136+
######################
137+
# Maven Wrapper
138+
######################
139+
!.mvn/wrapper/maven-wrapper.jar
140+
141+
######################
142+
# ESLint
143+
######################
144+
.eslintcache
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<parent>
3+
<artifactId>springdoc-openapi-tests</artifactId>
4+
<groupId>org.springdoc</groupId>
5+
<version>2.2.1-SNAPSHOT</version>
6+
</parent>
7+
<modelVersion>4.0.0</modelVersion>
8+
<artifactId>springdoc-openapi-kotlin-mvc-tests</artifactId>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.fasterxml.jackson.module</groupId>
13+
<artifactId>jackson-module-kotlin</artifactId>
14+
<scope>test</scope>
15+
</dependency>
16+
<dependency>
17+
<groupId>org.springdoc</groupId>
18+
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
19+
<scope>test</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.jetbrains.kotlin</groupId>
23+
<artifactId>kotlin-stdlib-jdk8</artifactId>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<artifactId>kotlin-maven-plugin</artifactId>
42+
<groupId>org.jetbrains.kotlin</groupId>
43+
<executions>
44+
<execution>
45+
<id>compile</id>
46+
<phase>process-sources</phase>
47+
<goals>
48+
<goal>compile</goal>
49+
</goals>
50+
<configuration>
51+
<sourceDirs>
52+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
53+
</sourceDirs>
54+
</configuration>
55+
</execution>
56+
<execution>
57+
<id>test-compile</id>
58+
<goals>
59+
<goal>test-compile</goal>
60+
</goals>
61+
<configuration>
62+
<sourceDirs>
63+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
64+
</sourceDirs>
65+
</configuration>
66+
</execution>
67+
</executions>
68+
<configuration>
69+
<compilerPlugins>
70+
<plugin>spring</plugin>
71+
</compilerPlugins>
72+
</configuration>
73+
<dependencies>
74+
<dependency>
75+
<groupId>org.jetbrains.kotlin</groupId>
76+
<artifactId>kotlin-maven-allopen</artifactId>
77+
<version>${kotlin.version}</version>
78+
</dependency>
79+
</dependencies>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api
20+
21+
import org.junit.jupiter.api.Test
22+
import org.skyscreamer.jsonassert.JSONAssert
23+
import org.slf4j.LoggerFactory
24+
import org.springframework.beans.factory.annotation.Autowired
25+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
26+
import org.springframework.boot.test.context.SpringBootTest
27+
import org.springframework.test.context.ActiveProfiles
28+
import org.springframework.test.web.servlet.MockMvc
29+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
30+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
31+
import java.nio.charset.StandardCharsets
32+
import java.nio.file.Files
33+
import java.nio.file.Paths
34+
35+
@SpringBootTest
36+
@AutoConfigureMockMvc
37+
@ActiveProfiles("test")
38+
abstract class AbstractKotlinSpringDocMVCTest {
39+
40+
@Autowired
41+
val mockMvc: MockMvc? = null
42+
43+
private val logger = LoggerFactory.getLogger(AbstractKotlinSpringDocMVCTest::class.java)
44+
45+
@Test
46+
fun testApp() {
47+
var result: String? = null
48+
try {
49+
val response = mockMvc!!.perform(MockMvcRequestBuilders.get("/v3/api-docs"))
50+
.andExpect(MockMvcResultMatchers.status().isOk).andReturn()
51+
52+
result = response.response.contentAsString
53+
val className = javaClass.simpleName
54+
val testNumber = className.replace("[^0-9]".toRegex(), "")
55+
56+
val expected = getContent("results/app$testNumber.json")
57+
JSONAssert.assertEquals(expected, result, true)
58+
} catch (e: AssertionError) {
59+
logger.error(result)
60+
throw e
61+
}
62+
}
63+
64+
companion object {
65+
@Throws(Exception::class)
66+
fun getContent(fileName: String): String {
67+
try {
68+
val path = Paths.get(
69+
AbstractKotlinSpringDocMVCTest::class.java.classLoader.getResource(
70+
fileName
71+
)!!.toURI()
72+
)
73+
val fileBytes = Files.readAllBytes(path)
74+
return String(fileBytes, StandardCharsets.UTF_8)
75+
} catch (e: Exception) {
76+
throw RuntimeException("Failed to read file: $fileName", e)
77+
}
78+
79+
}
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test.org.springdoc.api.app10
2+
3+
import org.springframework.web.bind.annotation.GetMapping
4+
import org.springframework.web.bind.annotation.RequestParam
5+
import org.springframework.web.bind.annotation.RestController
6+
import test.org.springdoc.api.app8.Greeting
7+
8+
data class Greeting(val greeting: String)
9+
10+
@RestController
11+
class ExampleController {
12+
@GetMapping("/")
13+
fun greet(@RequestParam name: String?) = Greeting("Hello ${name ?: "world"}")
14+
15+
@GetMapping("/test")
16+
fun test(@RequestParam name: String) = Greeting("Hello $name")
17+
18+
@GetMapping("/test-with-default")
19+
fun testWithDefault(@RequestParam(defaultValue = "world") name: String) = Greeting("Hello $name")
20+
}

0 commit comments

Comments
 (0)