Skip to content

Commit

Permalink
renamed JsonValidator into JsonSchemaValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Oct 28, 2024
1 parent c237a87 commit 0f97a21
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int main(int argc, char** argv) {
configStr = config.dump();

// validate the configuration file against the schema
mofka::JsonValidator validator{configSchema};
mofka::JsonSchemaValidator validator{configSchema};
auto errors = validator.validate(config);
if(!errors.empty()) {
std::cerr << "Invalid configuration: ";
Expand Down
2 changes: 1 addition & 1 deletion src/DefaultPartitionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ std::unique_ptr<mofka::PartitionManager> DefaultPartitionManager::create(
)"_json;

/* Validate configuration against schema */
static JsonValidator schemaValidator{configSchema};
static JsonSchemaValidator schemaValidator{configSchema};
auto validationErrors = schemaValidator.validate(config.json());
if(!validationErrors.empty()) {
spdlog::error("[mofka] Error(s) while validating JSON config for DefaultPartitionManager:");
Expand Down
3 changes: 1 addition & 2 deletions src/DefaultValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class DefaultValidator : public ValidatorInterface {
public:

void validate(const Metadata& metadata, const Data& data) const override {
(void)metadata;
(void)data;
if(!metadata.isValidJson())
throw InvalidMetadata("Metadata object does not contain valid JSON metadata");
}

Metadata metadata() const override {
Expand Down
8 changes: 4 additions & 4 deletions src/JsonUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ static inline bool ValidateIsJson(std::string_view json) {
return brackets.empty();
}

struct JsonValidator {
struct JsonSchemaValidator {

using ErrorList = std::vector<std::string>;

nlohmann::json_schema::json_validator m_validator;

JsonValidator(const nlohmann::json& schema) {
JsonSchemaValidator(const nlohmann::json& schema) {
m_validator.set_root_schema(schema);
}

JsonValidator(nlohmann::json&& schema) {
JsonSchemaValidator(nlohmann::json&& schema) {
m_validator.set_root_schema(std::move(schema));
}

JsonValidator(const char* schema) {
JsonSchemaValidator(const char* schema) {
m_validator.set_root_schema(nlohmann::json::parse(schema));
}

Expand Down
2 changes: 1 addition & 1 deletion src/ProviderImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ProviderImpl : public tl::provider<ProviderImpl> {
"required": ["uuid", "type", "topic"]
}
)"_json;
static JsonValidator jsonValidator{configSchema};
static JsonSchemaValidator jsonValidator{configSchema};

/* Validate configuration against schema */
auto errors = jsonValidator.validate(config.json());
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SchemaSerializer : public SerializerInterface {
if(!metadata.json().contains("schema"))
throw Exception{"SchemaSerializer is expecting a \"schema\" entry in its configuration"};
// check that the schema field indeed is a schema
JsonValidator{metadata.json()["schema"]};
JsonSchemaValidator{metadata.json()["schema"]};
// build the schema serializer and deserialize
auto serializer = makeSerializer(metadata.json()["schema"]);
auto deserializer = makeDeserializer(metadata.json()["schema"]);
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class SchemaValidator : public ValidatorInterface {

using json = nlohmann::json;

json m_json_schema;
JsonValidator m_json_validator;
json m_json_schema;
JsonSchemaValidator m_json_validator;

public:

Expand Down

0 comments on commit 0f97a21

Please sign in to comment.