This repository was archived by the owner on Dec 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 13 files changed +178
-11
lines changed
src/main/java/org/openapijsonschematools/client/schemas/validation
3_1_0_unit_test/java/.openapi-generator
src/main/java/org/openapijsonschematools/client/schemas/validation
src/main/java/org/openapijsonschematools/codegen/generators Expand file tree Collapse file tree 13 files changed +178
-11
lines changed Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
282
282
|DependentRequired|✓|OAS3
283
283
|DependentSchemas|✓|OAS3
284
284
|Discriminator|✗|OAS2,OAS3
285
- |Else|✗ |OAS3
285
+ |Else|✓ |OAS3
286
286
|Enum|✓|OAS2,OAS3
287
287
|ExclusiveMinimum|✓|OAS2,OAS3
288
288
|ExclusiveMaximum|✓|OAS2,OAS3
@@ -310,7 +310,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
310
310
|PropertyNames|✓|OAS3
311
311
|Ref|✓|OAS2,OAS3
312
312
|Required|✓|OAS2,OAS3
313
- |Then|✗ |OAS3
313
+ |Then|✓ |OAS3
314
314
|Type|✓|OAS2,OAS3
315
315
|UnevaluatedItems|✗|OAS3
316
316
|UnevaluatedProperties|✗|OAS3
Original file line number Diff line number Diff line change @@ -217,6 +217,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/DependentRequ
217
217
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentSchemasValidator.java
218
218
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
219
219
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
220
+ src/main/java/org/openapijsonschematools/client/schemas/validation/ElseValidator.java
220
221
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java
221
222
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMaximumValidator.java
222
223
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMinimumValidator.java
@@ -268,6 +269,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/RequiredValid
268
269
src/main/java/org/openapijsonschematools/client/schemas/validation/StringEnumValidator.java
269
270
src/main/java/org/openapijsonschematools/client/schemas/validation/StringSchemaValidator.java
270
271
src/main/java/org/openapijsonschematools/client/schemas/validation/StringValueMethod.java
272
+ src/main/java/org/openapijsonschematools/client/schemas/validation/ThenValidator.java
271
273
src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java
272
274
src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsValidator.java
273
275
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
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 .InvalidTypeException ;
5
+ import org .openapijsonschematools .client .exceptions .ValidationException ;
6
+
7
+ public class ElseValidator implements KeywordValidator {
8
+ @ Override
9
+ public @ Nullable PathToSchemasMap validate (
10
+ ValidationData data
11
+ ) {
12
+ var elseSchema = data .schema ().elseSchema ;
13
+ if (elseSchema == null ) {
14
+ return null ;
15
+ }
16
+ var ifPathToSchemas = data .ifPathToSchemas ();
17
+ if (ifPathToSchemas == null ) {
18
+ // if unset
19
+ return null ;
20
+ }
21
+ if (!ifPathToSchemas .isEmpty ()) {
22
+ // if validation is true
23
+ return null ;
24
+ }
25
+ JsonSchema elseSchemaInstance = JsonSchemaFactory .getInstance (elseSchema );
26
+ PathToSchemasMap pathToSchemas = new PathToSchemasMap ();
27
+ var elsePathToSchemas = JsonSchema .validate (elseSchemaInstance , data .arg (), data .validationMetadata ());
28
+ // todo capture validation error and describe it as an else error?
29
+ pathToSchemas .update (elsePathToSchemas );
30
+ return pathToSchemas ;
31
+ }
32
+ }
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ public abstract class JsonSchema {
55
55
public final @ Nullable Map <Pattern , Class <? extends JsonSchema >> patternProperties ;
56
56
public final @ Nullable List <Class <? extends JsonSchema >> prefixItems ;
57
57
public final @ Nullable Class <? extends JsonSchema > ifSchema ;
58
+ public final @ Nullable Class <? extends JsonSchema > then ;
59
+ public final @ Nullable Class <? extends JsonSchema > elseSchema ;
58
60
private final LinkedHashMap <String , KeywordValidator > keywordToValidator ;
59
61
60
62
protected JsonSchema (JsonSchemaInfo jsonSchemaInfo ) {
@@ -198,6 +200,14 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
198
200
if (this .ifSchema != null ) {
199
201
keywordToValidator .put ("if" , new IfValidator ());
200
202
}
203
+ this .then = jsonSchemaInfo .then ;
204
+ if (this .then != null ) {
205
+ keywordToValidator .put ("then" , new ThenValidator ());
206
+ }
207
+ this .elseSchema = jsonSchemaInfo .elseSchema ;
208
+ if (this .elseSchema != null ) {
209
+ keywordToValidator .put ("else" , new ElseValidator ());
210
+ }
201
211
this .keywordToValidator = keywordToValidator ;
202
212
}
203
213
Original file line number Diff line number Diff line change @@ -187,4 +187,14 @@ public JsonSchemaInfo ifSchema(Class<? extends JsonSchema> ifSchema) {
187
187
this .ifSchema = ifSchema ;
188
188
return this ;
189
189
}
190
+ public @ Nullable Class <? extends JsonSchema > then = null ;
191
+ public JsonSchemaInfo then (Class <? extends JsonSchema > then ) {
192
+ this .then = then ;
193
+ return this ;
194
+ }
195
+ public @ Nullable Class <? extends JsonSchema > elseSchema = null ;
196
+ public JsonSchemaInfo elseSchema (Class <? extends JsonSchema > elseSchema ) {
197
+ this .elseSchema = elseSchema ;
198
+ return this ;
199
+ }
190
200
}
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 .InvalidTypeException ;
5
+ import org .openapijsonschematools .client .exceptions .ValidationException ;
6
+
7
+ public class ThenValidator implements KeywordValidator {
8
+ @ Override
9
+ public @ Nullable PathToSchemasMap validate (
10
+ ValidationData data
11
+ ) {
12
+ var then = data .schema ().then ;
13
+ if (then == null ) {
14
+ return null ;
15
+ }
16
+ var ifPathToSchemas = data .ifPathToSchemas ();
17
+ if (ifPathToSchemas == null ) {
18
+ // if unset
19
+ return null ;
20
+ }
21
+ if (ifPathToSchemas .isEmpty ()) {
22
+ // if validation is false
23
+ return null ;
24
+ }
25
+ JsonSchema thenSchema = JsonSchemaFactory .getInstance (then );
26
+ PathToSchemasMap pathToSchemas = new PathToSchemasMap ();
27
+ var thenPathToSchemas = JsonSchema .validate (thenSchema , data .arg (), data .validationMetadata ());
28
+ // todo capture validation error and describe it as an then error?
29
+ pathToSchemas .update (ifPathToSchemas );
30
+ pathToSchemas .update (thenPathToSchemas );
31
+ return pathToSchemas ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -380,13 +380,6 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMet
380
380
src/main/java/org/openapijsonschematools/client/servers/Server0.java
381
381
src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java
382
382
src/main/java/org/openapijsonschematools/client/servers/ServerWithoutVariables.java
383
- src/test/java/org/openapijsonschematools/client/components/schemas/IfAndElseWithoutThenTest.java
384
- src/test/java/org/openapijsonschematools/client/components/schemas/IfAndThenWithoutElseTest.java
385
- src/test/java/org/openapijsonschematools/client/components/schemas/IfAppearsAtTheEndWhenSerializedKeywordProcessingSequenceTest.java
386
- src/test/java/org/openapijsonschematools/client/components/schemas/IgnoreElseWithoutIfTest.java
387
- src/test/java/org/openapijsonschematools/client/components/schemas/IgnoreThenWithoutIfTest.java
388
- src/test/java/org/openapijsonschematools/client/components/schemas/NonInterferenceAcrossCombinedSchemasTest.java
389
- src/test/java/org/openapijsonschematools/client/components/schemas/ValidateAgainstCorrectBranchThenVsElseTest.java
390
383
src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java
391
384
src/test/java/org/openapijsonschematools/client/schemas/AnyTypeSchemaTest.java
392
385
src/test/java/org/openapijsonschematools/client/schemas/ArrayTypeSchemaTest.java
Original file line number Diff line number Diff line change @@ -695,6 +695,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/DependentRequ
695
695
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentSchemasValidator.java
696
696
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
697
697
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
698
+ src/main/java/org/openapijsonschematools/client/schemas/validation/ElseValidator.java
698
699
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java
699
700
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMaximumValidator.java
700
701
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMinimumValidator.java
@@ -746,6 +747,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/RequiredValid
746
747
src/main/java/org/openapijsonschematools/client/schemas/validation/StringEnumValidator.java
747
748
src/main/java/org/openapijsonschematools/client/schemas/validation/StringSchemaValidator.java
748
749
src/main/java/org/openapijsonschematools/client/schemas/validation/StringValueMethod.java
750
+ src/main/java/org/openapijsonschematools/client/schemas/validation/ThenValidator.java
749
751
src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java
750
752
src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsValidator.java
751
753
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
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 .InvalidTypeException ;
5
+ import org .openapijsonschematools .client .exceptions .ValidationException ;
6
+
7
+ public class ElseValidator implements KeywordValidator {
8
+ @ Override
9
+ public @ Nullable PathToSchemasMap validate (
10
+ ValidationData data
11
+ ) {
12
+ var elseSchema = data .schema ().elseSchema ;
13
+ if (elseSchema == null ) {
14
+ return null ;
15
+ }
16
+ var ifPathToSchemas = data .ifPathToSchemas ();
17
+ if (ifPathToSchemas == null ) {
18
+ // if unset
19
+ return null ;
20
+ }
21
+ if (!ifPathToSchemas .isEmpty ()) {
22
+ // if validation is true
23
+ return null ;
24
+ }
25
+ JsonSchema elseSchemaInstance = JsonSchemaFactory .getInstance (elseSchema );
26
+ PathToSchemasMap pathToSchemas = new PathToSchemasMap ();
27
+ var elsePathToSchemas = JsonSchema .validate (elseSchemaInstance , data .arg (), data .validationMetadata ());
28
+ // todo capture validation error and describe it as an else error?
29
+ pathToSchemas .update (elsePathToSchemas );
30
+ return pathToSchemas ;
31
+ }
32
+ }
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ public abstract class JsonSchema {
55
55
public final @ Nullable Map <Pattern , Class <? extends JsonSchema >> patternProperties ;
56
56
public final @ Nullable List <Class <? extends JsonSchema >> prefixItems ;
57
57
public final @ Nullable Class <? extends JsonSchema > ifSchema ;
58
+ public final @ Nullable Class <? extends JsonSchema > then ;
59
+ public final @ Nullable Class <? extends JsonSchema > elseSchema ;
58
60
private final LinkedHashMap <String , KeywordValidator > keywordToValidator ;
59
61
60
62
protected JsonSchema (JsonSchemaInfo jsonSchemaInfo ) {
@@ -198,6 +200,14 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
198
200
if (this .ifSchema != null ) {
199
201
keywordToValidator .put ("if" , new IfValidator ());
200
202
}
203
+ this .then = jsonSchemaInfo .then ;
204
+ if (this .then != null ) {
205
+ keywordToValidator .put ("then" , new ThenValidator ());
206
+ }
207
+ this .elseSchema = jsonSchemaInfo .elseSchema ;
208
+ if (this .elseSchema != null ) {
209
+ keywordToValidator .put ("else" , new ElseValidator ());
210
+ }
201
211
this .keywordToValidator = keywordToValidator ;
202
212
}
203
213
Original file line number Diff line number Diff line change @@ -187,4 +187,14 @@ public JsonSchemaInfo ifSchema(Class<? extends JsonSchema> ifSchema) {
187
187
this .ifSchema = ifSchema ;
188
188
return this ;
189
189
}
190
+ public @ Nullable Class <? extends JsonSchema > then = null ;
191
+ public JsonSchemaInfo then (Class <? extends JsonSchema > then ) {
192
+ this .then = then ;
193
+ return this ;
194
+ }
195
+ public @ Nullable Class <? extends JsonSchema > elseSchema = null ;
196
+ public JsonSchemaInfo elseSchema (Class <? extends JsonSchema > elseSchema ) {
197
+ this .elseSchema = elseSchema ;
198
+ return this ;
199
+ }
190
200
}
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 .InvalidTypeException ;
5
+ import org .openapijsonschematools .client .exceptions .ValidationException ;
6
+
7
+ public class ThenValidator implements KeywordValidator {
8
+ @ Override
9
+ public @ Nullable PathToSchemasMap validate (
10
+ ValidationData data
11
+ ) {
12
+ var then = data .schema ().then ;
13
+ if (then == null ) {
14
+ return null ;
15
+ }
16
+ var ifPathToSchemas = data .ifPathToSchemas ();
17
+ if (ifPathToSchemas == null ) {
18
+ // if unset
19
+ return null ;
20
+ }
21
+ if (ifPathToSchemas .isEmpty ()) {
22
+ // if validation is false
23
+ return null ;
24
+ }
25
+ JsonSchema thenSchema = JsonSchemaFactory .getInstance (then );
26
+ PathToSchemasMap pathToSchemas = new PathToSchemasMap ();
27
+ var thenPathToSchemas = JsonSchema .validate (thenSchema , data .arg (), data .validationMetadata ());
28
+ // todo capture validation error and describe it as an then error?
29
+ pathToSchemas .update (ifPathToSchemas );
30
+ pathToSchemas .update (thenPathToSchemas );
31
+ return pathToSchemas ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -261,7 +261,7 @@ public JavaClientGenerator() {
261
261
SchemaFeature .DependentRequired ,
262
262
SchemaFeature .DependentSchemas ,
263
263
// SchemaFeature.Discriminator,
264
- // SchemaFeature.Else,
264
+ SchemaFeature .Else ,
265
265
SchemaFeature .Enum ,
266
266
SchemaFeature .ExclusiveMaximum ,
267
267
SchemaFeature .ExclusiveMinimum ,
@@ -289,7 +289,7 @@ public JavaClientGenerator() {
289
289
SchemaFeature .PropertyNames ,
290
290
SchemaFeature .Ref ,
291
291
SchemaFeature .Required ,
292
- // SchemaFeature.Then,
292
+ SchemaFeature .Then ,
293
293
SchemaFeature .Type ,
294
294
// SchemaFeature.UnevaluatedItems,
295
295
// SchemaFeature.UnevaluatedProperties,
You can’t perform that action at this time.
0 commit comments