Skip to content

Commit

Permalink
Fixed issue allow allowable values to be overriden
Browse files Browse the repository at this point in the history
fixes #3321
  • Loading branch information
dilipkrish committed Jun 25, 2020
1 parent 744162e commit 9b0e335
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 10 deletions.
8 changes: 4 additions & 4 deletions oas-contract-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ compileJava {

// tag::update-contract-tests[]
// NOTE: Uncomment to bulk update contracts
test {
systemProperty("contract.tests.root", "$projectDir/src/test/resources")
systemProperty("contract.tests.update", true)
}
//test {
// systemProperty("contract.tests.root", "$projectDir/src/test/resources")
// systemProperty("contract.tests.update", true)
//}
// end::update-contract-tests[]
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package springfox.test.contract.oas.bugs;

import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Set;
import java.util.UUID;

@RestController
Expand All @@ -20,4 +23,10 @@ public Object bug3338(@NotNull String username) {
public Object bug3329(@Size(max = 36, min = 36) UUID uuid) {
return null;
}

@GetMapping("/3321")
public void bug3321(
@ApiParam(allowableValues = "one, two, three")
@RequestParam(name = "expand", required = false) Set<NumberEnum> numbers) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package springfox.test.contract.oas.bugs;

public enum NumberEnum {
ONE,
TWO,
THREE
}
35 changes: 35 additions & 0 deletions oas-contract-tests/src/test/resources/contracts/bugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@
}
],
"paths": {
"/bugs/3321": {
"get": {
"tags": [
"bugs-controller"
],
"summary": "bug3321",
"operationId": "bug3321UsingGET",
"parameters": [
{
"name": "expand",
"in": "query",
"description": "expand",
"required": false,
"style": "pipeDelimited",
"schema": {
"uniqueItems": true,
"type": "array",
"items": {
"type": "string"
},
"enum": [
"one",
"three",
"two"
]
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/bugs/3329": {
"get": {
"tags": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import springfox.documentation.service.AllowableListValues;
import springfox.documentation.service.AllowableValues;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class EnumerationElementFacetBuilder implements ElementFacetBuilder {
Expand All @@ -20,7 +18,10 @@ public EnumerationElementFacetBuilder allowedValues(Collection<String> allowedVa
}

public EnumerationElementFacetBuilder allowedValues(AllowableValues allowedValues) {
this.allowedValues.addAll(from(allowedValues));
if (!from(allowedValues).isEmpty()) {
this.allowedValues.clear();
this.allowedValues.addAll(from(allowedValues));
}
return this;
}

Expand All @@ -41,10 +42,10 @@ public EnumerationElementFacetBuilder copyOf(ElementFacet facet) {
return this.allowedValues(other.getAllowedValues());
}

public static List<String> from(AllowableValues allowableValues) {
public static Set<String> from(AllowableValues allowableValues) {
if (allowableValues instanceof AllowableListValues) {
return ((AllowableListValues) allowableValues).getValues();
return new HashSet<>(((AllowableListValues) allowableValues).getValues());
}
return new ArrayList<>();
return new HashSet<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ public void bug2822(@ApiParam(example = "exampleMessage") @RequestBody String me
// Empty body is sufficient for testing
}

@GetMapping("/3321")
public void bug3321(
@ApiParam(allowableValues = "one, two, three")
@RequestParam(name = "expand", required = false) Set<NumberEnum> numbers) {
}

public enum NumberEnum {
ONE,
TWO,
THREE
}

@SuppressWarnings("VisibilityModifier")
public class Bug2423 {
public String from;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,43 @@
}
}
},
"/bugs/3321{?expand}": {
"get": {
"tags": [
"Bugs"
],
"summary": "bug3321",
"operationId": "bug3321UsingGET_1",
"parameters": [
{
"name": "expand",
"in": "query",
"description": "expand",
"required": false,
"type": "array",
"items": {
"type": "string",
"enum": [
"ONE",
"THREE",
"TWO"
]
},
"collectionFormat": "csv",
"enum": [
"one",
"three",
"two"
]
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/bugs/bug1827{?authorIds,authors[0].books[0].id,authors[0].books[0].name,authors[0].id,authors[0].name,id,name}": {
"get": {
"tags": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,43 @@
}
}
},
"/bugs/3321{?expand}": {
"get": {
"tags": [
"Bugs"
],
"summary": "bug3321",
"operationId": "bug3321UsingGET",
"parameters": [
{
"name": "expand",
"in": "query",
"description": "expand",
"required": false,
"type": "array",
"items": {
"type": "string",
"enum": [
"ONE",
"THREE",
"TWO"
]
},
"collectionFormat": "csv",
"enum": [
"one",
"three",
"two"
]
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/bugs/bug1827{?authorIds,authors[0].books[0].id,authors[0].books[0].name,authors[0].id,authors[0].name,id,name}": {
"get": {
"tags": [
Expand Down

0 comments on commit 9b0e335

Please sign in to comment.