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

Commit fed7bf9

Browse files
authored
Java, adds dependentSchemas (#365)
* dependentSchemas tests turned on in java 310 test spec * Samples regen
1 parent 8a24aad commit fed7bf9

File tree

40 files changed

+4145
-17
lines changed

40 files changed

+4145
-17
lines changed

.circleci/parallel.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ elif [ "$JOB_ID" = "testJava17ClientSamples" ]; then
3131

3232
(cd samples/client/petstore/java && mvn test)
3333
(cd samples/client/3_0_3_unit_test/java && mvn test)
34+
(cd samples/client/3_1_0_unit_test/java && mvn test)
3435

3536
else
3637
echo "Running job $JOB_ID"

docs/generators/java.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
280280
|Contains|✓|OAS3
281281
|Default|✓|OAS2,OAS3
282282
|DependentRequired|✓|OAS3
283-
|DependentSchemas||OAS3
283+
|DependentSchemas||OAS3
284284
|Discriminator|✗|OAS2,OAS3
285285
|Else|✗|OAS3
286286
|Enum|✓|OAS2,OAS3

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

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/ContainsValid
214214
src/main/java/org/openapijsonschematools/client/schemas/validation/CustomIsoparser.java
215215
src/main/java/org/openapijsonschematools/client/schemas/validation/DefaultValueMethod.java
216216
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentRequiredValidator.java
217+
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentSchemasValidator.java
217218
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
218219
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
219220
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.openapijsonschematools.client.schemas.validation;
2+
3+
import org.checkerframework.checker.nullness.qual.Nullable;
4+
5+
import java.util.ArrayList;
6+
import java.util.LinkedHashSet;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Set;
10+
11+
public class DependentSchemasValidator implements KeywordValidator {
12+
public final Map<String, Class<? extends JsonSchema>> dependentSchemas;
13+
14+
public DependentSchemasValidator(Map<String, Class<? extends JsonSchema>> dependentSchemas) {
15+
this.dependentSchemas = dependentSchemas;
16+
}
17+
18+
@Override
19+
public @Nullable PathToSchemasMap validate(
20+
JsonSchema schema,
21+
@Nullable Object arg,
22+
ValidationMetadata validationMetadata,
23+
@Nullable List<PathToSchemasMap> containsPathToSchemas
24+
) {
25+
if (!(arg instanceof Map<?, ?> mapArg)) {
26+
return null;
27+
}
28+
PathToSchemasMap pathToSchemas = new PathToSchemasMap();
29+
Set<String> presentProperties = new LinkedHashSet<>();
30+
for (Object key: mapArg.keySet()) {
31+
if (key instanceof String) {
32+
presentProperties.add((String) key);
33+
}
34+
}
35+
for(Map.Entry<String, Class<? extends JsonSchema>> entry: dependentSchemas.entrySet()) {
36+
String propName = entry.getKey();
37+
if (!presentProperties.contains(propName)) {
38+
continue;
39+
}
40+
Class<? extends JsonSchema> dependentSchemaClass = entry.getValue();
41+
JsonSchema dependentSchema = JsonSchemaFactory.getInstance(dependentSchemaClass);
42+
PathToSchemasMap otherPathToSchemas = JsonSchema.validate(dependentSchema, arg, validationMetadata);
43+
pathToSchemas.update(otherPathToSchemas);
44+
}
45+
return pathToSchemas;
46+
}
47+
}
48+

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

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public abstract class JsonSchema {
5151
public final @Nullable Integer minContains;
5252
public final @Nullable Class<? extends JsonSchema> propertyNames;
5353
public @Nullable Map<String, Set<String>> dependentRequired;
54+
public final @Nullable Map<String, Class<? extends JsonSchema>> dependentSchemas;
5455
private final LinkedHashMap<String, KeywordValidator> keywordToValidator;
5556

5657
protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
@@ -268,6 +269,13 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
268269
new DependentRequiredValidator(this.dependentRequired)
269270
);
270271
}
272+
this.dependentSchemas = jsonSchemaInfo.dependentSchemas;
273+
if (this.dependentSchemas != null) {
274+
keywordToValidator.put(
275+
"dependentSchemas",
276+
new DependentSchemasValidator(this.dependentSchemas)
277+
);
278+
}
271279
this.keywordToValidator = keywordToValidator;
272280
}
273281

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

