Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to networknt json schema validator implementation #3212

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,130 +3,6 @@
"name": "com.github.benmanes.caffeine.cache.SSSMSW",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jackson.jsonpointer.JsonPointerMessages",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.core.messages.JsonSchemaCoreMessageBundle",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.core.messages.JsonSchemaSyntaxMessageBundle",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.AdditionalItemsValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.AdditionalPropertiesValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.DependenciesValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.EnumValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.MaxItemsValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.MaxLengthValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.MaximumValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.MinItemsValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.MinLengthValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.MinimumValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.PatternValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.common.UniqueItemsValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv3.DisallowKeywordValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv3.DivisibleByValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv3.DraftV3TypeValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv3.ExtendsValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv3.PropertiesValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.AllOfValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.AnyOfValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.DraftV4TypeValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.MaxPropertiesValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.MinPropertiesValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.MultipleOfValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.NotValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.OneOfValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.keyword.validator.draftv4.RequiredKeywordValidator",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.messages.JsonSchemaConfigurationBundle",
"allDeclaredConstructors": true
},
{
"name": "com.github.fge.jsonschema.messages.JsonSchemaValidationBundle",
"allDeclaredConstructors": true
},
{
"name": "com.yahoo.elide.core.security.checks.prefab.Collections$AppendOnly",
"allDeclaredMethods": true,
Expand Down
2 changes: 1 addition & 1 deletion elide-model-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</dependency>

<dependency>
<groupId>com.github.java-json-tools</groupId>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
</dependency>
<dependency>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;

import org.apache.commons.lang3.StringUtils;
import org.hjson.JsonValue;
import org.hjson.ParseException;
Expand Down Expand Up @@ -58,9 +59,9 @@ public static Map<String, Object> stringToVariablesPojo(String fileName, String
if (schemaValidator.verifySchema(Config.MODELVARIABLE, jsonConfig, fileName)) {
variables = getModelPojo(jsonConfig, Map.class);
}
} catch (ProcessingException e) {
} catch (IOException e) {
log.error("Error Validating Variable config : " + e.getMessage());
throw new IOException(e);
throw e;
}
return variables;
}
Expand All @@ -81,9 +82,9 @@ public static ElideTableConfig stringToElideTablePojo(String fileName, String co
if (schemaValidator.verifySchema(Config.TABLE, jsonConfig, fileName)) {
table = getModelPojo(jsonConfig, ElideTableConfig.class);
}
} catch (ProcessingException e) {
} catch (IOException e) {
log.error("Error Validating Table config : " + e.getMessage());
throw new IOException(e);
throw e;
}
return table;
}
Expand All @@ -104,9 +105,9 @@ public static ElideDBConfig stringToElideDBConfigPojo(String fileName, String co
if (schemaValidator.verifySchema(Config.SQLDBConfig, jsonConfig, fileName)) {
dbconfig = getModelPojo(jsonConfig, ElideDBConfig.class);
}
} catch (ProcessingException e) {
} catch (IOException e) {
log.error("Error Validating DB config : " + e.getMessage());
throw new IOException(e);
throw e;
}
return dbconfig;
}
Expand All @@ -127,9 +128,9 @@ public static ElideNamespaceConfig stringToElideNamespaceConfigPojo(String fileN
if (schemaValidator.verifySchema(Config.NAMESPACEConfig, jsonConfig, fileName)) {
namespaceconfig = getModelPojo(jsonConfig, ElideNamespaceConfig.class);
}
} catch (ProcessingException e) {
} catch (IOException e) {
log.error("Error Validating DB config : " + e.getMessage());
throw new IOException(e);
throw e;
}
return namespaceconfig;
}
Expand All @@ -149,9 +150,9 @@ public static ElideSecurityConfig stringToElideSecurityPojo(String fileName, Str
if (schemaValidator.verifySchema(Config.SECURITY, jsonConfig, fileName)) {
return getModelPojo(jsonConfig, ElideSecurityConfig.class);
}
} catch (ProcessingException e) {
} catch (IOException e) {
log.error("Error Validating Security config : " + e.getMessage());
throw new IOException(e);
throw e;
}
return null;
}
Expand All @@ -176,9 +177,19 @@ private static String hjsonToJson(String hjson) {
}
}

private static class DynamicConfigObjectMapper {
private static final ObjectMapper INSTANCE;

static {
INSTANCE = JsonMapper.builder().enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS).build();
}

private static ObjectMapper getInstance() {
return INSTANCE;
}
}

private static <T> T getModelPojo(String jsonConfig, final Class<T> configPojo) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
return objectMapper.readValue(jsonConfig, configPojo);
return DynamicConfigObjectMapper.getInstance().readValue(jsonConfig, configPojo);
}
}
Loading