<commit_before><?php
namespace WoohooLabs\YinMiddlewares\Utils;

use JsonSchema\RefResolver;
use JsonSchema\Uri\UriRetriever;
use JsonSchema\Validator;
use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;

class JsonApiChecker
{
    /**
     * @param string $message
     * @return string
     */
    public function lint($message)
    {
        try {
            $linter = new JsonParser();
            $linter->lint($message);
        } catch (ParsingException $e) {
            return $e->getMessage();
        }

        return "";
    }

    /**
     * @param object $message
     * @return array
     */
    public function validate($message)
    {
        $jsonApiSchemaPath = realpath(__DIR__ . "/../../data/json-api-schema.json");

        $retriever = new UriRetriever();
        $schema = $retriever->retrieve('file://' . $jsonApiSchemaPath);

        $refResolver = new RefResolver($retriever);
        $refResolver->resolve($schema, 'file://' . dirname($jsonApiSchemaPath) . "/json-api-schema-ref.json");

        $validator = new Validator();
        $validator->check($message, $schema);

        return $validator->getErrors();
    }
}<commit_msg>Fixed max depth reached issue<commit_after><?php
namespace WoohooLabs\YinMiddlewares\Utils;

use JsonSchema\RefResolver;
use JsonSchema\Uri\UriRetriever;
use JsonSchema\Validator;
use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;

class JsonApiChecker
{
    /**
     * @param string $message
     * @return string
     */
    public function lint($message)
    {
        try {
            $linter = new JsonParser();
            $linter->lint($message);
        } catch (ParsingException $e) {
            return $e->getMessage();
        }

        return "";
    }

    /**
     * @param object $message
     * @return array
     */
    public function validate($message)
    {
        $jsonApiSchemaPath = realpath(__DIR__ . "/../../data/json-api-schema.json");

        $retriever = new UriRetriever();
        $schema = $retriever->retrieve('file://' . $jsonApiSchemaPath);

        RefResolver::$maxDepth = 100;
        $refResolver = new RefResolver($retriever);
        $refResolver->resolve($schema, 'file://' . dirname($jsonApiSchemaPath) . "/json-api-schema-ref.json");

        $validator = new Validator();
        $validator->check($message, $schema);

        return $validator->getErrors();
    }
}
{'fraction_non_alphanumeric': 0.14422277639235245, 'fraction_numerical': 0.0012468827930174563, 'mean_word_length': 2.468299711815562, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1335045', 'n_tokens_mistral': 732, 'n_tokens_neox': 724, 'n_words': 136}