1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Server\Validation;
15:
16: use Nexus\Assert\Assert;
17:
18: /**
19: * One JSON Schema violation, located by an RFC 6901 pointer into the validated data.
20: *
21: * @see https://www.rfc-editor.org/rfc/rfc6901
22: */
23: final readonly class SchemaViolation
24: {
25: /**
26: * @param string $pointer JSON pointer to the offending value
27: * @param non-empty-string $message
28: */
29: public function __construct(
30: public string $pointer,
31: public string $message,
32: ) {
33: Assert::that($pointer)->matchesRegularExpression(
34: '#\A(?:/(?:[^/~]|~[01])*)*\z#',
35: 'Schema violation pointer must be an RFC 6901 JSON pointer, {value} given.',
36: );
37: Assert::that($message)->isNonEmptyString('Schema violation message must be a non-empty string, {type} given.');
38: }
39:
40: /**
41: * @return array{pointer: string, message: non-empty-string}
42: */
43: public function toArray(): array
44: {
45: return ['pointer' => $this->pointer, 'message' => $this->message];
46: }
47: }
48: