@@ -125,43 +125,40 @@ public abstract class JsonSchema <MapInValueType, MapOutValueType, MapOutType, L
125
125
126
126
private PathToSchemasMap getPathToSchemas(Object arg, ValidationMetadata validationMetadata, Set<List <Object>> pathSet) {
127
127
PathToSchemasMap pathToSchemasMap = new PathToSchemasMap();
128
- if (validationMetadata.validationRanEarlier(this)) {
129
- // todo add deeper validated schemas
130
- } else {
131
- PathToSchemasMap otherPathToSchemas = validate(arg, validationMetadata);
132
- pathToSchemasMap.update(otherPathToSchemas);
133
- for (var schemas: pathToSchemasMap.values()) {
134
- JsonSchema< ?, ?, ?, ?, ?, ?> firstSchema = schemas.entrySet().iterator().next().getKey();
135
- schemas.clear();
136
- schemas.put(firstSchema, null);
137
- }
138
- pathSet.removeAll(pathToSchemasMap.keySet());
139
- if (!pathSet.isEmpty()) {
140
- LinkedHashMap<JsonSchema <?, ?, ?, ?, ?, ?>, Void> unsetAnyTypeSchema = new LinkedHashMap<> ();
141
- unsetAnyTypeSchema.put(JsonSchemaFactory.getInstance(UnsetAnyTypeJsonSchema.class), null);
142
- for (List<Object > pathToItem: pathSet) {
143
- pathToSchemasMap.put(pathToItem, unsetAnyTypeSchema);
144
- }
128
+ // todo add check of validationMetadata.validationRanEarlier(this)
129
+ PathToSchemasMap otherPathToSchemas = validate(arg, validationMetadata);
130
+ pathToSchemasMap.update(otherPathToSchemas);
131
+ for (var schemas: pathToSchemasMap.values()) {
132
+ JsonSchema< ?, ?, ?, ?, ?, ?> firstSchema = schemas.entrySet().iterator().next().getKey();
133
+ schemas.clear();
134
+ schemas.put(firstSchema, null);
135
+ }
136
+ pathSet.removeAll(pathToSchemasMap.keySet());
137
+ if (!pathSet.isEmpty()) {
138
+ LinkedHashMap<JsonSchema <?, ?, ?, ?, ?, ?>, Void> unsetAnyTypeSchema = new LinkedHashMap<> ();
139
+ unsetAnyTypeSchema.put(JsonSchemaFactory.getInstance(UnsetAnyTypeJsonSchema.class), null);
140
+ for (List<Object > pathToItem: pathSet) {
141
+ pathToSchemasMap.put(pathToItem, unsetAnyTypeSchema);
145
142
}
146
143
}
147
144
return pathToSchemasMap;
148
145
}
149
146
150
- private FrozenMap<String , MapOutValueType> getProperties(Map<String , MapInValueType > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
147
+ private FrozenMap<String , MapOutValueType> getProperties(Map< ?, ? > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
151
148
LinkedHashMap<String , MapOutValueType> properties = new LinkedHashMap<> ();
152
- for(Map.Entry<String , MapInValueType > entry: arg.entrySet()) {
153
- String propertyName = entry.getKey();
149
+ for(Map.Entry< ?, ? > entry: arg.entrySet()) {
150
+ String propertyName = (String) entry.getKey();
154
151
List<Object > propertyPathToItem = new ArrayList<> (pathToItem);
155
152
propertyPathToItem.add(propertyName);
156
- MapInValueType value = entry.getValue();
157
- JsonSchema< ?, ?, MapOutValueType , ?, ?, ?> propertySchema = (JsonSchema < ?, ?, MapOutValueType, ?, ?, ?>) pathToSchemas.get(propertyPathToItem).entrySet().iterator().next().getKey();
153
+ MapInValueType value = (MapInValueType) entry.getValue();
154
+ JsonSchema< ?, ?, ? , ?, ?, ?> propertySchema = pathToSchemas.get(propertyPathToItem).entrySet().iterator().next().getKey();
158
155
MapOutValueType castValue = (MapOutValueType) propertySchema.getNewInstance(value, propertyPathToItem, pathToSchemas);
159
156
properties.put(propertyName, castValue);
160
157
}
161
158
return new FrozenMap<> (properties);
162
159
}
163
160
164
- private FrozenList<ListOutItemType > getItems(List<ListInItemType > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
161
+ private FrozenList<ListOutItemType > getItems(List< ? > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
165
162
ArrayList<ListOutItemType > items = new ArrayList<> ();
166
163
int i = 0;
167
164
for (Object item: arg) {
@@ -183,21 +180,21 @@ public abstract class JsonSchema <MapInValueType, MapOutValueType, MapOutType, L
183
180
return (ListOutType) arg;
184
181
}
185
182
186
- private MapOutType getNewInstance(Map<String , MapInValueType > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
183
+ private MapOutType getNewInstance(Map< ?, ? > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
187
184
FrozenMap<String , MapOutValueType> usedArg = getProperties(arg, pathToItem, pathToSchemas);
188
185
return getMapOutputInstance(usedArg);
189
186
}
190
187
191
- private ListOutType getNewInstance(List<ListInItemType > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
188
+ private ListOutType getNewInstance(List< ? > arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
192
189
FrozenList<ListOutItemType > usedArg = getItems(arg, pathToItem, pathToSchemas);
193
190
return getListOutputInstance(usedArg);
194
191
}
195
192
196
193
private Object getNewInstance(Object arg, List<Object > pathToItem, PathToSchemasMap pathToSchemas) {
197
194
if (arg instanceof List) {
198
- return getNewInstance((List<ListInItemType >) arg, pathToItem, pathToSchemas);
195
+ return getNewInstance((List< ? >) arg, pathToItem, pathToSchemas);
199
196
} else if (arg instanceof Map) {
200
- return getNewInstance((Map<String , MapInValueType >) arg, pathToItem, pathToSchemas);
197
+ return getNewInstance((Map< ?, ? >) arg, pathToItem, pathToSchemas);
201
198
}
202
199
// str, int, float, boolean, null, FileIO, bytes
203
200
return arg;
@@ -254,9 +251,7 @@ public abstract class JsonSchema <MapInValueType, MapOutValueType, MapOutType, L
254
251
// todo add bytes and FileIO
255
252
256
253
public Object validate(Object arg, SchemaConfiguration configuration) throws ValidationException {
257
- if (arg instanceof Map || arg instanceof List) {
258
- // todo don't run validation if the instance is one of the class generic types
259
- }
254
+ // todo don't run validation if the instance is one of the class generic types
260
255
Set<List <Object>> pathSet = new HashSet<> ();
261
256
List<Object > pathToItem = new ArrayList<> ();
262
257
pathToItem.add("args[0]");
0 commit comments