Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 5abbd7b

Browse files
committed
Samples and docs updated
1 parent c60c778 commit 5abbd7b

File tree

13 files changed

+178
-11
lines changed

13 files changed

+178
-11
lines changed

docs/generators/java.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
282282
|DependentRequired|✓|OAS3
283283
|DependentSchemas|✓|OAS3
284284
|Discriminator|✗|OAS2,OAS3
285-
|Else||OAS3
285+
|Else||OAS3
286286
|Enum|✓|OAS2,OAS3
287287
|ExclusiveMinimum|✓|OAS2,OAS3
288288
|ExclusiveMaximum|✓|OAS2,OAS3
@@ -310,7 +310,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
310310
|PropertyNames|✓|OAS3
311311
|Ref|✓|OAS2,OAS3
312312
|Required|✓|OAS2,OAS3
313-
|Then||OAS3
313+
|Then||OAS3
314314
|Type|✓|OAS2,OAS3
315315
|UnevaluatedItems|✗|OAS3
316316
|UnevaluatedProperties|✗|OAS3

samples/client/3_0_3_unit_test/java/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/DependentRequ
217217
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentSchemasValidator.java
218218
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
219219
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
220+
src/main/java/org/openapijsonschematools/client/schemas/validation/ElseValidator.java
220221
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java
221222
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMaximumValidator.java
222223
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMinimumValidator.java
@@ -268,6 +269,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/RequiredValid
268269
src/main/java/org/openapijsonschematools/client/schemas/validation/StringEnumValidator.java
269270
src/main/java/org/openapijsonschematools/client/schemas/validation/StringSchemaValidator.java
270271
src/main/java/org/openapijsonschematools/client/schemas/validation/StringValueMethod.java
272+
src/main/java/org/openapijsonschematools/client/schemas/validation/ThenValidator.java
271273
src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java
272274
src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsValidator.java
273275
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public abstract class JsonSchema {
5555
public final @Nullable Map<Pattern, Class<? extends JsonSchema>> patternProperties;
5656
public final @Nullable List<Class<? extends JsonSchema>> prefixItems;
5757
public final @Nullable Class<? extends JsonSchema> ifSchema;
58+
public final @Nullable Class<? extends JsonSchema> then;
59+
public final @Nullable Class<? extends JsonSchema> elseSchema;
5860
private final LinkedHashMap<String, KeywordValidator> keywordToValidator;
5961

6062
protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
@@ -198,6 +200,14 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
198200
if (this.ifSchema != null) {
199201
keywordToValidator.put("if", new IfValidator());
200202
}
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+
}
201211
this.keywordToValidator = keywordToValidator;
202212
}
203213

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,14 @@ public JsonSchemaInfo ifSchema(Class<? extends JsonSchema> ifSchema) {
187187
this.ifSchema = ifSchema;
188188
return this;
189189
}
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+
}
190200
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

samples/client/3_1_0_unit_test/java/.openapi-generator/FILES

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,6 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMet
380380
src/main/java/org/openapijsonschematools/client/servers/Server0.java
381381
src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java
382382
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
390383
src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java
391384
src/test/java/org/openapijsonschematools/client/schemas/AnyTypeSchemaTest.java
392385
src/test/java/org/openapijsonschematools/client/schemas/ArrayTypeSchemaTest.java

samples/client/petstore/java/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/DependentRequ
695695
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentSchemasValidator.java
696696
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
697697
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
698+
src/main/java/org/openapijsonschematools/client/schemas/validation/ElseValidator.java
698699
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java
699700
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMaximumValidator.java
700701
src/main/java/org/openapijsonschematools/client/schemas/validation/ExclusiveMinimumValidator.java
@@ -746,6 +747,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/RequiredValid
746747
src/main/java/org/openapijsonschematools/client/schemas/validation/StringEnumValidator.java
747748
src/main/java/org/openapijsonschematools/client/schemas/validation/StringSchemaValidator.java
748749
src/main/java/org/openapijsonschematools/client/schemas/validation/StringValueMethod.java
750+
src/main/java/org/openapijsonschematools/client/schemas/validation/ThenValidator.java
749751
src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java
750752
src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsValidator.java
751753
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public abstract class JsonSchema {
5555
public final @Nullable Map<Pattern, Class<? extends JsonSchema>> patternProperties;
5656
public final @Nullable List<Class<? extends JsonSchema>> prefixItems;
5757
public final @Nullable Class<? extends JsonSchema> ifSchema;
58+
public final @Nullable Class<? extends JsonSchema> then;
59+
public final @Nullable Class<? extends JsonSchema> elseSchema;
5860
private final LinkedHashMap<String, KeywordValidator> keywordToValidator;
5961

6062
protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
@@ -198,6 +200,14 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
198200
if (this.ifSchema != null) {
199201
keywordToValidator.put("if", new IfValidator());
200202
}
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+
}
201211
this.keywordToValidator = keywordToValidator;
202212
}
203213

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,14 @@ public JsonSchemaInfo ifSchema(Class<? extends JsonSchema> ifSchema) {
187187
this.ifSchema = ifSchema;
188188
return this;
189189
}
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+
}
190200
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

src/main/java/org/openapijsonschematools/codegen/generators/JavaClientGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public JavaClientGenerator() {
261261
SchemaFeature.DependentRequired,
262262
SchemaFeature.DependentSchemas,
263263
// SchemaFeature.Discriminator,
264-
// SchemaFeature.Else,
264+
SchemaFeature.Else,
265265
SchemaFeature.Enum,
266266
SchemaFeature.ExclusiveMaximum,
267267
SchemaFeature.ExclusiveMinimum,
@@ -289,7 +289,7 @@ public JavaClientGenerator() {
289289
SchemaFeature.PropertyNames,
290290
SchemaFeature.Ref,
291291
SchemaFeature.Required,
292-
// SchemaFeature.Then,
292+
SchemaFeature.Then,
293293
SchemaFeature.Type,
294294
// SchemaFeature.UnevaluatedItems,
295295
// SchemaFeature.UnevaluatedProperties,

0 commit comments

Comments
 (0)