Skip to content

Commit bc9d0ca

Browse files
committed
Updated the documentation
Polished the javadocs for the configuration properties fixes #3378
1 parent d92928f commit bc9d0ca

File tree

5 files changed

+85
-39
lines changed

5 files changed

+85
-39
lines changed

docs/asciidoc/getting_started.adoc

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,43 @@ dependencies {
115115

116116
==== Migrating from existing 2.x version
117117
===== Spring Boot Applications
118-
1. Remove library inclusions of earlier
118+
1. Remove library inclusions of earlier releases. Specifically remove `springfox-swagger2` and `springfox-swagger-ui` inclusions.
119119
2. Remove the `@EnableSwagger2` annotations
120-
3. Added the `springfox-boot-starter`
120+
3. Add the `springfox-boot-starter`
121121
4. Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin
122122
and open api libraries for annotations and models) so if you used guava predicates/functions those will need to
123123
transition to java 8 function interfaces
124124

125125
===== Regular spring mvc
126-
1. Remove library inclusions of earlier
127-
2. Add `EnableOpenApi` for open API (and `@EnableSwagger2` for swagger 2.0)
128-
3. Added the `springfox-oas` library
126+
1. Remove library inclusions of earlier releases. Specifically remove `springfox-swagger2` and `springfox-swagger-ui` inclusions.
127+
2. For OpenAPI add the `@EnableOpenApi` annotation (and `@EnableSwagger2` for swagger 2.0)
128+
3. For OpenAPI add the `springfox-oas` library dependency (for swagger 2.0 use `springfox-swagger2`)
129129
4. Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin
130130
and open api libraries for annotations and models) so if you used guava predicates/functions those will need to
131131
transition to java 8 function interfaces
132132

133-
NOTE: Would love feedback to make this experience better
133+
===== Changes in swagger-ui
134+
NOTE: For non-boot applications `springfox-swagger-ui` is no longer automatically enabled by adding the dependency. It needs to be explicitly register
135+
using a resource handler configurer (`WebFluxConfigurer` or `WebMvcConfigurer`). Here is how it is configured in
136+
`springfox-boot-starter`
137+
138+
NOTE: swagger-ui location has moved from `http://host/context-path/swagger-ui.html` to `http://host/context-path/swagger-ui/index.html`
139+
OR `http://host/context-path/swagger-ui/` for short. This makes it work much better with pulling it as a web jar and turning it off
140+
using configuration properties if not needed.
141+
142+
For WebMvc https://github.com/springfox/springfox/blob/master/springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SwaggerUiWebMvcConfigurer.java[SwagggerUIWebMvcConfigurer.java]
143+
[[jackson-convention-example-1]]
144+
[source,java,linenums]
145+
----
146+
include::../../springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SwaggerUiWebMvcConfigurer.java[tags=swagger-ui-configurer,indent=0]
147+
----
148+
149+
For WebFlux https://github.com/springfox/springfox/blob/master/springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SwaggerUiWebFluxConfigurer.java[SwagggerUIWebMvcConfigurer.java]
150+
[[jackson-convention-example-1]]
151+
[source,java,linenums]
152+
----
153+
include::../../springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SwaggerUiWebFluxConfigurer.java[tags=swagger-ui-configurer,indent=0]
154+
----
134155

135156
== Quick start guides
136157
=== Springfox Spring MVC and Spring Boot
@@ -211,7 +232,7 @@ In version greater than 2.6.0, support for spring data rest was added.
211232

212233
NOTE: This is still in ***incubation***.
213234

214-
In order to use it
235+
In order to use it (non-spring-boot)
215236

