Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3f6625

Browse files
committed
Merge branch 'feature/1523/timeout-configuration'
2 parents 1e2ad44 + 70d9f08 commit f3f6625

8 files changed

Lines changed: 95 additions & 15 deletions

File tree

docs/asciidoc/getting_started.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
:releaseVersion: {springfox-released-version}
44
:snapshotVersion: {springfox-current-version}
5+
:springfoxRfc6570Version: {springfox-swagger-ui-rfc6570-version}
56

67
=== Dependencies
78
The Springfox libraries are hosted on https://bintray.com/springfox/maven-repo/springfox/view[bintray] and jcenter.
@@ -304,14 +305,14 @@ api docs are served](http://springfox.github.io/springfox/docs/current/#customiz
304305
NOTE: _Keep in mind this is experimental_!
305306
In order to use this feature
306307
1. Add `springfox-swagger-ui-rfc6570` instead of `springfox-swagger-ui` as a dependency
307-
http://mvnrepository.com/artifact/io.springfox.ui/springfox-swagger-ui-rfc6570/0.9.8[experimental swagger-ui].
308+
http://mvnrepository.com/artifact/io.springfox.ui/springfox-swagger-ui-rfc6570/{springfoxRfc6570Version}[experimental swagger-ui].
308309

309310
For gradle:
310311
[source,groovy]
311312
[subs="verbatim,attributes"]
312313
----
313314
dependencies {
314-
compile 'io.springfox.ui:springfox-swagger-ui-rfc6570:0.9.8'
315+
compile 'io.springfox.ui:springfox-swagger-ui-rfc6570:{springfoxRfc6570Version}'
315316
}
316317
----
317318

@@ -322,7 +323,7 @@ For maven:
322323
<dependency>
323324
<groupId>io.springfox.ui</groupId>
324325
<artifactId>springfox-swagger-ui-rfc6570</artifactId>
325-
<version>0.9.8</version>
326+
<version>{springfoxRfc6570Version}</version>
326327
</dependency>
327328
----
328329
NOTE: The newer version has changed the group id from `_io.springfox_` to `_io.springfox.ui_`!

gradle/dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ext {
1818
springPluginVersion = "1.2.0.RELEASE"
1919
swagger2Core = "1.5.10"
2020
springBoot = "1.3.6.RELEASE"
21+
springfoxRfc6570Version = "1.0.0"
2122

2223
libs = [
2324

gradle/documentation.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ asciidoctor {
1111
attributes 'source-highlighter': 'coderay',
1212
'springfox-current-version': latestSnapshotVersion(project),
1313
'springfox-released-version': latestReleasedVersion(project),
14+
'springfox-swagger-ui-rfc6570-version': "${rootProject.ext.springfoxRfc6570Version}",
1415
toc: 'left',
1516
idprefix: '',
1617
idseparator: '-',
@@ -108,6 +109,7 @@ task allJavadoc(type: Javadoc) {
108109
task docs {
109110
dependsOn asciidoctor
110111
doLast {
112+
println asciidoctor.attributes
111113
println asciidoctor.properties
112114
Class.forName("java.awt.Desktop").newInstance().browse(file("${asciidoctor.outputDir}/index.html").toURI())
113115
}

springfox-spring-config/src/main/java/springfox/springconfig/Swagger2SpringBoot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ UiConfiguration uiConfig() {
149149
"schema", // defaultModelRendering => schema
150150
UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS,
151151
false, // enableJsonEditor => true | false
152-
true); // showRequestHeaders => true | false
152+
true, // showRequestHeaders => true | false
153+
60000L); // requestTimeout => in milliseconds, defaults to null (uses jquery xh timeout)
153154
}
154155
}

springfox-swagger-common/src/main/java/springfox/documentation/swagger/web/UiConfiguration.java

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,46 @@ public class UiConfiguration {
2626
private final String docExpansion;
2727
private final String apisSorter;
2828
private final String defaultModelRendering;
29+
private final Long requestTimeout;
2930

3031
private final String[] supportedSubmitMethods;
3132

3233
private final boolean jsonEditor;
3334
private final boolean showRequestHeaders;
3435

3536
public UiConfiguration(String validatorUrl) {
36-
this(validatorUrl, "none", "alpha", "schema", Constants.DEFAULT_SUBMIT_METHODS, false, true);
37+
this(validatorUrl, "none", "alpha", "schema", Constants.DEFAULT_SUBMIT_METHODS, false, true, null);
3738
}
3839

3940
public UiConfiguration(String validatorUrl, String[] supportedSubmitMethods) {
40-
this(validatorUrl, "none", "alpha", "schema", supportedSubmitMethods, false, true);
41+
this(validatorUrl, "none", "alpha", "schema", supportedSubmitMethods, false, true, null);
4142
}
4243

44+
/**
45+
* Use the default constructor instead (with requestTimeout)
46+
* {@link UiConfiguration#UiConfiguration(String, String, String, String, String[], boolean, boolean, Long)} )}
47+
*
48+
* @deprecated @since 2.6.1
49+
* @param validatorUrl - By default, Swagger-UI attempts to validate specs against swagger.io's online validator.
50+
* You can use this parameter to set a different validator URL, for example for locally
51+
* deployed validators (Validator Badge). Setting it to null will disable validation. This
52+
* parameter is relevant for Swagger 2.0 specs only.
53+
* @param docExpansion - Controls how the API listing is displayed. It can be set to 'none' (default), 'list'
54+
* (shows operations for each resource), or 'full' (fully expanded: shows operations and their
55+
* details).
56+
* @param apisSorter Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see Array
57+
* .prototype.sort() to know how sort function works). Default is the order returned by the
58+
* server unchanged.
59+
* @param defaultModelRendering - Controls how models are shown when the API is first rendered. (The user can
60+
* always switch the rendering for a given model by clicking the 'Model' and 'Model
61+
* Schema' links.) It can be set to 'model' or 'schema', and the default is 'schema'.
62+
* @param supportedSubmitMethods - An array of of the HTTP operations that will have the 'Try it out!' option. An
63+
* empty array disables all operations. This does not filter the operations from the display.
64+
* @param jsonEditor - Enables a graphical view for editing complex bodies. Defaults to false.
65+
* @param showRequestHeaders - Whether or not to show the headers that were sent when making a request via the 'Try
66+
* it out!' option. Defaults to false.
67+
*/
68+
@Deprecated
4369
public UiConfiguration(
4470
String validatorUrl,
4571
String docExpansion,
@@ -48,10 +74,53 @@ public UiConfiguration(
4874
String[] supportedSubmitMethods,
4975
boolean jsonEditor,
5076
boolean showRequestHeaders) {
77+
this(
78+
validatorUrl,
79+
docExpansion,
80+
apisSorter,
81+
defaultModelRendering,
82+
supportedSubmitMethods,
83+
jsonEditor,
84+
showRequestHeaders,
85+
null);
86+
}
87+
88+
/**
89+
* Default constructor
90+
* @param validatorUrl - By default, Swagger-UI attempts to validate specs against swagger.io's online validator.
91+
* You can use this parameter to set a different validator URL, for example for locally
92+
* deployed validators (Validator Badge). Setting it to null will disable validation. This
93+
* parameter is relevant for Swagger 2.0 specs only.
94+
* @param docExpansion - Controls how the API listing is displayed. It can be set to 'none' (default), 'list'
95+
* (shows operations for each resource), or 'full' (fully expanded: shows operations and their
96+
* details).
97+
* @param apisSorter Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see Array
98+
* .prototype.sort() to know how sort function works). Default is the order returned by the
99+
* server unchanged.
100+
* @param defaultModelRendering - Controls how models are shown when the API is first rendered. (The user can
101+
* always switch the rendering for a given model by clicking the 'Model' and 'Model
102+
* Schema' links.) It can be set to 'model' or 'schema', and the default is 'schema'.
103+
* @param supportedSubmitMethods - An array of of the HTTP operations that will have the 'Try it out!' option. An
104+
* empty array disables all operations. This does not filter the operations from the display.
105+
* @param jsonEditor - Enables a graphical view for editing complex bodies. Defaults to false.
106+
* @param showRequestHeaders - Whether or not to show the headers that were sent when making a request via the 'Try
107+
* it out!' option. Defaults to false.
108+
* @param requestTimeout - XHR timeout
109+
*/
110+
public UiConfiguration(
111+
String validatorUrl,
112+
String docExpansion,
113+
String apisSorter,
114+
String defaultModelRendering,
115+
String[] supportedSubmitMethods,
116+
boolean jsonEditor,
117+
boolean showRequestHeaders,
118+
Long requestTimeout) {
51119
this.validatorUrl = validatorUrl;
52120
this.docExpansion = docExpansion;
53121
this.apisSorter = apisSorter;
54122
this.defaultModelRendering = defaultModelRendering;
123+
this.requestTimeout = requestTimeout;
55124
this.jsonEditor = jsonEditor;
56125
this.showRequestHeaders = showRequestHeaders;
57126
this.supportedSubmitMethods = supportedSubmitMethods;
@@ -92,6 +161,11 @@ public boolean isShowRequestHeaders() {
92161
return showRequestHeaders;
93162
}
94163

164+
@JsonProperty("requestTimeout")
165+
public Long getRequestTimeout() {
166+
return requestTimeout;
167+
}
168+
95169
public static class Constants {
96170
public static final String[] DEFAULT_SUBMIT_METHODS = new String[] { "get", "post", "put", "delete", "patch" };
97171
public static final String[] NO_SUBMIT_METHODS = new String[] {};

springfox-swagger-common/src/test/groovy/springfox/documentation/swagger/web/ApiResourceControllerSpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ApiResourceControllerSpec extends Specification {
7070
expect:
7171
mockMvc.perform(get("/swagger-resources/configuration/ui")
7272
.accept(MediaType.APPLICATION_JSON))
73-
.andExpect(content().string("{\"validatorUrl\":\"/validate\",\"docExpansion\":\"none\",\"apisSorter\":\"alpha\",\"defaultModelRendering\":\"schema\",\"supportedSubmitMethods\":[\"get\",\"post\",\"put\",\"delete\",\"patch\"],\"jsonEditor\":false,\"showRequestHeaders\":true}"))
73+
.andExpect(content().string("{\"validatorUrl\":\"/validate\",\"docExpansion\":\"none\",\"apisSorter\":\"alpha\",\"defaultModelRendering\":\"schema\",\"requestTimeout\":null,\"supportedSubmitMethods\":[\"get\",\"post\",\"put\",\"delete\",\"patch\"],\"jsonEditor\":false,\"showRequestHeaders\":true}"))
7474
}
7575

7676
def "Cache is available" (){
@@ -95,11 +95,11 @@ class ApiResourceControllerSpec extends Specification {
9595
given:
9696
ObjectMapper mapper = new ObjectMapper()
9797
when:
98-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
98+
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
9999
then:
100100
mapper.writer().writeValueAsString(sut.securityConfiguration) == "{\"clientId\":\"client\"," +
101101
"\"clientSecret\":\"client-secret\",\"realm\":\"real\",\"appName\":\"test\",\"apiKey\":\"key\",\"apiKeyVehicle\":\"header\",\"scopeSeparator\":\",\",\"apiKeyName\":\"api_key\"}"
102-
mapper.writer().writeValueAsString(sut.uiConfiguration) == "{\"validatorUrl\":\"/validate\",\"docExpansion\":\"none\",\"apisSorter\":\"alpha\",\"defaultModelRendering\":\"schema\",\"supportedSubmitMethods\":[\"get\",\"post\",\"put\",\"delete\",\"patch\"],\"jsonEditor\":false,\"showRequestHeaders\":true}"
102+
mapper.writer().writeValueAsString(sut.uiConfiguration) == "{\"validatorUrl\":\"/validate\",\"docExpansion\":\"none\",\"apisSorter\":\"alpha\",\"defaultModelRendering\":\"schema\",\"requestTimeout\":null,\"supportedSubmitMethods\":[\"get\",\"post\",\"put\",\"delete\",\"patch\"],\"jsonEditor\":false,\"showRequestHeaders\":true}"
103103
mapper.writer().writeValueAsString(sut.swaggerResources().body) == "[{\"name\":\"test\"," +
104104
"\"location\":\"/v1?group=test\",\"swaggerVersion\":\"1.2\"},{\"name\":\"test\",\"location\":\"/v2?group=test\",\"swaggerVersion\":\"2.0\"}]"
105105
}

springfox-swagger-ui/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ plugins {
2626
}
2727

2828
ext {
29-
swaggerUiVersion = '2.2.5'
29+
swaggerUiVersion = '2.2.6'
3030
swaggerUiDist = "build/libs/swagger-ui-dist.zip"
3131
swaggerUiExplodedDir = "swagger-ui-${swaggerUiVersion}/dist/"
3232
downloadUrl = "https://github.com/swagger-api/swagger-ui/archive/v${swaggerUiVersion}.zip"

springfox-swagger-ui/src/web/js/springfox.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ $(function() {
2323
dom_id: "swagger-ui-container",
2424
validatorUrl: data.validatorUrl,
2525
supportedSubmitMethods: data.supportedSubmitMethods || ['get', 'post', 'put', 'delete', 'patch'],
26+
docExpansion: data.docExpansion || 'none',
27+
jsonEditor: JSON.parse(data.jsonEditor) || false,
28+
apisSorter: data.apisSorter || 'alpha',
29+
defaultModelRendering: data.defaultModelRendering || 'schema',
30+
showRequestHeaders: data.showRequestHeaders || true,
31+
timeout: data.requestTimeout,
2632
onComplete: function(swaggerApi, swaggerUi) {
2733

2834
initializeSpringfox();
@@ -39,11 +45,6 @@ $(function() {
3945
onFailure: function(data) {
4046
log("Unable to Load SwaggerUI");
4147
},
42-
docExpansion: data.docExpansion || 'none',
43-
jsonEditor: JSON.parse(data.jsonEditor) || false,
44-
apisSorter: data.apisSorter || 'alpha',
45-
defaultModelRendering: data.defaultModelRendering || 'schema',
46-
showRequestHeaders: data.showRequestHeaders || true
4748
});
4849

4950
initializeBaseUrl();

0 commit comments

Comments
 (0)