This repository was archived by the owner on Dec 25, 2024. It is now read-only.
File tree 10 files changed +97
-1
lines changed
samples/client/3_1_0_unit_test/java
src/main/java/org/openapijsonschematools/client
src/main/resources/java/src/main/java/packagename/components/schemas/SchemaClass
10 files changed +97
-1
lines changed Original file line number Diff line number Diff line change @@ -287,10 +287,12 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/LongEnumValid
287
287
src/main/java/org/openapijsonschematools/client/schemas/validation/LongValueMethod.java
288
288
src/main/java/org/openapijsonschematools/client/schemas/validation/MapSchemaValidator.java
289
289
src/main/java/org/openapijsonschematools/client/schemas/validation/MapUtils.java
290
+ src/main/java/org/openapijsonschematools/client/schemas/validation/MaxContainsValidator.java
290
291
src/main/java/org/openapijsonschematools/client/schemas/validation/MaxItemsValidator.java
291
292
src/main/java/org/openapijsonschematools/client/schemas/validation/MaxLengthValidator.java
292
293
src/main/java/org/openapijsonschematools/client/schemas/validation/MaxPropertiesValidator.java
293
294
src/main/java/org/openapijsonschematools/client/schemas/validation/MaximumValidator.java
295
+ src/main/java/org/openapijsonschematools/client/schemas/validation/MinContainsValidator.java
294
296
src/main/java/org/openapijsonschematools/client/schemas/validation/MinItemsValidator.java
295
297
src/main/java/org/openapijsonschematools/client/schemas/validation/MinLengthValidator.java
296
298
src/main/java/org/openapijsonschematools/client/schemas/validation/MinPropertiesValidator.java
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ A schema class that validates payloads
19
19
### Field Summary
20
20
| Modifier and Type | Field and Description |
21
21
| ----------------- | ---------------------- |
22
+ | Integer | maxContains = 1 |
22
23
23
24
### Method Summary
24
25
| Modifier and Type | Method and Description |
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ A schema class that validates payloads
19
19
### Field Summary
20
20
| Modifier and Type | Field and Description |
21
21
| ----------------- | ---------------------- |
22
+ | Integer | minContains = 1 |
22
23
23
24
### Method Summary
24
25
| Modifier and Type | Method and Description |
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ public static class MaxcontainsWithoutContainsIsIgnored1 extends JsonSchema impl
46
46
47
47
protected MaxcontainsWithoutContainsIsIgnored1 () {
48
48
super (new JsonSchemaInfo ()
49
+ .maxContains (1 )
49
50
);
50
51
}
51
52
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ public static class MincontainsWithoutContainsIsIgnored1 extends JsonSchema impl
46
46
47
47
protected MincontainsWithoutContainsIsIgnored1 () {
48
48
super (new JsonSchemaInfo ()
49
+ .minContains (1 )
49
50
);
50
51
}
51
52
Original file line number Diff line number Diff line change @@ -236,6 +236,20 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
236
236
new ContainsValidator (this .contains )
237
237
);
238
238
}
239
+ this .maxContains = jsonSchemaInfo .maxContains ;
240
+ if (this .maxContains != null ) {
241
+ keywordToValidator .put (
242
+ "maxContains" ,
243
+ new MaxContainsValidator (this .maxContains )
244
+ );
245
+ }
246
+ this .minContains = jsonSchemaInfo .minContains ;
247
+ if (this .minContains != null ) {
248
+ keywordToValidator .put (
249
+ "minContains" ,
250
+ new MinContainsValidator (this .minContains )
251
+ );
252
+ }
239
253
this .keywordToValidator = keywordToValidator ;
240
254
}
241
255
Original file line number Diff line number Diff line change @@ -147,4 +147,14 @@ public JsonSchemaInfo contains(Class<? extends JsonSchema> contains) {
147
147
this .contains = contains ;
148
148
return this ;
149
149
}
150
+ public @ Nullable Integer maxContains = null ;
151
+ public JsonSchemaInfo maxContains (Integer maxContains ) {
152
+ this .maxContains = maxContains ;
153
+ return this ;
154
+ }
155
+ public @ Nullable Integer minContains = null ;
156
+ public JsonSchemaInfo minContains (Integer minContains ) {
157
+ this .minContains = minContains ;
158
+ return this ;
159
+ }
150
160
}
Original file line number Diff line number Diff line change
1
+ package org .openapijsonschematools .client .schemas .validation ;
2
+
3
+ import org .checkerframework .checker .nullness .qual .Nullable ;
4
+ import org .openapijsonschematools .client .exceptions .ValidationException ;
5
+
6
+ import java .util .List ;
7
+
8
+ public class MaxContainsValidator implements KeywordValidator {
9
+ public final int maxContains ;
10
+
11
+ public MaxContainsValidator (int maxContains ) {
12
+ this .maxContains = maxContains ;
13
+ }
14
+
15
+ @ Override
16
+ public @ Nullable PathToSchemasMap validate (
17
+ JsonSchema schema ,
18
+ @ Nullable Object arg ,
19
+ ValidationMetadata validationMetadata ,
20
+ List <PathToSchemasMap > containsPathToSchemas
21
+ ) {
22
+ if (!(arg instanceof List )) {
23
+ return null ;
24
+ }
25
+ if (containsPathToSchemas .size () > maxContains ) {
26
+ throw new ValidationException (
27
+ "Validation failed for maxContains keyword in class=" +schema .getClass ()+
28
+ " at pathToItem=" +validationMetadata .pathToItem ()+". Too many items validated to the contains schema."
29
+ )
30
+ }
31
+ return null ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ package org .openapijsonschematools .client .schemas .validation ;
2
+
3
+ import org .checkerframework .checker .nullness .qual .Nullable ;
4
+ import org .openapijsonschematools .client .exceptions .ValidationException ;
5
+
6
+ import java .util .List ;
7
+
8
+ public class MinContainsValidator implements KeywordValidator {
9
+ public final int minContains ;
10
+
11
+ public MinContainsValidator (int minContains ) {
12
+ this .minContains = minContains ;
13
+ }
14
+
15
+ @ Override
16
+ public @ Nullable PathToSchemasMap validate (
17
+ JsonSchema schema ,
18
+ @ Nullable Object arg ,
19
+ ValidationMetadata validationMetadata ,
20
+ List <PathToSchemasMap > containsPathToSchemas
21
+ ) {
22
+ if (!(arg instanceof List )) {
23
+ return null ;
24
+ }
25
+ if (containsPathToSchemas .size () < minContains ) {
26
+ throw new ValidationException (
27
+ "Validation failed for minContains keyword in class=" +schema .getClass ()+
28
+ " at pathToItem=" +validationMetadata .pathToItem ()+". Too few items validated to the contains schema."
29
+ )
30
+ }
31
+ return null ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ public static class {{jsonPathPiece.pascalCase}} extends JsonSchema implements L
49
49
{{ /if }}
50
50
{{ #neq maxContains null}}
51
51
{{> src/main/java/packagename/components/schemas/SchemaClass/_maxContains }}
52
- {{ /if }}
52
+ {{ /neq }}
53
53
{{ #neq minContains null}}
54
54
{{> src/main/java/packagename/components/schemas/SchemaClass/_minContains }}
55
55
{{ /neq }}
You can’t perform that action at this time.
0 commit comments