+5
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,9 @@ public JsonSchemaInfo dependentRequired(Map<String, Set<String>> dependentRequir
167167
this.dependentRequired = dependentRequired;
168168
return this;
169169
}
170+
public @Nullable Map<String, Class<? extends JsonSchema>> dependentSchemas = null;
171+
public JsonSchemaInfo dependentSchemas(Map<String, Class<? extends JsonSchema>> dependentSchemas) {
172+
this.dependentSchemas = dependentSchemas;
173+
return this;
174+
}
170175
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ docs/components/schemas/ContainsKeywordValidation.md
2626
docs/components/schemas/ContainsWithNullInstanceElements.md
2727
docs/components/schemas/DateFormat.md
2828
docs/components/schemas/DateTimeFormat.md
29+
docs/components/schemas/DependentSchemasDependenciesWithEscapedCharacters.md
30+
docs/components/schemas/DependentSchemasDependentSubschemaIncompatibleWithRoot.md
31+
docs/components/schemas/DependentSchemasSingleDependency.md
2932
docs/components/schemas/DurationFormat.md
3033
docs/components/schemas/EmailFormat.md
3134
docs/components/schemas/EmptyDependents.md
@@ -63,6 +66,7 @@ docs/components/schemas/MinimumValidationWithSignedInteger.md
6366
docs/components/schemas/MinitemsValidation.md
6467
docs/components/schemas/MinlengthValidation.md
6568
docs/components/schemas/MinpropertiesValidation.md
69+
docs/components/schemas/MultipleDependentsRequired.md
6670
docs/components/schemas/MultipleTypesCanBeSpecifiedInAnArray.md
6771
docs/components/schemas/NestedAllofToCheckValidationSemantics.md
6872
docs/components/schemas/NestedAnyofToCheckValidationSemantics.md
@@ -97,6 +101,7 @@ docs/components/schemas/RequiredValidation.md
97101
docs/components/schemas/RequiredWithEmptyArray.md
98102
docs/components/schemas/RequiredWithEscapedCharacters.md
99103
docs/components/schemas/SimpleEnumValidation.md
104+
docs/components/schemas/SingleDependency.md
100105
docs/components/schemas/SmallMultipleOfLargeInteger.md
101106
docs/components/schemas/StringTypeMatchesStrings.md
102107
docs/components/schemas/TimeFormat.md
@@ -141,6 +146,9 @@ src/main/java/org/openapijsonschematools/client/components/schemas/ContainsKeywo
141146
src/main/java/org/openapijsonschematools/client/components/schemas/ContainsWithNullInstanceElements.java
142147
src/main/java/org/openapijsonschematools/client/components/schemas/DateFormat.java
143148
src/main/java/org/openapijsonschematools/client/components/schemas/DateTimeFormat.java
149+
src/main/java/org/openapijsonschematools/client/components/schemas/DependentSchemasDependenciesWithEscapedCharacters.java
150+
src/main/java/org/openapijsonschematools/client/components/schemas/DependentSchemasDependentSubschemaIncompatibleWithRoot.java
151+
src/main/java/org/openapijsonschematools/client/components/schemas/DependentSchemasSingleDependency.java
144152
src/main/java/org/openapijsonschematools/client/components/schemas/DurationFormat.java
145153
src/main/java/org/openapijsonschematools/client/components/schemas/EmailFormat.java
146154
src/main/java/org/openapijsonschematools/client/components/schemas/EmptyDependents.java
@@ -178,6 +186,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/MinimumValida
178186
src/main/java/org/openapijsonschematools/client/components/schemas/MinitemsValidation.java
179187
src/main/java/org/openapijsonschematools/client/components/schemas/MinlengthValidation.java
180188
src/main/java/org/openapijsonschematools/client/components/schemas/MinpropertiesValidation.java
189+
src/main/java/org/openapijsonschematools/client/components/schemas/MultipleDependentsRequired.java
181190
src/main/java/org/openapijsonschematools/client/components/schemas/MultipleTypesCanBeSpecifiedInAnArray.java
182191
src/main/java/org/openapijsonschematools/client/components/schemas/NestedAllofToCheckValidationSemantics.java
183192
src/main/java/org/openapijsonschematools/client/components/schemas/NestedAnyofToCheckValidationSemantics.java
@@ -212,6 +221,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/RequiredValid
212221
src/main/java/org/openapijsonschematools/client/components/schemas/RequiredWithEmptyArray.java
213222
src/main/java/org/openapijsonschematools/client/components/schemas/RequiredWithEscapedCharacters.java
214223
src/main/java/org/openapijsonschematools/client/components/schemas/SimpleEnumValidation.java
224+
src/main/java/org/openapijsonschematools/client/components/schemas/SingleDependency.java
215225
src/main/java/org/openapijsonschematools/client/components/schemas/SmallMultipleOfLargeInteger.java
216226
src/main/java/org/openapijsonschematools/client/components/schemas/StringTypeMatchesStrings.java
217227
src/main/java/org/openapijsonschematools/client/components/schemas/TimeFormat.java
@@ -266,6 +276,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/ContainsValid
266276
src/main/java/org/openapijsonschematools/client/schemas/validation/CustomIsoparser.java
267277
src/main/java/org/openapijsonschematools/client/schemas/validation/DefaultValueMethod.java
268278
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentRequiredValidator.java
279+
src/main/java/org/openapijsonschematools/client/schemas/validation/DependentSchemasValidator.java
269280
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
270281
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
271282
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java

