Skip to content

Commit a2d378f

Browse files
author
Bastian Wilhelm
committed
#34 add test case for bean validation
1 parent 085928f commit a2d378f

6 files changed

Lines changed: 295 additions & 1 deletion

File tree

src/testInt/groovy/com/github/hauner/openapi/generatr/GeneratrEndToEndTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class GeneratrEndToEndTest extends GeneratrTestBase {
4141
new TestSet(name: 'params-request-body'),
4242
new TestSet(name: 'params-request-body-multipart-form-data'),
4343
new TestSet(name: 'params-spring-pageable-mapping'),
44-
new TestSet(name: 'params-enum')
44+
new TestSet(name: 'params-enum'),
45+
// new TestSet(name: 'bean-validation'),
4546
]
4647
}
4748

src/testInt/resources/bean-validation/beanvalidation

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-generatr-spring.
3+
* DO NOT EDIT.
4+
*/
5+
6+
package generated.api;
7+
8+
import generated.model.Obj1;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.PostMapping;
12+
import org.springframework.web.bind.annotation.RequestBody;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
15+
import javax.validation.Valid;
16+
import javax.validation.constraints.*;
17+
18+
public interface EndpointApi {
19+
20+
@GetMapping(path = "/endpoint/nullable")
21+
ResponseEntity<Void> getEndpointNullable(
22+
@NotNull @RequestParam(name = "nullable-false", required = false) String nullableFalse,
23+
@RequestParam(name = "nullable-true", required = false) String nullableTrue);
24+
25+
@GetMapping(path = "/endpoint/length")
26+
ResponseEntity<Void> getEndpointLength(
27+
@Size(min = 2) @RequestParam(name = "min-length", required = false) String minLength,
28+
@Size(max = 4) @RequestParam(name = "max-length", required = false) String maxLength,
29+
@Size(min = 2, max = 4) @RequestParam(name = "min-max-length", required = false) String minMaxLength);
30+
31+
@GetMapping(path = "/endpoint/minmax")
32+
ResponseEntity<Void> getEndpointMinmax(
33+
@DecimalMin(value = 10) @RequestParam(name = "min", required = false) Integer min,
34+
@DecimalMin(value = 10, inclusive = false) @RequestParam(name = "min-ex", required = false) Integer minEx,
35+
@DecimalMax(value = 20) @RequestParam(name = "max", required = false) Integer max,
36+
@DecimalMax(value = 20, inclusive = false) @RequestParam(name = "max-ex", required = false) Integer maxEx,
37+
@DecimalMin(value = 10) @DecimalMax(value = 20) @RequestParam(name = "min-max", required = false) Integer minMax,
38+
@DecimalMin(value = 10, inclusive = false) @DecimalMax(value = 20, inclusive = false) @RequestParam(name = "min-max-ex", required = false) Integer minMaxEx);
39+
40+
@GetMapping(path = "/endpoint/items")
41+
ResponseEntity<Void> getEndpointItems(
42+
@Size(min = 2) @RequestParam(name = "min", required = false) List<String> min,
43+
@Size(max = 4) @RequestParam(name = "max", required = false) List<String> max,
44+
@Size(min = 2, max = 4) @RequestParam(name = "min-max", required = false) List<String> minMax);
45+
46+
@PostMapping(
47+
path = "/endpoint/obj",
48+
consumes = {"application/json"})
49+
ResponseEntity<Void> postEndpointObj(@Valid @RequestBody(required = false) Obj1 body);
50+
51+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-generatr-spring.
3+
* DO NOT EDIT.
4+
*/
5+
6+
package generated.model;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
import javax.validation.constraints.*;
11+
12+
public class Obj1 {
13+
14+
@JsonProperty("pro1")
15+
@NotNull
16+
private String prop1;
17+
18+
@JsonProperty("prop2")
19+
@DecimalMax(value = 3)
20+
private Integer prop2;
21+
22+
@JsonProperty("prop3")
23+
@Valid
24+
private Obj2 prop3;
25+
26+
public String getProp1() {
27+
return prop1;
28+
}
29+
30+
public void setProp1(String prop1) {
31+
this.prop1 = prop1;
32+
}
33+
34+
public Integer getProp2() {
35+
return prop2;
36+
}
37+
38+
public void setProp2(Integer prop2) {
39+
this.prop2 = prop2;
40+
}
41+
42+
public Obj2 getProp3() {
43+
return prop3;
44+
}
45+
46+
public void setProp3(Obj2 prop3) {
47+
this.prop3 = prop3;
48+
}
49+
50+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-generatr-spring.
3+
* DO NOT EDIT.
4+
*/
5+
6+
package generated.model;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
import javax.validation.constraints.*;
11+
12+
public class Obj2 {
13+
14+
@JsonProperty("prop4")
15+
@Size(max = 10)
16+
private String prop1;
17+
18+
public String getProp4() {
19+
return prop4;
20+
}
21+
22+
public void setProp4(String prop4) {
23+
this.prop4 = prop4;
24+
}
25+
26+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
openapi: 3.0.2
2+
info:
3+
title: test simple path parameters
4+
version: 1.0.0
5+
6+
paths:
7+
/endpoint/nullable:
8+
get:
9+
tags:
10+
- endpoint
11+
parameters:
12+
- in: query
13+
name: nullable-false
14+
schema:
15+
type: string
16+
nullable: false
17+
- in: query
18+
name: nullable-true
19+
schema:
20+
type: string
21+
nullable: true
22+
responses:
23+
'204':
24+
description: empty
25+
26+
/endpoint/length:
27+
get:
28+
tags:
29+
- endpoint
30+
parameters:
31+
- in: query
32+
name: min-length
33+
schema:
34+
type: string
35+
minLength: 2
36+
- in: query
37+
name: max-length
38+
schema:
39+
type: string
40+
maxLength: 4
41+
- in: query
42+
name: min-max-length
43+
schema:
44+
type: string
45+
minLength: 2
46+
maxLength: 4
47+
responses:
48+
'204':
49+
description: empty
50+
51+
/endpoint/minmax:
52+
get:
53+
tags:
54+
- endpoint
55+
parameters:
56+
- in: query
57+
name: min
58+
schema:
59+
type: integer
60+
format: int32
61+
minimum: 10
62+
- in: query
63+
name: min-ex
64+
schema:
65+
type: integer
66+
format: int32
67+
minimum: 10
68+
exclusiveMinimum: true
69+
- in: query
70+
name: max
71+
schema:
72+
type: integer
73+
format: int32
74+
maximum: 20
75+
- in: query
76+
name: max-ex
77+
schema:
78+
type: integer
79+
format: int32
80+
maximum: 20
81+
exclusiveMaximum: true
82+
- in: query
83+
name: min-max
84+
schema:
85+
type: integer
86+
format: int32
87+
minimum: 10
88+
maximum: 20
89+
- in: query
90+
name: min-max-ex
91+
schema:
92+
type: integer
93+
format: int32
94+
minimum: 10
95+
exclusiveMinimum: true
96+
maximum: 20
97+
exclusiveMaximum: true
98+
responses:
99+
'204':
100+
description: empty
101+
102+
/endpoint/items:
103+
get:
104+
tags:
105+
- endpoint
106+
parameters:
107+
- in: query
108+
name: min
109+
schema:
110+
type: array
111+
minItems: 2
112+
items:
113+
type: string
114+
- in: query
115+
name: max
116+
schema:
117+
type: array
118+
maxItems: 4
119+
items:
120+
type: string
121+
- in: query
122+
name: min-max
123+
schema:
124+
type: array
125+
minItems: 2
126+
maxItems: 4
127+
items:
128+
type: string
129+
responses:
130+
'204':
131+
description: empty
132+
133+
/endpoint/obj:
134+
post:
135+
tags:
136+
- endpoint
137+
requestBody:
138+
content:
139+
application/json:
140+
schema:
141+
$ref: '#/components/schemas/Obj1'
142+
responses:
143+
'204':
144+
description: empty
145+
146+
147+
components:
148+
schemas:
149+
Obj1:
150+
type: object
151+
properties:
152+
prop1:
153+
type: string
154+
nullable: false
155+
prop2:
156+
type: integer
157+
format: int32
158+
maximum: 3
159+
prop3:
160+
$ref: '#/components/schemas/Obj2'
161+
Obj2:
162+
type: object
163+
properties:
164+
prop4:
165+
type: string
166+
maxLength: 10

0 commit comments

Comments
 (0)