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

Skip to content

Commit 45ff577

Browse files
committed
Added breaking test to demonstrate nullable expandable parameters
Fixed the contracts accordingly (1864)
1 parent a6a046a commit 45ff577

6 files changed

Lines changed: 115 additions & 27 deletions

File tree

springfox-spring-web/src/test/java/springfox/documentation/spring/web/dummy/controllers/BugsController.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.swagger.annotations.ApiResponses;
3030
import org.springframework.hateoas.Resource;
3131
import org.springframework.http.ResponseEntity;
32+
import org.springframework.web.bind.annotation.GetMapping;
3233
import org.springframework.web.bind.annotation.ModelAttribute;
3334
import org.springframework.web.bind.annotation.RequestBody;
3435
import org.springframework.web.bind.annotation.RequestMapping;
@@ -41,6 +42,7 @@
4142

4243
import javax.servlet.http.HttpServletResponse;
4344
import javax.validation.Valid;
45+
import javax.validation.constraints.NotNull;
4446
import java.net.MalformedURLException;
4547
import java.net.URL;
4648
import java.nio.ByteBuffer;
@@ -218,6 +220,24 @@ public void modelWithListOfEnumsAsJson(@RequestBody Model1819 model) {
218220
public void modelWithListOfEnumsAsModelAttribute(@ModelAttribute Model1819 model) {
219221
}
220222

223+
@GetMapping("/1864")
224+
public void test(@Valid Model1864 req) {
225+
226+
}
227+
228+
public class Model1864 {
229+
@NotNull
230+
private String somename;
231+
232+
public String getSomename() {
233+
return somename;
234+
}
235+
236+
public void setSomename(String somename) {
237+
this.somename = somename;
238+
}
239+
}
240+
221241
public class Model1819 {
222242

223243
private List<EnumType> enumTypes;

swagger-contract-tests/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ dependencies {
4040
compile project(':springfox-swagger1')
4141
compile project(':springfox-swagger2')
4242
compile project(':springfox-data-rest')
43+
compile project(':springfox-petstore')
44+
compile project(':springfox-bean-validators')
4345
compile project(':springfox-spring-web').sourceSets.test.output
44-
compile project(path: ':springfox-petstore')
4546

4647

4748
compile(project(path: ':springfox-swagger-ui')) {

swagger-contract-tests/src/test/groovy/springfox/test/contract/swaggertests/FunctionContractSpec.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.springframework.test.context.ContextConfiguration
3636
import spock.lang.Shared
3737
import spock.lang.Specification
3838
import spock.lang.Unroll
39+
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration
3940
import springfox.documentation.schema.AlternateTypeRuleConvention
4041
import springfox.documentation.spring.web.plugins.JacksonSerializerConvention
4142

@@ -190,7 +191,11 @@ class FunctionContractSpec extends Specification implements FileAccess {
190191
"springfox.test.contract.swagger",
191192
"springfox.petstore.controller"
192193
])
193-
@Import([SecuritySupport, Swagger12TestConfig, Swagger2TestConfig])
194+
@Import([
195+
SecuritySupport,
196+
Swagger12TestConfig,
197+
Swagger2TestConfig,
198+
BeanValidatorPluginsConfiguration])
194199
static class Config {
195200

196201
@Bean

swagger-contract-tests/src/test/resources/contract/swagger2/declaration-bugs-different-service.json

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"host": "localhost:__PORT__",
1515
"basePath": "/",
1616
"tags": [
17-
{
18-
"name": "foo",
19-
"description": "Foo Description"
20-
},
2117
{
2218
"name": "bugs-controller",
2319
"description": "Bugs Controller"
20+
},
21+
{
22+
"name": "foo",
23+
"description": "Foo Description"
2424
}
2525
],
2626
"produces": [
@@ -530,8 +530,8 @@
530530
"description": "Remove an apple from a user. You must specify the user name and the apple name.",
531531
"operationId": "bug1722UsingPOST_2",
532532
"consumes": [
533-
"application/xml",
534-
"application/json"
533+
"application/json",
534+
"application/xml"
535535
],
536536
"produces": [
537537
"application/xml",
@@ -629,15 +629,17 @@
629629
{
630630
"name": "pageNumber",
631631
"in": "query",
632-
"required": false,
632+
"required": true,
633633
"type": "integer",
634+
"minimum": 1.0,
634635
"format": "int32"
635636
},
636637
{
637638
"name": "pageSize",
638639
"in": "query",
639-
"required": false,
640+
"required": true,
640641
"type": "integer",
642+
"maximum": 50.0,
641643
"format": "int32"
642644
},
643645
{
@@ -894,6 +896,35 @@
894896
}
895897
}
896898
}
899+
},
900+
"/bugs/1864{?somename}": {
901+
"get": {
902+
"tags": [
903+
"bugs-controller"
904+
],
905+
"summary": "test",
906+
"operationId": "testUsingGET_2",
907+
"consumes": [
908+
"application/json"
909+
],
910+
"produces": [
911+
"application/xml",
912+
"application/json"
913+
],
914+
"parameters": [
915+
{
916+
"name": "somename",
917+
"in": "query",
918+
"required": true,
919+
"type": "string"
920+
}
921+
],
922+
"responses": {
923+
"200": {
924+
"description": "OK"
925+
}
926+
}
927+
}
897928
}
898929
},
899930
"securityDefinitions": {
@@ -1076,4 +1107,4 @@
10761107
}
10771108
}
10781109
}
1079-
}
1110+
}