samples/client/3_1_0_unit_test/java/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ allowed input and output types.
184184
| [ContainsWithNullInstanceElements.ContainsWithNullInstanceElements1](docs/components/schemas/ContainsWithNullInstanceElements.md#containswithnullinstanceelements1) | |
185185
| [DateFormat.DateFormat1](docs/components/schemas/DateFormat.md#dateformat1) | |
186186
| [DateTimeFormat.DateTimeFormat1](docs/components/schemas/DateTimeFormat.md#datetimeformat1) | |
187+
| [DependentSchemasDependenciesWithEscapedCharacters.DependentSchemasDependenciesWithEscapedCharacters1](docs/components/schemas/DependentSchemasDependenciesWithEscapedCharacters.md#dependentschemasdependencieswithescapedcharacters1) | |
188+
| [DependentSchemasDependentSubschemaIncompatibleWithRoot.DependentSchemasDependentSubschemaIncompatibleWithRoot1](docs/components/schemas/DependentSchemasDependentSubschemaIncompatibleWithRoot.md#dependentschemasdependentsubschemaincompatiblewithroot1) | |
189+
| [DependentSchemasSingleDependency.DependentSchemasSingleDependency1](docs/components/schemas/DependentSchemasSingleDependency.md#dependentschemassingledependency1) | |
187190
| [DurationFormat.DurationFormat1](docs/components/schemas/DurationFormat.md#durationformat1) | |
188191
| [EmailFormat.EmailFormat1](docs/components/schemas/EmailFormat.md#emailformat1) | |
189192
| [EmptyDependents.EmptyDependents1](docs/components/schemas/EmptyDependents.md#emptydependents1) | |
@@ -221,6 +224,7 @@ allowed input and output types.
221224
| [MinitemsValidation.MinitemsValidation1](docs/components/schemas/MinitemsValidation.md#minitemsvalidation1) | |
222225
| [MinlengthValidation.MinlengthValidation1](docs/components/schemas/MinlengthValidation.md#minlengthvalidation1) | |
223226
| [MinpropertiesValidation.MinpropertiesValidation1](docs/components/schemas/MinpropertiesValidation.md#minpropertiesvalidation1) | |
227+
| [MultipleDependentsRequired.MultipleDependentsRequired1](docs/components/schemas/MultipleDependentsRequired.md#multipledependentsrequired1) | |
224228
| [MultipleTypesCanBeSpecifiedInAnArray.MultipleTypesCanBeSpecifiedInAnArray1](docs/components/schemas/MultipleTypesCanBeSpecifiedInAnArray.md#multipletypescanbespecifiedinanarray1) | |
225229
| [NestedAllofToCheckValidationSemantics.NestedAllofToCheckValidationSemantics1](docs/components/schemas/NestedAllofToCheckValidationSemantics.md#nestedalloftocheckvalidationsemantics1) | |
226230
| [NestedAnyofToCheckValidationSemantics.NestedAnyofToCheckValidationSemantics1](docs/components/schemas/NestedAnyofToCheckValidationSemantics.md#nestedanyoftocheckvalidationsemantics1) | |
@@ -255,6 +259,7 @@ allowed input and output types.
255259
| [RequiredWithEmptyArray.RequiredWithEmptyArray1](docs/components/schemas/RequiredWithEmptyArray.md#requiredwithemptyarray1) | |
256260
| [RequiredWithEscapedCharacters.RequiredWithEscapedCharacters1](docs/components/schemas/RequiredWithEscapedCharacters.md#requiredwithescapedcharacters1) | |
257261
| [SimpleEnumValidation.SimpleEnumValidation1](docs/components/schemas/SimpleEnumValidation.md#simpleenumvalidation1) | |
262+
| [SingleDependency.SingleDependency1](docs/components/schemas/SingleDependency.md#singledependency1) | |
258263
| [SmallMultipleOfLargeInteger.SmallMultipleOfLargeInteger1](docs/components/schemas/SmallMultipleOfLargeInteger.md#smallmultipleoflargeinteger1) | |
259264
| [StringTypeMatchesStrings.StringTypeMatchesStrings1](docs/components/schemas/StringTypeMatchesStrings.md#stringtypematchesstrings1) | |
260265
| [TimeFormat.TimeFormat1](docs/components/schemas/TimeFormat.md#timeformat1) | |

0 commit comments

Comments
 (0)