Skip to content

Commit

Permalink
Add support for showCommonExtensions configuration options for swagge…
Browse files Browse the repository at this point in the history
…r-ui
  • Loading branch information
sakuna63 committed Sep 7, 2018
1 parent a04d57b commit 6b3e4d7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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 @@ -190,6 +191,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 @@ -222,6 +224,8 @@ public UiConfiguration(
* 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.
Expand All @@ -243,6 +247,7 @@ public UiConfiguration(
Integer maxDisplayedTags,
OperationsSorter operationsSorter,
Boolean showExtensions,
Boolean showCommonExtensions,
TagsSorter tagsSorter,
String validatorUrl) {
this(
Expand All @@ -257,6 +262,7 @@ public UiConfiguration(
maxDisplayedTags,
operationsSorter,
showExtensions,
showCommonExtensions,
tagsSorter,
Constants.DEFAULT_SUBMIT_METHODS,
validatorUrl);
Expand Down Expand Up @@ -291,6 +297,8 @@ public UiConfiguration(
* 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.
Expand All @@ -316,6 +324,7 @@ public UiConfiguration(
Integer maxDisplayedTags,
OperationsSorter operationsSorter,
Boolean showExtensions,
Boolean showCommonExtensions,
TagsSorter tagsSorter,
String[] supportedSubmitMethods,
String validatorUrl) {
Expand All @@ -331,6 +340,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 @@ -431,6 +441,11 @@ public Boolean getShowExtensions() {
return showExtensions;
}

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

@JsonProperty("tagsSorter")
public TagsSorter getTagsSorter() {
return tagsSorter;
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 @@ -181,6 +183,16 @@ public UiConfigurationBuilder showExtensions(Boolean 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
* function (see Array.prototype.sort() to learn how to write a sort function). Two tag name strings
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 @@ -40,6 +40,7 @@ class UiConfigurationBuilderSpec extends Specification {
" \"filter\": false,\n" +
" \"operationsSorter\": \"alpha\",\n" +
" \"showExtensions\": false,\n" +
" \"showCommonExtensions\": false,\n" +
" \"tagsSorter\": \"alpha\",\n" +
" \"supportedSubmitMethods\": [\"get\",\"put\",\"post\",\"delete\",\"options\",\"head\",\"patch\"," +
"\"trace\"],\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UiConfigurationSpec extends Specification {
" \"filter\": false,\n" +
" \"operationsSorter\": \"alpha\",\n" +
" \"showExtensions\": false,\n" +
" \"showCommonExtensions\": false,\n" +
" \"tagsSorter\": \"alpha\",\n" +
" \"validatorUrl\": \"validator:urn\"\n" +
"}"
Expand All @@ -59,6 +60,7 @@ class UiConfigurationSpec extends Specification {
" \"filter\": false,\n" +
" \"operationsSorter\": \"alpha\",\n" +
" \"showExtensions\": false,\n" +
" \"showCommonExtensions\": false,\n" +
" \"tagsSorter\": \"alpha\",\n" +
" \"validatorUrl\": \"\"\n" +
"}"
Expand Down

0 comments on commit 6b3e4d7

Please sign in to comment.