swagger-contract-tests/src/test/resources/contract/swagger2/declaration-bugs-service.json

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"host": "localhost:__PORT__",
1515
"basePath": "/",
1616
"tags": [
17-
{
18-
"name": "foo",
19-
"description": "Foo Description"
20-
},
2117
{
2218
"name": "bugs-controller",
2319
"description": "Bugs Controller"
20+
},
21+
{
22+
"name": "foo",
23+
"description": "Foo Description"
2424
}
2525
],
2626
"produces": [
@@ -541,8 +541,8 @@
541541
"description": "Remove an apple from a user. You must specify the user name and the apple name.",
542542
"operationId": "bug1722UsingPOST_1",
543543
"consumes": [
544-
"application/xml",
545-
"application/json"
544+
"application/json",
545+
"application/xml"
546546
],
547547
"produces": [
548548
"application/xml",
@@ -640,15 +640,17 @@
640640
{
641641
"name": "pageNumber",
642642
"in": "query",
643-
"required": false,
643+
"required": true,
644644
"type": "integer",
645+
"minimum": 1.0,
645646
"format": "int32"
646647
},
647648
{
648649
"name": "pageSize",
649650
"in": "query",
650-
"required": false,
651+
"required": true,
651652
"type": "integer",
653+
"maximum": 50.0,
652654
"format": "int32"
653655
},
654656
{
@@ -905,6 +907,35 @@
905907
}
906908
}
907909
}
910+
},
911+
"/bugs/1864{?somename}": {
912+
"get": {
913+
"tags": [
914+
"bugs-controller"
915+
],
916+
"summary": "test",
917+
"operationId": "testUsingGET_1",
918+
"consumes": [
919+
"application/json"
920+
],
921+
"produces": [
922+
"application/xml",
923+
"application/json"
924+
],
925+
"parameters": [
926+
{
927+
"name": "somename",
928+
"in": "query",
929+
"required": true,
930+
"type": "string"
931+
}
932+
],
933+
"responses": {
934+
"200": {
935+
"description": "OK"
936+
}
937+
}
938+
}
908939
}
909940
},
910941
"securityDefinitions": {
@@ -1095,4 +1126,4 @@
10951126
}
10961127
}
10971128
}
1098-
}
1129+
}

swagger-contract-tests/src/test/resources/contract/swagger2/swagger.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
"basePath": "/",
1616
"tags": [
1717
{
18-
"name": "pet-store-resource",
19-
"description": "Operations about store"
18+
"name": "generic-pet-controller",
19+
"description": "Generic Pet Controller"
2020
},
2121
{
2222
"name": "pet-controller",
2323
"description": "Operations about pets"
2424
},
2525
{
26-
"name": "generic-pet-controller",
27-
"description": "Generic Pet Controller"
26+
"name": "pet-store-resource",
27+
"description": "Operations about store"
2828
},
2929
{
3030
"name": "user-controller",
3131
"description": "Operations about user"
3232
}
3333
],
3434
"schemes": [
35-
"http",
36-
"https"
35+
"https",
36+
"http"
3737
],
3838
"produces": [
3939
"application/xml",
@@ -990,4 +990,4 @@
990990
}
991991
}
992992
}
993-
}
993+
}

0 commit comments

Comments
 (0)