216237
1. add the `springfox-data-rest` dependency (via Gradle or Maven).
217238
2. Import the configuration from the `springfox-data-rest` module (via Java or xml config) as shown below
@@ -236,8 +257,6 @@ dependencies {
236257
</dependency>
237258
----
238259

239-
240-
241260
==== java config
242261
[source,java]
243262
[subs="verbatim,attributes"]
@@ -255,6 +274,9 @@ Import the bean in your xml configuration by defining a bean of the following ty
255274
<bean class="springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration.class" />
256275
----
257276

277+
NOTE: for spring boot, this section is not needed. Springfox will autoconfigure itself based on the detection of spring
278+
data rest components.
279+
258280
=== Springfox Support for JSR-303
259281
In version greater than 2.3.2, support for bean validation annotations was added, specifically for @NotNull, @Min,
260282
@Max, and @Size.
@@ -347,35 +369,10 @@ Regarding http://springfox.github.io/springfox/docs/current/#q13[where swagger-u
347369
and http://springfox.github.io/springfox/docs/current/#customizing-the-swagger-endpoints[where the api docs are served]
348370
those are totally configurable.
349371

350-
=== Springfox RFC6570 support *incubating*
351-
NOTE: _Keep in mind this is experimental_!
352-
In order to use this feature
353-
354-
1. Add `springfox-swagger-ui-rfc6570` instead of `springfox-swagger-ui` as a dependency
355-
http://mvnrepository.com/artifact/io.springfox.ui/springfox-swagger-ui-rfc6570/{springfoxRfc6570Version}[experimental swagger-ui].
372+
=== Springfox RFC6570 support
373+
NOTE: Support has been dropped experimental feature as swagger-ui and the spec itself has better support for this.
356374

357-
For gradle:
358-
[source,groovy]
359-
[subs="verbatim,attributes"]
360-
----
361-
dependencies {
362-
compile 'io.springfox.ui:springfox-swagger-ui-rfc6570:{springfoxRfc6570Version}'
363-
}
364-
----
365-
366-
For maven:
367-
[source,xml]
368-
[subs="verbatim,attributes"]
369-
----
370-
<dependency>
371-
<groupId>io.springfox.ui</groupId>
372-
<artifactId>springfox-swagger-ui-rfc6570</artifactId>
373-
<version>{springfoxRfc6570Version}</version>
374-
</dependency>
375-
----
376-
NOTE: The newer version has changed the group id from `_io.springfox_` to `_io.springfox.ui_`!
377-
378-
- Enable url templating; (http://springfox.github.io/springfox/docs/current/#springfox-swagger2-with-spring-mvc-and-spring-boot[see #21])
375+
- Turn enableUrlTemplating `OFF`; (http://springfox.github.io/springfox/docs/current/#springfox-swagger2-with-spring-mvc-and-spring-boot[see #21])
379376

380377
=== Springfox Spring-Integration Support *incubating*
381378
NOTE: _Keep in mind this is experimental_!
@@ -459,7 +456,6 @@ cookies-based auth in the browser. (Credit: https://github.com/evser[@evser])
459456
}
460457
----
461458

462-
463459
And configure the Docket to be secured via the `AUTHORIZATION` header:
464460
[source,java]
465461
[subs="verbatim,attributes"]

springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SpringfoxConfigurationProperties.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
@ConfigurationProperties("springfox.documentation")
77
public class SpringfoxConfigurationProperties {
8+
/**
9+
* Flag that indicates if springfox should auto start scanning services
10+
*/
811
private boolean autoStartup = true;
12+
/**
13+
* Flag that indicates if springfox should scan services to produce specifications.
14+
*/
915
private boolean enabled = true;
1016
@NestedConfigurationProperty
1117
private SwaggerConfigurationProperties swagger;
@@ -54,6 +60,11 @@ public void setSwaggerUi(SwaggerUiConfigurationProperties swaggerUi) {
5460
this.swaggerUi = swaggerUi;
5561
}
5662

63+
/**
64+
* Configuration properties related to swagger specification.
65+
*
66+
* @since 3.0.0
67+
*/
5768
public static class SwaggerConfigurationProperties {
5869
@NestedConfigurationProperty
5970
private Swagger2Configuration v2;
@@ -68,9 +79,24 @@ public void setV2(Swagger2Configuration v2) {
6879

6980
}
7081

82+
/**
83+
* Configuration properties related to swagger 2.0 specification.
84+
*
85+
* @since 3.0.0
86+
*/
7187
public static class Swagger2Configuration {
88+
/**
89+
* Flag that disables swagger 2 related beans
90+
*/
7291
private boolean enabled = false;
92+
/**
93+
* Flag that toggles between generating models using v3.0.0 of the library or the 2.9.x version of the library.
94+
* This flag can be changed to false, if v3.0.0 is not working as expected.
95+
*/
7396
private boolean useModelV3 = true;
97+
/**
98+
* Host name to use for swagger 2 specification
99+
*/
74100
private String host;
75101

76102
public String getHost() {
@@ -97,8 +123,15 @@ public void setUseModelV3(boolean useModelV3) {
97123
this.useModelV3 = useModelV3;
98124
}
99125
}
100-
126+
/**
127+
* Configuration properties related to OpenApi 3.0 specification.
128+
*
129+
* @since 3.0.0
130+
*/
101131
public static class OpenApiConfigurationProperties {
132+
/**
133+
* Flag that disables openApi related beans
134+
*/
102135
private boolean enabled = true;
103136

104137
public boolean isEnabled() {
@@ -110,8 +143,20 @@ public void setEnabled(boolean enabled) {
110143
}
111144
}
112145

146+
/**
147+
* Configuration properties related to swagger-ui specification.
148+
*
149+
* @since 3.0.0
150+
*/
113151
public static class SwaggerUiConfigurationProperties {
152+
/**
153+
* Flag that disables swagger-ui from being resource-handled. No swagger-ui when this is false.
154+
*/
114155
private boolean enabled = true;
156+
/**
157+
* Base url for swagger-ui. For e.g. setting it to /documentation will put swagger-ui
158+
* at /documentation/swagger-ui/index.html
159+
*/
115160
private String baseUrl = "";
116161

117162
public boolean isEnabled() {

springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SwaggerUiWebFluxConfigurer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
55
import org.springframework.web.reactive.config.WebFluxConfigurer;
66

7+
// tag::swagger-ui-configurer[]
78
public class SwaggerUiWebFluxConfigurer implements WebFluxConfigurer {
89
private final String baseUrl;
910

@@ -20,3 +21,4 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
2021
.resourceChain(false);
2122
}
2223
}
24+
// end::swagger-ui-configurer[]

springfox-boot-starter/src/main/java/springfox/boot/starter/autoconfigure/SwaggerUiWebMvcConfigurer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
66
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
77

8+
// tag::swagger-ui-configurer[]
89
public class SwaggerUiWebMvcConfigurer implements WebMvcConfigurer {
910
private final String baseUrl;
1011

@@ -27,3 +28,4 @@ public void addViewControllers(ViewControllerRegistry registry) {
2728
.setViewName("forward:" + baseUrl + "/swagger-ui/index.html");
2829
}
2930
}
31+
// end::swagger-ui-configurer[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
spring.jpa.hibernate.ddl-auto=none
22
logging.level.springfox.documentation=DEBUG
33
#server.servlet.context-path=/context
4+
spring.activemq.broker-url=

0 commit comments

Comments
 (0)