From 901e2e9db621af21744b722007f25e1977eab166 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 18 Dec 2023 16:08:54 -0800 Subject: [PATCH] Trims more away --- .../client/schemas/validation/JsonSchema.java | 44 --------------- .../schemas/validation/KeywordEntry.java | 9 --- .../schemas/validation/KeywordValidator.java | 12 ---- .../schemas/validation/TypeValidator.java | 38 ------------- .../schemas/validation/JsonSchemaTest.java | 55 ------------------- 5 files changed, 158 deletions(-) delete mode 100644 samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordEntry.java delete mode 100644 samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordValidator.java delete mode 100644 samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java delete mode 100644 samples/client/3_0_3_unit_test/java_simplified/src/test/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaTest.java diff --git a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java b/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java index cf9724f5daa9..a4455ac38e27 100644 --- a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java +++ b/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java @@ -19,53 +19,9 @@ public abstract class JsonSchema { public final @Nullable Set> type; - private final @NonNull LinkedHashMap keywordToValidator; protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) { - LinkedHashMap keywordToValidator = new LinkedHashMap<>(); this.type = jsonSchemaInfo.type; - if (this.type != null) { - keywordToValidator.put( - "type", - new TypeValidator(this.type) - ); - } - this.keywordToValidator = keywordToValidator; - } - - public static PathToSchemasMap validate( - JsonSchema jsonSchema, - Object arg, - ValidationMetadata validationMetadata - ) throws ValidationException { - LinkedHashSet disabledKeywords = validationMetadata.configuration().disabledKeywordFlags().getKeywords(); - PathToSchemasMap pathToSchemas = new PathToSchemasMap(); - LinkedHashMap thisKeywordToValidator = jsonSchema.keywordToValidator; - if (thisKeywordToValidator != null) { - for (Map.Entry entry: thisKeywordToValidator.entrySet()) { - String jsonKeyword = entry.getKey(); - if (disabledKeywords.contains(jsonKeyword)) { - continue; - } - KeywordValidator validator = entry.getValue(); - PathToSchemasMap otherPathToSchemas = validator.validate( - jsonSchema, - arg, - validationMetadata - ); - if (otherPathToSchemas == null) { - continue; - } - pathToSchemas.update(otherPathToSchemas); - } - } - List pathToItem = validationMetadata.pathToItem(); - if (!pathToSchemas.containsKey(pathToItem)) { - pathToSchemas.put(validationMetadata.pathToItem(), new LinkedHashMap<>()); - } - pathToSchemas.get(pathToItem).put(jsonSchema, null); - - return pathToSchemas; } public static class PathToSchemasMap extends LinkedHashMap, LinkedHashMap> { diff --git a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordEntry.java b/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordEntry.java deleted file mode 100644 index 647b930ba4cf..000000000000 --- a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordEntry.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.openapijsonschematools.client.schemas.validation; - -import java.util.AbstractMap; - -public class KeywordEntry extends AbstractMap.SimpleEntry { - public KeywordEntry(String key, KeywordValidator value) { - super(key, value); - } -} diff --git a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordValidator.java b/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordValidator.java deleted file mode 100644 index 9cfd789e1e76..000000000000 --- a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/KeywordValidator.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.openapijsonschematools.client.schemas.validation; - -import org.openapijsonschematools.client.exceptions.ValidationException; - -public interface KeywordValidator { - JsonSchema.PathToSchemasMap validate( - JsonSchema schema, - Object arg, - ValidationMetadata validationMetadata) throws ValidationException; - - Object getConstraint(); -} \ No newline at end of file diff --git a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java b/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java deleted file mode 100644 index 8f7b36972ab7..000000000000 --- a/samples/client/3_0_3_unit_test/java_simplified/src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.openapijsonschematools.client.schemas.validation; - -import org.openapijsonschematools.client.exceptions.ValidationException; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class TypeValidator implements KeywordValidator { - public final Set> type; - - public TypeValidator(Set> type) { - this.type = type; - } - - @Override - public Object getConstraint() { - return type; - } - - @Override - public JsonSchema.PathToSchemasMap validate(JsonSchema schema, Object arg, ValidationMetadata validationMetadata) { - Class argClass; - if (arg == null) { - argClass = Void.class; - } else if (arg instanceof List) { - argClass = List.class; - } else if (arg instanceof Map) { - argClass = Map.class; - } else { - argClass = arg.getClass(); - } - if (!type.contains(argClass)) { - throw new ValidationException("invalid type"); - } - return null; - } -} diff --git a/samples/client/3_0_3_unit_test/java_simplified/src/test/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaTest.java b/samples/client/3_0_3_unit_test/java_simplified/src/test/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaTest.java deleted file mode 100644 index 452ef8f0b804..000000000000 --- a/samples/client/3_0_3_unit_test/java_simplified/src/test/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.openapijsonschematools.client.schemas.validation; - -import org.junit.Assert; -import org.junit.Test; -import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; -import org.openapijsonschematools.client.configurations.SchemaConfiguration; -import org.openapijsonschematools.client.exceptions.InvalidTypeException; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -class SomeSchema extends JsonSchema { - private static SomeSchema instance; - protected SomeSchema() { - super(new JsonSchemaInfo() - .type(Set.of(String.class)) - ); - } - - public static SomeSchema getInstance() { - if (instance == null) { - instance = new SomeSchema(); - } - return instance; - } -} - -public class JsonSchemaTest { - - @Test - public void testValidateSucceeds() { - List pathToItem = new ArrayList<>(); - pathToItem.add("args[0"); - ValidationMetadata validationMetadata = new ValidationMetadata( - pathToItem, - new SchemaConfiguration(JsonSchemaKeywordFlags.ofNone()), - new JsonSchema.PathToSchemasMap(), - new LinkedHashSet<>() - ); - SomeSchema schema = JsonSchemaFactory.getInstance(SomeSchema.class); - JsonSchema.PathToSchemasMap pathToSchemas = JsonSchema.validate( - schema, - "hi", - validationMetadata - ); - JsonSchema.PathToSchemasMap expectedPathToSchemas = new JsonSchema.PathToSchemasMap(); - LinkedHashMap validatedClasses = new LinkedHashMap<>(); - validatedClasses.put(schema, null); - expectedPathToSchemas.put(pathToItem, validatedClasses); - Assert.assertEquals(pathToSchemas, expectedPathToSchemas); - } -} \ No newline at end of file