Skip to content

Commit d48d49f

Browse files
committed
added test for vendor extension
1 parent 0cdb143 commit d48d49f

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ __Full example__
9191
description = "",
9292
termsOfService = "",
9393
contact = @Contact(name = "", url = "", email = ""),
94-
license = @License(name = "", url = ""))
95-
)
94+
license = @License(name = "", url = ""),
95+
extensions = @Extension(name = "x-test",
96+
properties = @ExtensionProperty(name = "test-key", value = "test-value")
97+
))
98+
)
9699
```
97100

98101
* Use __conventionMode__ to print better names on the swagger-ui page. It will alter the tags (the name of the groups).

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<jackson.version>2.8.8</jackson.version>
1717
<lombok.version>1.16.16</lombok.version>
1818
<guava.version>22.0</guava.version>
19+
<jsonpath.version>2.2.0</jsonpath.version>
1920

2021
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2122
<java.version>1.8</java.version>
@@ -73,6 +74,12 @@
7374
<scope>provided</scope>
7475
</dependency>
7576

77+
<dependency>
78+
<groupId>com.jayway.jsonpath</groupId>
79+
<artifactId>json-path</artifactId>
80+
<version>${jsonpath.version}</version>
81+
<scope>test</scope>
82+
</dependency>
7683
<dependency>
7784
<groupId>cglib</groupId>
7885
<artifactId>cglib-nodep</artifactId>

src/test/groovy/com/github/springfox/loader/SpringfoxLoaderConfigSpec.groovy

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.springfox.loader
22

33
import com.github.springfox.loader.testutils.TestApplication
4+
import com.jayway.jsonpath.JsonPath
45
import org.springframework.beans.factory.annotation.Autowired
56
import org.springframework.boot.test.context.SpringBootTest
67
import org.springframework.boot.test.web.client.TestRestTemplate
@@ -35,8 +36,8 @@ class SpringfoxLoaderConfigSpec extends Specification {
3536
def version = loaderProps.getVersion()
3637

3738
then:
38-
title == "test"
39-
version == "1.0.0"
39+
title == 'test'
40+
version == '1.0.0'
4041
}
4142

4243
def "Initialize with test profile"() {
@@ -47,9 +48,19 @@ class SpringfoxLoaderConfigSpec extends Specification {
4748
enabled
4849
}
4950

51+
def "GET api-docs with vendor extension"() {
52+
when:
53+
def response = restTemplate.getForEntity('/v2/api-docs', String)
54+
def json = response.getBody()
55+
56+
then:
57+
response.statusCode == HttpStatus.OK
58+
JsonPath.read(json, '$.info.x-test.test-key') == 'test-value'
59+
}
60+
5061
def "Custom base path for swagger-ui"() {
5162
when:
52-
def response = restTemplate.getForEntity("/docs/swagger-ui.html", String)
63+
def response = restTemplate.getForEntity('/docs/swagger-ui.html', String)
5364

5465
then:
5566
response.statusCode == HttpStatus.OK
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package com.github.springfox.loader.testutils;
22

33
import com.github.springfox.loader.EnableSpringfox;
4+
import io.swagger.annotations.Extension;
5+
import io.swagger.annotations.ExtensionProperty;
6+
import io.swagger.annotations.Info;
47
import org.springframework.boot.autoconfigure.SpringBootApplication;
58

6-
@EnableSpringfox(swaggerUiBasePath = "/docs", includeControllers = TestController.class)
9+
@EnableSpringfox(
10+
value = @Info(title = "test", version = "1.0.0",
11+
extensions = @Extension(name = "x-test",
12+
properties = @ExtensionProperty(name = "test-key", value = "test-value")
13+
)
14+
),
15+
swaggerUiBasePath = "/docs", includeControllers = TestController.class)
716
@SpringBootApplication
817
public class TestApplication {
918
}

0 commit comments

Comments
 (0)