Skip to content

Commit e78b80d

Browse files
committed
removing unused code from ObjectSchema
1 parent cafa3ae commit e78b80d

File tree

1 file changed

+0
-149
lines changed

1 file changed

+0
-149
lines changed

core/src/main/java/org/everit/json/schema/ObjectSchema.java

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.everit.json.schema;
22

3-
import static java.lang.String.format;
4-
import static java.util.Arrays.asList;
53
import static java.util.Objects.requireNonNull;
64

75
import java.util.ArrayList;
@@ -10,14 +8,12 @@
108
import java.util.HashSet;
119
import java.util.List;
1210
import java.util.Map;
13-
import java.util.Map.Entry;
1411
import java.util.Objects;
1512
import java.util.Optional;
1613
import java.util.Set;
1714
import java.util.regex.Pattern;
1815

1916
import org.everit.json.schema.internal.JSONPrinter;
20-
import org.json.JSONObject;
2117

2218
/**
2319
* Object schema validator.
@@ -202,21 +198,6 @@ public ObjectSchema(Builder builder) {
202198
this.propertyNameSchema = builder.propertyNameSchema;
203199
}
204200

205-
private List<String> getAdditionalProperties(JSONObject subject) {
206-
String[] names = JSONObject.getNames(subject);
207-
if (names == null) {
208-
return new ArrayList<>();
209-
} else {
210-
List<String> namesList = new ArrayList<>();
211-
for (String name : names) {
212-
if (!propertySchemas.containsKey(name) && !matchesAnyPattern(name)) {
213-
namesList.add(name);
214-
}
215-
}
216-
return namesList;
217-
}
218-
}
219-
220201
public Integer getMaxProperties() {
221202
return maxProperties;
222203
}
@@ -283,136 +264,6 @@ public boolean requiresObject() {
283264
return requiresObject;
284265
}
285266

286-
private void testAdditionalProperties(JSONObject subject, List<ValidationException> validationExceptions) {
287-
if (!additionalProperties) {
288-
List<String> additionalProperties = getAdditionalProperties(subject);
289-
if (null == additionalProperties || additionalProperties.isEmpty()) {
290-
return;
291-
}
292-
for (String additionalProperty : additionalProperties) {
293-
validationExceptions.add(new ValidationException(this,
294-
format("extraneous key [%s] is not permitted", additionalProperty), "additionalProperties"));
295-
}
296-
} else if (schemaOfAdditionalProperties != null) {
297-
List<String> additionalPropNames = getAdditionalProperties(subject);
298-
for (String propName : additionalPropNames) {
299-
Object propVal = subject.get(propName);
300-
Optional<ValidationException> exception = ifFails(schemaOfAdditionalProperties, propVal);
301-
if (exception.isPresent()) {
302-
validationExceptions.add(exception.get().prepend(propName, this));
303-
}
304-
}
305-
}
306-
}
307-
308-
private void testPatternProperties(JSONObject subject, List<ValidationException> validationExceptions) {
309-
String[] propNames = JSONObject.getNames(subject);
310-
if (propNames == null || propNames.length == 0) {
311-
return;
312-
}
313-
for (Entry<Pattern, Schema> entry : patternProperties.entrySet()) {
314-
for (String propName : propNames) {
315-
if (entry.getKey().matcher(propName).find()) {
316-
Optional<ValidationException> exception = ifFails(entry.getValue(), subject.get(propName));
317-
if (exception.isPresent()) {
318-
validationExceptions.add(exception.get().prepend(propName));
319-
}
320-
}
321-
}
322-
}
323-
}
324-
325-
private void testProperties(JSONObject subject, List<ValidationException> validationExceptions) {
326-
if (propertySchemas != null) {
327-
for (Entry<String, Schema> entry : propertySchemas.entrySet()) {
328-
String key = entry.getKey();
329-
if (subject.has(key)) {
330-
Optional<ValidationException> exception = ifFails(entry.getValue(), subject.get(key));
331-
if (exception.isPresent()) {
332-
validationExceptions.add(exception.get().prepend(key));
333-
}
334-
} else if (entry.getValue().hasDefaultValue()) {
335-
subject.put(key, entry.getValue().getDefaultValue());
336-
}
337-
}
338-
}
339-
}
340-
341-
private void testPropertyDependencies(JSONObject subject, List<ValidationException> validationExceptions) {
342-
for (String property : propertyDependencies.keySet()) {
343-
if (subject.has(property)) {
344-
for (String mustBePresent : propertyDependencies.get(property)) {
345-
if (!subject.has(mustBePresent)) {
346-
validationExceptions.add(
347-
failure(format("property [%s] is required", mustBePresent), "dependencies"));
348-
}
349-
}
350-
}
351-
}
352-
}
353-
354-
private void testSchemaDependencies(JSONObject subject, List<ValidationException> validationExceptions) {
355-
for (Map.Entry<String, Schema> schemaDep : schemaDependencies.entrySet()) {
356-
String propName = schemaDep.getKey();
357-
if (subject.has(propName)) {
358-
ifFails(schemaDep.getValue(), subject).ifPresent(validationExceptions::add);
359-
}
360-
}
361-
}
362-
363-
private void testSize(JSONObject subject, List<ValidationException> validationExceptions) {
364-
int actualSize = subject.length();
365-
if (minProperties != null && actualSize < minProperties.intValue()) {
366-
validationExceptions.addAll(
367-
asList(failure(format("minimum size: [%d], found: [%d]", minProperties, actualSize),
368-
"minProperties")));
369-
return;
370-
}
371-
if (maxProperties != null && actualSize > maxProperties.intValue()) {
372-
validationExceptions.addAll(
373-
asList(failure(format("maximum size: [%d], found: [%d]", maxProperties, actualSize),
374-
"maxProperties")));
375-
}
376-
}
377-
378-
@Override
379-
public void validate(Object subject) {
380-
super.validate(subject);
381-
// if (!(subject instanceof JSONObject)) {
382-
// if (requiresObject) {
383-
// throw failure(JSONObject.class, subject);
384-
// }
385-
// } else {
386-
// List<ValidationException> validationExceptions = new ArrayList<>();
387-
// JSONObject objSubject = (JSONObject) subject;
388-
// testRequiredProperties(objSubject, validationExceptions);
389-
// testProperties(objSubject, validationExceptions); // Test after requiredProperties because default values add properties
390-
// testAdditionalProperties(objSubject, validationExceptions);
391-
// testSize(objSubject, validationExceptions);
392-
// testPropertyDependencies(objSubject, validationExceptions);
393-
// testSchemaDependencies(objSubject, validationExceptions);
394-
// testPatternProperties(objSubject, validationExceptions);
395-
// testPropertyNames(objSubject, validationExceptions);
396-
// ValidationException.throwFor(this, validationExceptions);
397-
// }
398-
}
399-
400-
private void testPropertyNames(JSONObject subject, List<ValidationException> validationExceptions) {
401-
if (propertyNameSchema != null) {
402-
String[] names = JSONObject.getNames(subject);
403-
if (names == null || names.length == 0) {
404-
return;
405-
}
406-
for (String name : names) {
407-
try {
408-
propertyNameSchema.validate(name);
409-
} catch (ValidationException e) {
410-
validationExceptions.add(e.prepend(name));
411-
}
412-
}
413-
}
414-
}
415-
416267
@Override
417268
public boolean definesProperty(String field) {
418269
field = field.replaceFirst("^#", "").replaceFirst("^/", "");

0 commit comments

Comments
 (0)