Class SchemaResolver

java.lang.Object
com.bonitasoft.processbuilder.validation.SchemaResolver

public final class SchemaResolver extends Object
Utility class responsible for loading, resolving, and validating JSON data against OpenAPI (Swagger) schema definitions.

This class handles file parsing, recursive reference resolution, schema extraction, and detailed logging of validation reports. It is non-instantiable.

Since:
1.0
Author:
Bonitasoft
  • Method Details

    • getValidatorSchema

      public static LoadedSchema getValidatorSchema(String resourcePath, String targetSchemaName, String jsonInput)
      Loads the OpenAPI document from a resource, resolves dependencies, and prepares the JsonSchema validator for a specific target schema.
      Parameters:
      resourcePath - The path to the OpenAPI resource (e.g., "schemas/openapi.yaml").
      targetSchemaName - The name of the schema to extract from the components section (e.g., "Category").
      jsonInput - The raw JSON input string (stored in LoadedSchema).
      Returns:
      A LoadedSchema record containing the validator, titles map, and input.
      Throws:
      RuntimeException - If reading, parsing, schema resolution, or serialization fails.
    • parseJson

      public static com.fasterxml.jackson.databind.JsonNode parseJson(String json)
      Parses a JSON string into a Jackson JsonNode.
      Parameters:
      json - The JSON string to parse.
      Returns:
      The resulting JsonNode.
      Throws:
      RuntimeException - if the JSON string is malformed.
    • isJsonValid

      public static boolean isJsonValid(LoadedSchema loadedSchema)
      Performs JSON validation against the loaded schema, logging the outcome and detailed errors.
      Parameters:
      loadedSchema - The record containing the validator, titles map, and input JSON.
      Returns:
      true if validation is successful, false otherwise.
    • printRelevantValidationErrors

      public static void printRelevantValidationErrors(com.github.fge.jsonschema.core.report.ProcessingReport report, Map<String,String> componentTitles)
      Logs the relevant validation errors (ERROR/FATAL) by descending into the 'allOf' structure.
      Parameters:
      report - The processing report containing validation errors.
      componentTitles - Map of internal pointer names to user-friendly component names.