validateSpecifications

The validateSpecifications method checks if a validation specification is well formatted. It does not store nor modify the existing specification.

When the validation specification is not formatted correctly, a detailed error message is returned to help you to debug.

Signature

Copied to clipboard!
kuzzleio::validation_response* validateSpecifications(
    const std::string& index,
    const std::string& collection,
    const std::string& specifications);

kuzzleio::validation_response* validateSpecifications(
    const std::string& index,
    const std::string& collection,
    const std::string& specifications,
    const kuzzleio::query_options& options);

Arguments

Arguments Type Description
index const std::string& Index name
collection const std::string& Collection name
specifications const std::string& JSON string representating the specifications to validate
options kuzzleio::query_options\* Query options

specifications

A JSON string representing the specifications the specifications.

The JSON must follow the Specification Structure:

Copied to clipboard!
{
  "strict": "true",
  "fields": {
    "licence": {
      "mandatory": true,
      "type": "string"
    }
    // ... specification for each field
  }
}

options

Additional query options

Property Type
(default)
Description
queuable bool(true) If true, queues the request during downtime, until connected to Kuzzle again

Return

A kuzzleio::validation_response object which contain information about the specifications validity.

Property Type Description
valid bool Specification validity
details const char \* const \* Array of string with details about each specification errors
description const char \* General error message

Usage

Copied to clipboard!
try {
  std::string specifications = R"({
    "strict": false,
    "fields": {
      "license": {
        "mandatory": true,
        "type": "string"
      }
    }
  })";

  kuzzleio::validation_response *validation_response =
    kuzzle->collection->validateSpecifications(
      "nyc-open-data",
      "yellow-taxi",
      specifications);

  if (validation_response->valid) {
    std::cout << "Specifications are valid" << std::endl;
  }
} catch (kuzzleio::KuzzleException &e) {
  std::cerr << e.what() << std::endl;
}