Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the 'showCommonExtensions' configuration available in swagger-ui #2973

Merged
merged 1 commit into from
Aug 3, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ UiConfiguration uiConfig() {
.maxDisplayedTags(null)
.operationsSorter(OperationsSorter.ALPHA)
.showExtensions(false)
.showCommonExtensions(false)
.tagsSorter(TagsSorter.ALPHA)
.supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
.validatorUrl(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class UiConfiguration {
private final Integer maxDisplayedTags;
private final OperationsSorter operationsSorter;
private final Boolean showExtensions;
private final Boolean showCommonExtensions;
private final TagsSorter tagsSorter;
private final String validatorUrl;
/**
Expand Down Expand Up @@ -192,6 +193,7 @@ public UiConfiguration(
this.maxDisplayedTags = null;
this.operationsSorter = OperationsSorter.of(apisSorter);
this.showExtensions = false;
this.showCommonExtensions = false;
this.tagsSorter = TagsSorter.of(apisSorter);
}

Expand Down Expand Up @@ -260,6 +262,7 @@ public UiConfiguration(
maxDisplayedTags,
operationsSorter,
showExtensions,
false,
tagsSorter,
Constants.DEFAULT_SUBMIT_METHODS,
validatorUrl);
Expand Down Expand Up @@ -322,6 +325,86 @@ public UiConfiguration(
Boolean showExtensions,
TagsSorter tagsSorter,
String[] supportedSubmitMethods,
String validatorUrl) {
this(
deepLinking,
displayOperationId,
defaultModelsExpandDepth,
defaultModelExpandDepth,
defaultModelRendering,
displayRequestDuration,
docExpansion,
filter,
maxDisplayedTags,
operationsSorter,
showExtensions,
false,
tagsSorter,
supportedSubmitMethods,
validatorUrl);
this.apisSorter = "alpha";
}

/**
* Default constructor
*
* @param deepLinking If set to true, enables deep linking for tags and operations. See the Deep Linking
* documentation for more information.
* @param displayOperationId Controls the display of operationId in operations list. The default is false.
* @param defaultModelsExpandDepth The default expansion depth for models (set to -1 completely hide the models).
* @param defaultModelExpandDepth The default expansion depth for the model on the model-example section.
* @param defaultModelRendering Controls how the model is shown when the API is first rendered. (The user can
* always switch the rendering for a given model by clicking the 'Model' and 'Example
* Value' links.)
* @param displayRequestDuration Controls the display of the request duration (in milliseconds) for Try-It-Out
* requests.
* @param docExpansion Controls the default expansion setting for the operations and tags. It can be
* 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none'
* (expands nothing).
* @param filter If set, enables filtering. The top bar will show an edit box that you can use to
* filter the tagged operations that are shown. Can be Boolean to enable or disable,
* or a string, in which case filtering will be enabled using that string as the
* filter expression. Filtering is case sensitive matching the filter expression
* anywhere inside the tag.
* @param maxDisplayedTags If set, limits the number of tagged operations displayed to at most this many. The
* default is to show all operations.
* @param operationsSorter Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths
* alphanumerically), 'method' (sort by HTTP method) or a function (see
* Array.prototype.sort() to know how sort function works). Default is the order
* returned by the server unchanged.
* @param showExtensions Controls the display of vendor extension (x-) fields and values for Operations,
* Parameters, and Schema.
* @param showCommonExtensions Controls the display of extensions (pattern, maxLength, minLength, maximum,
* minimum) fields and values for Parameters.
* @param tagsSorter Apply a sort to the tag list of each API. It can be 'alpha' (sort by paths
* alphanumerically) or a function (see Array.prototype.sort() to learn how to write a
* sort function). Two tag name strings are passed to the sorter for each pass.
* Default is the order determined by Swagger-UI.
* @param supportedSubmitMethods List of HTTP methods that have the Try it out feature enabled. An empty array
* disables Try it out for all operations. This does not filter the operations from
* the
* display.
* @param validatorUrl By default, Swagger-UI attempts to validate specs against swagger.io's online
* validator. You can use this parameter to set a different validator URL, for example
* for locally deployed validators (Validator Badge). Setting it to null will disable
* validation. This parameter is relevant for Swagger 2.0 specs only.
*/
@SuppressWarnings("ParameterNumber")
public UiConfiguration(
Boolean deepLinking,
Boolean displayOperationId,
Integer defaultModelsExpandDepth,
Integer defaultModelExpandDepth,
ModelRendering defaultModelRendering,
Boolean displayRequestDuration,
DocExpansion docExpansion,
Object filter,
Integer maxDisplayedTags,
OperationsSorter operationsSorter,
Boolean showExtensions,
Boolean showCommonExtensions,
TagsSorter tagsSorter,
String[] supportedSubmitMethods,
String validatorUrl) {
this.apisSorter = "alpha";
this.deepLinking = deepLinking;
Expand All @@ -335,6 +418,7 @@ public UiConfiguration(
this.maxDisplayedTags = maxDisplayedTags;
this.operationsSorter = operationsSorter;
this.showExtensions = showExtensions;
this.showCommonExtensions = showCommonExtensions;
this.tagsSorter = tagsSorter;
this.supportedSubmitMethods = supportedSubmitMethods;
this.validatorUrl = validatorUrl;
Expand Down Expand Up @@ -434,6 +518,11 @@ public OperationsSorter getOperationsSorter() {
public Boolean getShowExtensions() {
return showExtensions;
}

@JsonProperty("showCommonExtensions")
public Boolean getShowCommonExtensions() {
return showCommonExtensions;
}

@JsonProperty("tagsSorter")
public TagsSorter getTagsSorter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class UiConfigurationBuilder {
private Integer maxDisplayedTags;
private OperationsSorter operationsSorter;
private Boolean showExtensions;
private Boolean showCommonExtensions;
private TagsSorter tagsSorter;

/*--------------------------------------------*\
Expand Down Expand Up @@ -64,6 +65,7 @@ public UiConfiguration build() {
defaultIfAbsent(maxDisplayedTags, null),
defaultIfAbsent(operationsSorter, OperationsSorter.ALPHA),
defaultIfAbsent(showExtensions, false),
defaultIfAbsent(showCommonExtensions, false),
defaultIfAbsent(tagsSorter, TagsSorter.ALPHA),
defaultIfAbsent(supportedSubmitMethods, UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS),
defaultIfAbsent(validatorUrl, null)
Expand Down Expand Up @@ -180,6 +182,16 @@ public UiConfigurationBuilder showExtensions(Boolean showExtensions) {
this.showExtensions = showExtensions;
return this;
}

/**
* @param showCommonExtensions Controls the display of extensions (pattern, maxLength, minLength, maximum,
* minimum) fields and values for Parameters.
* @return this
*/
public UiConfigurationBuilder showCommonExtensions(Boolean showCommonExtensions) {
this.showCommonExtensions = showCommonExtensions;
return this;
}

/**
* @param tagsSorter Apply a sort to the tag list of each API. It can be 'alpha' (sort by paths alphanumerically) or a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ApiResourceControllerSpec extends Specification {
"maxDisplayedTags": 1000,
"operationsSorter": "alpha",
"showExtensions": false,
"showCommonExtensions": false,
"tagsSorter": "alpha",
"supportedSubmitMethods":["get","put","post","delete","options","head","patch","trace"],
"validatorUrl": "/validate"
Expand Down Expand Up @@ -105,6 +106,7 @@ class ApiResourceControllerSpec extends Specification {
.maxDisplayedTags(1000)
.operationsSorter(OperationsSorter.ALPHA)
.showExtensions(false)
.showCommonExtensions(false)
.tagsSorter(TagsSorter.ALPHA)
.supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
.validatorUrl("/validate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class UiConfigurationBuilderSpec extends Specification {
" \"docExpansion\": \"none\",\n" +
" \"filter\": false,\n" +
" \"operationsSorter\": \"alpha\",\n" +
" \"showCommonExtensions\": false,\n" +
" \"showExtensions\": false,\n" +
" \"tagsSorter\": \"alpha\",\n" +
" \"supportedSubmitMethods\": [\"get\",\"put\",\"post\",\"delete\",\"options\",\"head\",\"patch\"," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class UiConfigurationSpec extends Specification {
" \"docExpansion\": \"none\",\n" +
" \"filter\": false,\n" +
" \"operationsSorter\": \"alpha\",\n" +
" \"showCommonExtensions\": false,\n" +
" \"showExtensions\": false,\n" +
" \"tagsSorter\": \"alpha\",\n" +
" \"validatorUrl\": \"validator:urn\"\n" +
Expand All @@ -58,6 +59,7 @@ class UiConfigurationSpec extends Specification {
" \"docExpansion\": \"none\",\n" +
" \"filter\": false,\n" +
" \"operationsSorter\": \"alpha\",\n" +
" \"showCommonExtensions\": false,\n" +
" \"showExtensions\": false,\n" +
" \"tagsSorter\": \"alpha\",\n" +
" \"validatorUrl\": \"\"\n" +
Expand Down
1 change: 1 addition & 0 deletions springfox-swagger-ui/src/web/js/springfox.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ window.onload = () => {
maxDisplayedTags: configUI.maxDisplayedTags,
operationsSorter: configUI.operationsSorter,
showExtensions: configUI.showExtensions,
showCommonExtensions: configUI.showCommonExtensions,
tagSorter: configUI.tagSorter,
/*--------------------------------------------*\
* Network
Expand Down