diff --git a/CHANGELOG.md b/CHANGELOG.md index b0c33c0e..c087c499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,57 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.0] + +### Removed + +- `Schema\Model\Schema::withOverrides()` is removed. Build a schema from + constraint groups with `Schema::fromConstraintGroups()` (static factory) and + apply partial updates with `Schema::withOverrideGroups()`, which takes the + four group DTOs `Schema\Model\Internal\ScalarFields`, + `ArrayFields`, `ObjectFields` and `CompositionFields` and replaces only the + fields that are non-null in the supplied groups (`nullable` is a separate + parameter, so it can be flipped back to `false`). The `Schema` constructor + is no longer deprecated: instantiating the model directly with named + arguments is the canonical API. +- `Validator\Error\ValidationContext::create()` and the public + `ValidationContext` constructor are removed. Create contexts exclusively + through the named constructor + `ValidationContext::fromInit(Validator\Error\Internal\ValidationContextInit)`; + the DTO carries `pool`, `errorFormatter`, `nullableAsType`, + `emptyArrayStrategy` and `mode`, and the context always owns a fresh + `BreadcrumbManager`, so per-request isolation is guaranteed by construction. + Branch contexts keep using `forkForBranch()`. +- The public `Validator\Validation\ValidationStack` constructor is removed. + Build a stack through `ValidationStack::fromGroup()` with a + `Validator\Validation\Internal\ValidationGroup` (`root`: `RootServices` + DTO, `options`: `ValidatorOptions` DTO, optional `bodyLimits`). +- `Validator\Exception\ValidationErrorInterface::getType()` and all of its + implementations are removed. Use `keyword()`, which returns the same + validation keyword (`'type'`, `'minLength'`, `'format'`, ...). +- `Builder\OpenApiValidatorInterface::getFormattedErrors()` is removed. + Format a `ValidationException` through + `Validator\Error\Formatter\ErrorFormatterInterface::formatException()`. + The output is byte-identical to the removed method when the validator was + built with the default formatter; otherwise call the configured formatter's + `formatException()` directly. +- `Builder\OpenApiValidatorBuilder::enableStrictCallbackRuntimeTemplate()` is + removed. Strict callback runtime template resolution is the default; use + `disableStrictCallbackRuntimeTemplate()` to opt out (see the security + warning in the README). +- `Validator\Exception\InvalidMultipleOfSchemaException::forLargeIntegerWithoutBcmath()` + is removed. `multipleOf` checks fall back to pure-PHP decimal string + modulus when the BCMath extension is unavailable, so the exception is never + thrown; `forNonPositiveValue()` remains. + +### Changed + +- `Validator\Error\ValidationContext` and `Validator\Validation\ValidationStack` + are now named-constructor-only services: their constructors are private and + the only creation entry points are `ValidationContext::fromInit()` and + `ValidationStack::fromGroup()`. Schema model classes keep public + constructors. + ## [0.8.0] ### Added diff --git a/README.md b/README.md index db79ca83..adf22ed7 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,6 @@ The interface exposes the following methods: | `validateRequest(ServerRequestInterface $request): Operation` | Validate and return matched operation | | `validateResponse(ResponseInterface $response, Operation $operation): void` | Validate response against operation | | `validateSchema(mixed $data, string $schemaRef): void` | Validate data against a schema reference | -| `getFormattedErrors(ValidationException $e): string` | Format validation errors as string (**deprecated** in favor of `ErrorFormatterInterface::formatException()`, removed in 2.0) | | `validateWebhook(ServerRequestInterface $request, string $name): Operation` | Validate webhook request | | `validateCallback(ServerRequestInterface $request, string $name): Operation` | Validate callback request | | `getDocument(): OpenApiDocument` | Returns the loaded OpenAPI document for introspection or routing maps (available after `build()`) | @@ -242,8 +241,6 @@ $validator = OpenApiValidatorBuilder::create() > **SECURITY WARNING**: `disableStrictCallbackRuntimeTemplate()` disables the protection against SSRF via attacker-controlled callback URLs: declared security checks still pass against an arbitrary URL when the runtime template is unresolvable. Use it only when callback URLs are validated at the application level (an allowlist of permitted outbound hosts, signed callback URLs, or destination validation before any outbound request is issued). -The previous opt-in method `enableStrictCallbackRuntimeTemplate()` is retained as a deprecated no-op for backward compatibility: strict behaviour is now the default. The method will be removed in 2.0. - ### Link Resolution Resolve OpenAPI Link parameters from response data. Both methods return a `ResolvedLink` DTO exposing resolved `parameters`, `requestBody`, and the optional `server` override declared by the link. @@ -521,7 +518,6 @@ $validator = OpenApiValidatorBuilder::create() | `enableStrictFormats()` | Reject unknown format values instead of skipping | `false` | | `enableReportDeprecated()` | Log deprecated schema elements via PSR-3 logger | `true` | | `enableServerPathResolution()` | Strip server base path from request path before matching | `false` | -| `enableStrictCallbackRuntimeTemplate()` | Deprecated no-op: strict mode is now the default. Will be removed in 2.0 | `true` (effective) | | `disableStrictCallbackRuntimeTemplate()` | Opt out of strict callback runtime template resolution. **SECURITY WARNING**: unresolvable callback expressions like `{$request.body#/callback_url}` are treated as wildcards that accept any URL, enabling SSRF via attacker-controlled callback URLs. Use only when callback URLs are validated at the application level. | `false` (opt-in legacy mode) | | `withExternalRefAllowedRoot(string $path)` | Directory that external `file://` `$ref` references must stay inside | `null` (auto-derived from spec path for file-loaded specs) | | `withExternalRefMaxBytes(int $bytes)` | Set max external ref file size | `10485760` (10 MB) | @@ -714,6 +710,7 @@ All regular expressions in schemas are validated at parse time; an invalid patte All validation errors throw `ValidationException` which contains detailed error information: ```php +use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Exception\ValidationException; try { @@ -731,8 +728,8 @@ try { ); } - // Get formatted errors - $formatted = $validator->getFormattedErrors($e); + // Format errors via a formatter + $formatted = (new SimpleFormatter())->formatException($e); echo $formatted; } ``` @@ -764,8 +761,6 @@ Error formatters omit raw values unless constructed with `includeSensitiveValues All errors implement `ValidationErrorInterface` and provide `dataPath()`, `schemaPath()`, `keyword()`, `message()`, `params()`, and `suggestion()` methods. -> Note: The `getType()` method is deprecated in favor of `keyword()` and will be removed in 2.0. Both return the same validation keyword (e.g., `'type'`, `'minLength'`, `'format'`). Use `keyword()` in new code. - #### Type and Value Errors | Error Type | Keyword | Description | @@ -905,7 +900,7 @@ $validator = OpenApiValidatorBuilder::create() ->build(); ``` -To format a `ValidationException` without holding a reference to the validator, call `ErrorFormatterInterface::formatException()` directly. This is the canonical replacement for the deprecated `OpenApiValidatorInterface::getFormattedErrors()` (removed in 2.0): +To format a `ValidationException` without holding a reference to the validator, call `ErrorFormatterInterface::formatException()` directly: ```php use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; diff --git a/psalm.xml b/psalm.xml index bb71f938..58594fed 100644 --- a/psalm.xml +++ b/psalm.xml @@ -15,15 +15,4 @@ - - - - - - - - - - - diff --git a/rector.php b/rector.php index af02ac41..61d9586b 100644 --- a/rector.php +++ b/rector.php @@ -6,7 +6,6 @@ use Rector\CodingStyle\Rector\Closure\ClosureDelegatingCallToFirstClassCallableRector; use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; -use Rector\Php84\Rector\Class_\DeprecatedAnnotationToDeprecatedAttributeRector; return RectorConfig::configure() ->withPaths([ @@ -21,9 +20,4 @@ ArrowFunctionDelegatingCallToFirstClassCallableRector::class, ClosureDelegatingCallToFirstClassCallableRector::class, ClosureToArrowFunctionRector::class, - DeprecatedAnnotationToDeprecatedAttributeRector::class => [ - __DIR__ . '/src/Schema/Model/Schema.php', - __DIR__ . '/src/Validator/Validation/ValidationStack.php', - __DIR__ . '/src/Validator/Error/ValidationContext.php', - ], ]); diff --git a/src/Builder/OpenApiValidatorBuilder.php b/src/Builder/OpenApiValidatorBuilder.php index d69fbef9..6a41adcd 100644 --- a/src/Builder/OpenApiValidatorBuilder.php +++ b/src/Builder/OpenApiValidatorBuilder.php @@ -44,8 +44,6 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Deprecated; - use function dirname; use function realpath; use function sprintf; @@ -221,22 +219,6 @@ public function withMaxRegexBacktracks(int $maxBacktracks): self return $this->with(new BuilderConfig(maxRegexBacktracks: $maxBacktracks)); } - #[Deprecated(message: <<<'TXT' - since 1.x, will be removed in 2.0. Strict mode is now the - default: callback expressions that use runtime templates - such as `{$request.body#/callback_url}` throw an - {@see \Duyler\OpenApi\Validator\Exception\UnresolvableCallbackPathException} by default instead - of being treated as wildcards that accept any URL. This - method is retained as a no-op for backward compatibility - with callers that explicitly opted in. To restore the - legacy wildcard behaviour, use - {@see disableStrictCallbackRuntimeTemplate()}. - TXT)] - public function enableStrictCallbackRuntimeTemplate(): self - { - return $this; - } - public function disableStrictCallbackRuntimeTemplate(): self { return $this->with(new BuilderConfig(strictCallbackRuntimeTemplate: false)); diff --git a/src/Builder/OpenApiValidatorInterface.php b/src/Builder/OpenApiValidatorInterface.php index a4d4be09..730adc2c 100644 --- a/src/Builder/OpenApiValidatorInterface.php +++ b/src/Builder/OpenApiValidatorInterface.php @@ -6,7 +6,6 @@ use Duyler\OpenApi\Builder\Exception\BuilderException; use Duyler\OpenApi\Schema\OpenApiDocument; -use Duyler\OpenApi\Validator\Error\Formatter\ErrorFormatterInterface; use Duyler\OpenApi\Validator\Exception\BodyTooLargeException; use Duyler\OpenApi\Validator\Exception\OperationNotFoundException; use Duyler\OpenApi\Validator\Exception\UnsupportedSecuritySchemeException; @@ -17,7 +16,6 @@ use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Deprecated; use RuntimeException; /** @@ -73,20 +71,6 @@ public function validateResponse(ResponseInterface $response, Operation $operati */ public function validateSchema(mixed $data, string $schemaRef): void; - /** - * Get validation errors as formatted string. - * - * @see ErrorFormatterInterface::formatException() - * - * @param ValidationException $e Validation exception containing errors - * @return string Formatted error messages - */ - #[Deprecated(message: <<<'TXT' - Use ErrorFormatterInterface::formatException() instead. - This method will be removed in 2.0. - TXT)] - public function getFormattedErrors(ValidationException $e): string; - /** * Validate webhook request against OpenAPI specification and return matched operation. * diff --git a/src/Schema/Model/Schema.php b/src/Schema/Model/Schema.php index 877388ef..b9456fed 100644 --- a/src/Schema/Model/Schema.php +++ b/src/Schema/Model/Schema.php @@ -38,7 +38,6 @@ * @param list|null $enum * @param array|null $examples * @param Xml|null $xml - * @deprecated since 1.x, will be removed in 2.0. Use {@see fromConstraintGroups()} instead. */ public function __construct( public ?string $ref = null, @@ -100,152 +99,6 @@ public function __construct( public ?Xml $xml = null, ) {} - /** - * @param string|list|null $type - * @param array|null $properties - * @param list|null $required - * @param list|null $allOf - * @param list|null $anyOf - * @param list|null $oneOf - * @param Schema|bool|null $not - * @param Schema|bool|null $items - * @param list|null $prefixItems - * @param array|null $patternProperties - * @param array|null $dependentSchemas - * @param Schema|bool|null $additionalProperties - * @param Schema|bool|null $unevaluatedProperties - * @param Schema|bool|null $contentSchema - * @param Schema|bool|null $contains - * @param Schema|bool|null $propertyNames - * @param Schema|bool|null $if - * @param Schema|bool|null $then - * @param Schema|bool|null $else - * @param Schema|bool|null $unevaluatedItems - * @param list|null $enum - * @param array|null $examples - * @param Xml|null $xml - * @deprecated since 1.x, will be removed in 2.0. Use {@see withOverrideGroups()} instead. - */ - public function withOverrides( - ?string $ref = null, - ?string $refSummary = null, - ?string $refDescription = null, - ?string $format = null, - ?string $title = null, - ?string $description = null, - string|int|float|bool|array|null $default = null, - ?bool $hasDefault = null, - ?bool $deprecated = null, - ?bool $readOnly = null, - ?bool $writeOnly = null, - string|array|null $type = null, - ?bool $nullable = null, - string|int|float|bool|array|null $const = null, - ?bool $hasConst = null, - ?float $multipleOf = null, - ?float $maximum = null, - ?float $exclusiveMaximum = null, - ?float $minimum = null, - ?float $exclusiveMinimum = null, - ?int $maxLength = null, - ?int $minLength = null, - ?string $pattern = null, - ?int $maxItems = null, - ?int $minItems = null, - ?bool $uniqueItems = null, - ?int $maxProperties = null, - ?int $minProperties = null, - ?array $required = null, - ?array $allOf = null, - ?array $anyOf = null, - ?array $oneOf = null, - Schema|bool|null $not = null, - ?Discriminator $discriminator = null, - ?array $properties = null, - Schema|bool|null $additionalProperties = null, - Schema|bool|null $unevaluatedProperties = null, - Schema|bool|null $items = null, - ?array $prefixItems = null, - Schema|bool|null $contains = null, - ?int $minContains = null, - ?int $maxContains = null, - ?array $patternProperties = null, - Schema|bool|null $propertyNames = null, - ?array $dependentSchemas = null, - Schema|bool|null $if = null, - Schema|bool|null $then = null, - Schema|bool|null $else = null, - Schema|bool|null $unevaluatedItems = null, - string|int|float|bool|array|null $example = null, - ?array $examples = null, - ?array $enum = null, - ?string $contentEncoding = null, - ?string $contentMediaType = null, - Schema|bool|null $contentSchema = null, - ?string $jsonSchemaDialect = null, - ?Xml $xml = null, - ): self { - return new self( - ref: $ref ?? $this->ref, - refSummary: $refSummary ?? $this->refSummary, - refDescription: $refDescription ?? $this->refDescription, - format: $format ?? $this->format, - title: $title ?? $this->title, - description: $description ?? $this->description, - default: $default ?? $this->default, - hasDefault: $hasDefault ?? $this->hasDefault, - deprecated: $deprecated ?? $this->deprecated, - readOnly: $readOnly ?? $this->readOnly, - writeOnly: $writeOnly ?? $this->writeOnly, - type: $type ?? $this->type, - nullable: $nullable ?? $this->nullable, - const: $const ?? $this->const, - hasConst: $hasConst ?? $this->hasConst, - multipleOf: $multipleOf ?? $this->multipleOf, - maximum: $maximum ?? $this->maximum, - exclusiveMaximum: $exclusiveMaximum ?? $this->exclusiveMaximum, - minimum: $minimum ?? $this->minimum, - exclusiveMinimum: $exclusiveMinimum ?? $this->exclusiveMinimum, - maxLength: $maxLength ?? $this->maxLength, - minLength: $minLength ?? $this->minLength, - pattern: $pattern ?? $this->pattern, - maxItems: $maxItems ?? $this->maxItems, - minItems: $minItems ?? $this->minItems, - uniqueItems: $uniqueItems ?? $this->uniqueItems, - maxProperties: $maxProperties ?? $this->maxProperties, - minProperties: $minProperties ?? $this->minProperties, - required: $required ?? $this->required, - allOf: $allOf ?? $this->allOf, - anyOf: $anyOf ?? $this->anyOf, - oneOf: $oneOf ?? $this->oneOf, - not: $not ?? $this->not, - discriminator: $discriminator ?? $this->discriminator, - properties: $properties ?? $this->properties, - additionalProperties: $additionalProperties ?? $this->additionalProperties, - unevaluatedProperties: $unevaluatedProperties ?? $this->unevaluatedProperties, - items: $items ?? $this->items, - prefixItems: $prefixItems ?? $this->prefixItems, - contains: $contains ?? $this->contains, - minContains: $minContains ?? $this->minContains, - maxContains: $maxContains ?? $this->maxContains, - patternProperties: $patternProperties ?? $this->patternProperties, - propertyNames: $propertyNames ?? $this->propertyNames, - dependentSchemas: $dependentSchemas ?? $this->dependentSchemas, - if: $if ?? $this->if, - then: $then ?? $this->then, - else: $else ?? $this->else, - unevaluatedItems: $unevaluatedItems ?? $this->unevaluatedItems, - example: $example ?? $this->example, - examples: $examples ?? $this->examples, - enum: $enum ?? $this->enum, - contentEncoding: $contentEncoding ?? $this->contentEncoding, - contentMediaType: $contentMediaType ?? $this->contentMediaType, - contentSchema: $contentSchema ?? $this->contentSchema, - jsonSchemaDialect: $jsonSchemaDialect ?? $this->jsonSchemaDialect, - xml: $xml ?? $this->xml, - ); - } - /** * @param ?bool $nullable */ diff --git a/src/Validator/Error/Formatter/ErrorFormatterInterface.php b/src/Validator/Error/Formatter/ErrorFormatterInterface.php index afe9a80a..95e29c10 100644 --- a/src/Validator/Error/Formatter/ErrorFormatterInterface.php +++ b/src/Validator/Error/Formatter/ErrorFormatterInterface.php @@ -19,9 +19,8 @@ public function formatMultiple(array $errors): string; /** * Format a ValidationException's errors into a single string. * - * Replaces OpenApiValidatorInterface::getFormattedErrors() as the - * canonical way to format validation errors without holding a - * reference to the validator. + * This is the canonical way to format validation errors without + * holding a reference to the validator. */ public function formatException(ValidationException $exception): string; } diff --git a/src/Validator/Error/ValidationContext.php b/src/Validator/Error/ValidationContext.php index d8e6e20d..15c58d38 100644 --- a/src/Validator/Error/ValidationContext.php +++ b/src/Validator/Error/ValidationContext.php @@ -22,10 +22,7 @@ final class ValidationContext /** @var array */ private array $evaluatedItemIndices = []; - /** - * @deprecated since 1.x, will be removed in 2.0. Use {@see fromInit()} instead. - */ - public function __construct( + private function __construct( public readonly BreadcrumbManager $breadcrumbs, public readonly ValidatorPool $pool, public readonly ErrorFormatterInterface $errorFormatter, @@ -35,26 +32,6 @@ public function __construct( public readonly ?ValidatorMode $mode = null, ) {} - /** - * @deprecated since 1.x, will be removed in 2.0. Use {@see fromInit()} instead. - */ - public static function create( - ValidatorPool $pool, - ?ErrorFormatterInterface $errorFormatter = null, - bool $nullableAsType = true, - EmptyArrayStrategy $emptyArrayStrategy = EmptyArrayStrategy::AllowBoth, - ?ValidatorMode $mode = null, - ): self { - return new self( - breadcrumbs: BreadcrumbManager::create(), - pool: $pool, - errorFormatter: $errorFormatter ?? new SimpleFormatter(), - nullableAsType: $nullableAsType, - emptyArrayStrategy: $emptyArrayStrategy, - mode: $mode, - ); - } - public static function fromInit(ValidationContextInit $init): self { return new self( diff --git a/src/Validator/Exception/AbstractValidationError.php b/src/Validator/Exception/AbstractValidationError.php index 24781f68..624aab0e 100644 --- a/src/Validator/Exception/AbstractValidationError.php +++ b/src/Validator/Exception/AbstractValidationError.php @@ -8,7 +8,6 @@ use Override; use RuntimeException; use Throwable; -use Deprecated; abstract class AbstractValidationError extends RuntimeException implements ValidationErrorInterface { @@ -68,11 +67,4 @@ public function suggestion(): ?string { return $this->suggestion; } - - #[Override] - #[Deprecated(message: 'Use keyword() instead. This method will be removed in 2.0.')] - public function getType(): string - { - return $this->keyword; - } } diff --git a/src/Validator/Exception/InvalidDataTypeException.php b/src/Validator/Exception/InvalidDataTypeException.php index c040b66f..ebb693d6 100644 --- a/src/Validator/Exception/InvalidDataTypeException.php +++ b/src/Validator/Exception/InvalidDataTypeException.php @@ -12,12 +12,9 @@ final class InvalidDataTypeException extends InvalidArgumentException implements { use SanitizableExceptionTrait; - public readonly string $type; - public function __construct(string $message, int $code = 0, ?Throwable $previous = null) { parent::__construct($message, $code, $previous); - $this->type = 'invalid'; } #[Override] @@ -55,10 +52,4 @@ public function suggestion(): ?string { return null; } - - #[Override] - public function getType(): string - { - return $this->type; - } } diff --git a/src/Validator/Exception/InvalidMultipleOfSchemaException.php b/src/Validator/Exception/InvalidMultipleOfSchemaException.php index 82e090b8..ff0299da 100644 --- a/src/Validator/Exception/InvalidMultipleOfSchemaException.php +++ b/src/Validator/Exception/InvalidMultipleOfSchemaException.php @@ -4,7 +4,6 @@ namespace Duyler\OpenApi\Validator\Exception; -use Deprecated; use InvalidArgumentException; use function sprintf; @@ -20,20 +19,4 @@ public static function forNonPositiveValue(float $multipleOf): self $multipleOf, )); } - - #[Deprecated( - message: 'NumericRangeValidator::isMultipleOf now ' - . 'uses pure-PHP decimal string modulus when bcmath is unavailable, ' - . 'so this factory is no longer thrown from the validator. Retained ' - . 'for backward compatibility with external callers; will be removed ' - . 'in 2.0.', - )] - public static function forLargeIntegerWithoutBcmath(int $data, float $multipleOf): self - { - return new self(sprintf( - 'Cannot reliably check multipleOf for integer %d with float multipleOf %s without BCMath extension', - $data, - $multipleOf, - )); - } } diff --git a/src/Validator/Exception/ValidationErrorInterface.php b/src/Validator/Exception/ValidationErrorInterface.php index 50a01f9b..bfd75d05 100644 --- a/src/Validator/Exception/ValidationErrorInterface.php +++ b/src/Validator/Exception/ValidationErrorInterface.php @@ -4,8 +4,6 @@ namespace Duyler\OpenApi\Validator\Exception; -use Deprecated; - interface ValidationErrorInterface { public function keyword(): string; @@ -22,7 +20,4 @@ public function message(): string; public function params(): array; public function suggestion(): ?string; - - #[Deprecated(message: 'Use keyword() instead. This method will be removed in 2.0.')] - public function getType(): string; } diff --git a/src/Validator/OpenApiValidator.php b/src/Validator/OpenApiValidator.php index 7c524c22..2433bbce 100644 --- a/src/Validator/OpenApiValidator.php +++ b/src/Validator/OpenApiValidator.php @@ -11,7 +11,6 @@ use Duyler\OpenApi\Validator\Dto\ValidatorDependencies; use Duyler\OpenApi\Validator\Error\Formatter\ErrorFormatterInterface; use Duyler\OpenApi\Validator\Exception\UnknownLinkException; -use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\Link\LinkContext; use Duyler\OpenApi\Validator\Link\ResolvedLink; use Override; @@ -80,12 +79,6 @@ public function validateSchema(mixed $data, string $schemaRef): void $this->dependencies->schemaValidation->validate($data, $schemaRef); } - #[Override] - public function getFormattedErrors(ValidationException $e): string - { - return $this->dependencies->errorFormatter->formatMultiple($e->getErrors()); - } - #[Override] public function reset(): void { diff --git a/src/Validator/Request/AbstractParameterValidator.php b/src/Validator/Request/AbstractParameterValidator.php index 64420fdb..49eb03e0 100644 --- a/src/Validator/Request/AbstractParameterValidator.php +++ b/src/Validator/Request/AbstractParameterValidator.php @@ -6,6 +6,7 @@ use Duyler\OpenApi\Schema\Model\Parameter; use Duyler\OpenApi\Validator\Dto\ParameterValidationConfig; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\MissingParameterException; use Duyler\OpenApi\Validator\SchemaValidator\SchemaValidatorInterface; @@ -26,11 +27,11 @@ public function validate(array $data, array $parameterSchemas): void { $location = $this->getLocation(); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, nullableAsType: $this->config->nullableAsType, emptyArrayStrategy: $this->config->emptyArrayStrategy, - ); + )); foreach ($parameterSchemas as $param) { if (false === $param instanceof Parameter) { diff --git a/src/Validator/Request/QueryStringValidator.php b/src/Validator/Request/QueryStringValidator.php index 8a5bdce9..d09834b2 100644 --- a/src/Validator/Request/QueryStringValidator.php +++ b/src/Validator/Request/QueryStringValidator.php @@ -6,6 +6,7 @@ use Duyler\OpenApi\Schema\Model\Parameter; use Duyler\OpenApi\Validator\Dto\ParameterValidationConfig; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\InvalidParameterException; use Duyler\OpenApi\Validator\Exception\MissingParameterException; @@ -30,11 +31,11 @@ public function __construct( public function validate(string $queryString, array $parameterSchemas): void { - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, nullableAsType: $this->config->nullableAsType, emptyArrayStrategy: $this->config->emptyArrayStrategy, - ); + )); foreach ($parameterSchemas as $param) { if (false === $param instanceof Parameter) { diff --git a/src/Validator/Response/ResponseHeadersValidator.php b/src/Validator/Response/ResponseHeadersValidator.php index b110bd76..ed551087 100644 --- a/src/Validator/Response/ResponseHeadersValidator.php +++ b/src/Validator/Response/ResponseHeadersValidator.php @@ -10,6 +10,7 @@ use Duyler\OpenApi\Validator\Coercion\Internal\IntegerCoercer; use Duyler\OpenApi\Validator\Coercion\NumberStringNormalizer; use Duyler\OpenApi\Validator\Dto\ParameterValidationConfig; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\InvalidParameterException; use Duyler\OpenApi\Validator\Exception\MissingParameterException; @@ -62,11 +63,11 @@ public function validate(array $headers, ?Headers $headerSchemas): void if (null !== $value && null !== $header->schema) { $coercedValue = $this->coerceValue($value, $header->schema, $name); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, nullableAsType: $this->config->nullableAsType, emptyArrayStrategy: $this->config->emptyArrayStrategy, - ); + )); $this->schemaValidator->validate($coercedValue, $header->schema, $context); } } diff --git a/src/Validator/Schema/DiscriminatorValidator.php b/src/Validator/Schema/DiscriminatorValidator.php index 4f8f5a94..e535db2d 100644 --- a/src/Validator/Schema/DiscriminatorValidator.php +++ b/src/Validator/Schema/DiscriminatorValidator.php @@ -13,6 +13,7 @@ use Duyler\OpenApi\Validator\Exception\InvalidDiscriminatorValueException; use Duyler\OpenApi\Validator\Exception\MissingDiscriminatorPropertyException; use Duyler\OpenApi\Validator\Exception\UnknownDiscriminatorValueException; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\TypeFormatter; @@ -45,12 +46,12 @@ public function validate( return; } - $validationContext = $context ?? ValidationContext::create( - $this->dependencies->pool, - $this->dependencies->errorFormatter, - $this->configuration->nullableAsType, - $this->configuration->emptyArrayStrategy, - ); + $validationContext = $context ?? ValidationContext::fromInit(new ValidationContextInit( + pool: $this->dependencies->pool, + errorFormatter: $this->dependencies->errorFormatter, + nullableAsType: $this->configuration->nullableAsType, + emptyArrayStrategy: $this->configuration->emptyArrayStrategy, + )); if (null === $discriminator->propertyName) { $this->validateWithoutPropertyName($data, $discriminator, $document, $validationContext); diff --git a/src/Validator/Schema/Internal/CompositionResolver.php b/src/Validator/Schema/Internal/CompositionResolver.php index d75bf19b..73647bb6 100644 --- a/src/Validator/Schema/Internal/CompositionResolver.php +++ b/src/Validator/Schema/Internal/CompositionResolver.php @@ -4,6 +4,10 @@ namespace Duyler\OpenApi\Validator\Schema\Internal; +use Duyler\OpenApi\Schema\Model\Internal\ArrayFields; +use Duyler\OpenApi\Schema\Model\Internal\CompositionFields; +use Duyler\OpenApi\Schema\Model\Internal\ObjectFields; +use Duyler\OpenApi\Schema\Model\Internal\ScalarFields; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; @@ -66,10 +70,11 @@ public function resolveCompositionRefs(Schema $schema, WeakMap $visited): Schema return $schema; } - $resolved = $schema->withOverrides( - allOf: $allOf, - anyOf: $anyOf, - oneOf: $oneOf, + $resolved = $schema->withOverrideGroups( + scalar: new ScalarFields(), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(allOf: $allOf, anyOf: $anyOf, oneOf: $oneOf), ); $this->resolvedCache[$schema] = $resolved; diff --git a/src/Validator/Schema/SchemaValidatorWithContext.php b/src/Validator/Schema/SchemaValidatorWithContext.php index 36a40dea..40fbea83 100644 --- a/src/Validator/Schema/SchemaValidatorWithContext.php +++ b/src/Validator/Schema/SchemaValidatorWithContext.php @@ -8,6 +8,7 @@ use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; use Duyler\OpenApi\Validator\Dto\ValidatorConfiguration; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Schema\Internal\CompositionResolver; use Duyler\OpenApi\Validator\Schema\Internal\PropertiesAndItemsDispatcher; @@ -57,13 +58,13 @@ public function __construct( public function validate(array|int|string|float|bool|null $data, Schema $schema, ?ValidatorMode $mode = null): void { - $context = ValidationContext::create( - $this->dependencies->pool, - $this->dependencies->errorFormatter, - $this->configuration->nullableAsType, - $this->configuration->emptyArrayStrategy, - $mode, - ); + $context = ValidationContext::fromInit(new ValidationContextInit( + pool: $this->dependencies->pool, + errorFormatter: $this->dependencies->errorFormatter, + nullableAsType: $this->configuration->nullableAsType, + emptyArrayStrategy: $this->configuration->emptyArrayStrategy, + mode: $mode, + )); $this->doValidate($data, $schema, $context, true); } diff --git a/src/Validator/Schema/StatelessValidatorDispatcher.php b/src/Validator/Schema/StatelessValidatorDispatcher.php index dcb7c8d6..c76e800c 100644 --- a/src/Validator/Schema/StatelessValidatorDispatcher.php +++ b/src/Validator/Schema/StatelessValidatorDispatcher.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\Schema; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Schema\Internal\ApplicableValidators; use Duyler\OpenApi\Validator\SchemaValidator\SchemaValidatorInterface; @@ -33,7 +34,7 @@ public function __construct( public function validate(array|int|string|float|bool|null $data, Schema $schema, ?ValidationContext $context = null): void { if (null === $context) { - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); } $context->incrementDepth(); diff --git a/src/Validator/SchemaValidator/AdditionalPropertiesValidator.php b/src/Validator/SchemaValidator/AdditionalPropertiesValidator.php index ffa0633d..83880565 100644 --- a/src/Validator/SchemaValidator/AdditionalPropertiesValidator.php +++ b/src/Validator/SchemaValidator/AdditionalPropertiesValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\AdditionalPropertyError; use Duyler\OpenApi\Validator\Exception\ValidationException; @@ -171,7 +172,7 @@ private function validateAdditionalSchemas(array $data, Schema $additionalSchema $keyString = (string) $key; if (null === $context) { - $context = ValidationContext::create(pool: $this->pool(), nullableAsType: $nullableAsType); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $nullableAsType)); } $context->enterBreadcrumb($keyString); diff --git a/src/Validator/SchemaValidator/ContainsValidator.php b/src/Validator/SchemaValidator/ContainsValidator.php index b4eb4f69..a7ec9fea 100644 --- a/src/Validator/SchemaValidator/ContainsValidator.php +++ b/src/Validator/SchemaValidator/ContainsValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\AbstractValidationError; use Duyler\OpenApi\Validator\Exception\ContainsMatchError; @@ -65,7 +66,7 @@ private function validateBooleanTrueContains(array $data, Schema $schema, ?Valid { $this->enforceContainsBounds(count($data), $schema, $dataPath); - $containsContext = $context ?? ValidationContext::create(pool: $this->pool()); + $containsContext = $context ?? ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool())); foreach (array_keys($data) as $index) { /** @var int $index */ @@ -79,7 +80,7 @@ private function validateBooleanTrueContains(array $data, Schema $schema, ?Valid private function countSchemaMatches(array $data, Schema $containsSchema, ?ValidationContext $context, string $dataPath, ?int $maxContains = null): int { $validator = $this->createSchemaValidator(); - $containsContext = $context ?? ValidationContext::create(pool: $this->pool()); + $containsContext = $context ?? ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool())); $matchCount = 0; diff --git a/src/Validator/SchemaValidator/ItemsValidator.php b/src/Validator/SchemaValidator/ItemsValidator.php index a70aaeef..00d2d065 100644 --- a/src/Validator/SchemaValidator/ItemsValidator.php +++ b/src/Validator/SchemaValidator/ItemsValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\InvalidDataTypeException; use Duyler\OpenApi\Validator\Exception\InvalidFormatException; @@ -89,7 +90,7 @@ private function validateOneItem(mixed $item, int $index, ItemValidationState $s $normalizedItem = SchemaValueNormalizer::normalize($item, $state->allowNull); if (null === $state->context) { - $state->context = ValidationContext::create(pool: $this->pool(), nullableAsType: $state->nullableAsType); + $state->context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $state->nullableAsType)); } $state->context->enterBreadcrumbIndex($index); diff --git a/src/Validator/SchemaValidator/PatternPropertiesValidator.php b/src/Validator/SchemaValidator/PatternPropertiesValidator.php index ddced3af..3b51471b 100644 --- a/src/Validator/SchemaValidator/PatternPropertiesValidator.php +++ b/src/Validator/SchemaValidator/PatternPropertiesValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Override; @@ -92,7 +93,7 @@ private function applyPatterns(array $data, array $patternProperties, array $nor $propertySchema = $patternProperties[$pattern]; if (null === $context) { - $context = ValidationContext::create(pool: $this->pool(), nullableAsType: $nullableAsType); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $nullableAsType)); } $context->enterBreadcrumb($propertyName); diff --git a/src/Validator/SchemaValidator/PrefixItemsValidator.php b/src/Validator/SchemaValidator/PrefixItemsValidator.php index de8fe796..d5ad281e 100644 --- a/src/Validator/SchemaValidator/PrefixItemsValidator.php +++ b/src/Validator/SchemaValidator/PrefixItemsValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\AbstractValidationError; use Duyler\OpenApi\Validator\Exception\InvalidDataTypeException; @@ -69,7 +70,7 @@ private function validatePrefixItemAt(mixed $item, int $index, ItemValidationSta $value = SchemaValueNormalizer::normalize($item, $allowNull); if (null === $state->context) { - $state->context = ValidationContext::create(pool: $this->pool(), nullableAsType: $state->nullableAsType); + $state->context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $state->nullableAsType)); } $state->context->enterBreadcrumbIndex($index); diff --git a/src/Validator/SchemaValidator/PropertiesValidator.php b/src/Validator/SchemaValidator/PropertiesValidator.php index a3661ebf..df82e85a 100644 --- a/src/Validator/SchemaValidator/PropertiesValidator.php +++ b/src/Validator/SchemaValidator/PropertiesValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\AbstractValidationError; use Duyler\OpenApi\Validator\Exception\InvalidDataTypeException; @@ -38,7 +39,7 @@ public function validate(mixed $data, Schema $schema, ?ValidationContext $contex $validator = $this->createSchemaValidator(); $nullableAsType = $context?->nullableAsType ?? true; - $context ??= ValidationContext::create(pool: $this->pool(), nullableAsType: $nullableAsType); + $context ??= ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $nullableAsType)); foreach ($schema->properties as $name => $propertySchema) { if (false === array_key_exists($name, $data)) { diff --git a/src/Validator/SchemaValidator/UnevaluatedItemsValidator.php b/src/Validator/SchemaValidator/UnevaluatedItemsValidator.php index 5630d678..cc05a68a 100644 --- a/src/Validator/SchemaValidator/UnevaluatedItemsValidator.php +++ b/src/Validator/SchemaValidator/UnevaluatedItemsValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\Exception\ValidationException; @@ -102,7 +103,7 @@ private function validateUnevaluatedItems(array $data, Schema $unevaluatedItems, $item = $data[$index]; if (null === $context) { - $context = ValidationContext::create(pool: $this->pool(), nullableAsType: $nullableAsType); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $nullableAsType)); } $context->enterBreadcrumbIndex($index); diff --git a/src/Validator/SchemaValidator/UnevaluatedPropertiesValidator.php b/src/Validator/SchemaValidator/UnevaluatedPropertiesValidator.php index 4ad699e7..a4c06d80 100644 --- a/src/Validator/SchemaValidator/UnevaluatedPropertiesValidator.php +++ b/src/Validator/SchemaValidator/UnevaluatedPropertiesValidator.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Validator\SchemaValidator; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\UnevaluatedPropertyError; use Override; @@ -77,7 +78,7 @@ private function validateUnevaluatedProperties(array $data, Schema $unevaluatedP $value = $data[$propertyName]; if (null === $context) { - $context = ValidationContext::create(pool: $this->pool(), nullableAsType: $nullableAsType); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool(), nullableAsType: $nullableAsType)); } $context->enterBreadcrumb($propertyName); diff --git a/src/Validator/Validation/ValidationStack.php b/src/Validator/Validation/ValidationStack.php index fc8a0738..6b137f22 100644 --- a/src/Validator/Validation/ValidationStack.php +++ b/src/Validator/Validation/ValidationStack.php @@ -52,13 +52,12 @@ private readonly ValidatorConfiguration $validatorConfiguration; /** - * @deprecated since 1.x, will be removed in 2.0. Use {@see fromGroup()} instead. * @param int $maxJsonBodyBytes * @param int $maxMultipartBodyBytes * @param int $maxRegexBacktracks * @param int $maxStreamingRecords */ - public function __construct( + private function __construct( public readonly OpenApiDocument $document, public readonly ValidatorPool $pool, public readonly FormatRegistry $formatRegistry, diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php index c3709234..565cbc4e 100644 --- a/tests/Functional/FunctionalTestCase.php +++ b/tests/Functional/FunctionalTestCase.php @@ -8,10 +8,10 @@ use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Schema\Parser\YamlParser; use Duyler\OpenApi\Schema\SchemaParserInterface; -use Duyler\OpenApi\Validator\Error\BreadcrumbManager; use Duyler\OpenApi\Validator\Error\Formatter\ErrorFormatterInterface; use Duyler\OpenApi\Validator\Error\Formatter\JsonFormatter; use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; @@ -51,11 +51,10 @@ protected function setUp(): void protected function createContext(ErrorFormatterInterface $formatter = new SimpleFormatter()): ValidationContext { - return new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + return ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); } protected function createValidator(): SchemaValidatorWithContext @@ -140,7 +139,7 @@ protected function assertMultipleErrors( } } - protected function getFormattedErrors(ValidationException $e, ErrorFormatterInterface $formatter): array + protected function formatValidationErrors(ValidationException $e, ErrorFormatterInterface $formatter): array { $errors = []; foreach ($e->getErrors() as $error) { diff --git a/tests/Functional/Request/RequestBodyValidationTest.php b/tests/Functional/Request/RequestBodyValidationTest.php index 1bf20615..cc97bb39 100644 --- a/tests/Functional/Request/RequestBodyValidationTest.php +++ b/tests/Functional/Request/RequestBodyValidationTest.php @@ -6,6 +6,7 @@ use Duyler\OpenApi\Builder\OpenApiValidatorBuilder; use Duyler\OpenApi\Builder\OpenApiValidatorInterface; +use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Exception\AbstractValidationError; use Duyler\OpenApi\Validator\Exception\MissingRequestBodyException; use Duyler\OpenApi\Validator\Exception\UnsupportedMediaTypeException; @@ -517,7 +518,7 @@ private function capture_validator_output( return ''; } catch (ValidationException $e) { - return $e->getMessage() . $validator->getFormattedErrors($e); + return $e->getMessage() . (new SimpleFormatter())->formatException($e); } catch (AbstractValidationError $e) { return $e->getMessage() . ($e->suggestion() ?? ''); } catch (RuntimeException $e) { diff --git a/tests/Functional/Response/CompositionBranchErrorsTest.php b/tests/Functional/Response/CompositionBranchErrorsTest.php index dbbb5337..53416a79 100644 --- a/tests/Functional/Response/CompositionBranchErrorsTest.php +++ b/tests/Functional/Response/CompositionBranchErrorsTest.php @@ -6,6 +6,7 @@ use Duyler\OpenApi\Builder\OpenApiValidatorBuilder; use Duyler\OpenApi\Builder\OpenApiValidatorInterface; +use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Exception\ValidationException; use Nyholm\Psr7\Factory\Psr17Factory; use PHPUnit\Framework\Attributes\Test; @@ -64,7 +65,7 @@ public function null_body_reports_a_structured_error_with_a_data_path(): void $exception = $this->assertRejects('null'); $this->assertNotEmpty($exception->getErrors()); - $this->assertNotSame('', $this->validator->getFormattedErrors($exception)); + $this->assertNotSame('', (new SimpleFormatter())->formatException($exception)); $this->assertSame('All of the schemas must match, but 1 failed', $exception->getMessage()); } diff --git a/tests/Functional/Schema/CompositionBranchErrorsTest.php b/tests/Functional/Schema/CompositionBranchErrorsTest.php index b7c69a9c..aebae7f4 100644 --- a/tests/Functional/Schema/CompositionBranchErrorsTest.php +++ b/tests/Functional/Schema/CompositionBranchErrorsTest.php @@ -6,6 +6,7 @@ use Duyler\OpenApi\Builder\OpenApiValidatorBuilder; use Duyler\OpenApi\Builder\OpenApiValidatorInterface; +use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Exception\ValidationException; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -147,7 +148,7 @@ public function formatted_errors_are_never_empty_and_never_repeat(): void foreach ($cases as [$schema, $data]) { $exception = $this->assertRejects($schema, $data); - $this->assertNotSame('', $this->validator->getFormattedErrors($exception), $schema); + $this->assertNotSame('', (new SimpleFormatter())->formatException($exception), $schema); $this->assertNoDuplicates($exception, $schema); } } diff --git a/tests/Functional/Validator/OpenApiValidatorDirectTest.php b/tests/Functional/Validator/OpenApiValidatorDirectTest.php index eb590703..3d8ba8bc 100644 --- a/tests/Functional/Validator/OpenApiValidatorDirectTest.php +++ b/tests/Functional/Validator/OpenApiValidatorDirectTest.php @@ -5,6 +5,7 @@ namespace Duyler\OpenApi\Test\Functional\Validator; use Duyler\OpenApi\Builder\OpenApiValidatorBuilder; +use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Operation; use Duyler\OpenApi\Validator\Exception\ValidationException; use PHPUnit\Framework\Attributes\Test; @@ -95,7 +96,7 @@ public function get_formatted_errors_returns_formatted_message(): void $validator->validateResponse($response, $operation); $this->fail('Expected ValidationException to be thrown'); } catch (ValidationException $e) { - $formatted = $validator->getFormattedErrors($e); + $formatted = (new SimpleFormatter())->formatException($e); $this->assertIsString($formatted); $this->assertNotEmpty($formatted); } diff --git a/tests/Functional/Validator/OpenApiValidatorSchemaTest.php b/tests/Functional/Validator/OpenApiValidatorSchemaTest.php index 8af90c34..a23d6d7b 100644 --- a/tests/Functional/Validator/OpenApiValidatorSchemaTest.php +++ b/tests/Functional/Validator/OpenApiValidatorSchemaTest.php @@ -14,6 +14,7 @@ use Duyler\OpenApi\Event\ArrayDispatcher; use Duyler\OpenApi\Event\ValidationFinishedEvent; use Duyler\OpenApi\Event\ValidationStartedEvent; +use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\Webhook\Exception\UnknownWebhookException; use Exception; @@ -136,7 +137,7 @@ public function get_formatted_errors_returns_string(): void $this->validator->validateSchema(['age' => 30], '#/components/schemas/User'); $this->fail('Expected ValidationException'); } catch (ValidationException $e) { - $formatted = $this->validator->getFormattedErrors($e); + $formatted = (new SimpleFormatter())->formatException($e); self::assertIsString($formatted); self::assertNotEmpty($formatted); diff --git a/tests/Functional/Validator/SchemaValidator/EmptyArrayStrategyTest.php b/tests/Functional/Validator/SchemaValidator/EmptyArrayStrategyTest.php index ead0815a..63a7db07 100644 --- a/tests/Functional/Validator/SchemaValidator/EmptyArrayStrategyTest.php +++ b/tests/Functional/Validator/SchemaValidator/EmptyArrayStrategyTest.php @@ -9,6 +9,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\EmptyArrayStrategy; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\SchemaValidator\TypeValidator; @@ -31,7 +32,7 @@ protected function setUp(): void public function empty_array_with_prefer_array_strategy_valid_for_array(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray)); $schema = new Schema(type: 'array'); $validator->validate([], $schema, $context); @@ -43,7 +44,7 @@ public function empty_array_with_prefer_array_strategy_valid_for_array(): void public function empty_array_with_prefer_array_strategy_invalid_for_object(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray)); $schema = new Schema(type: 'object'); $this->expectException(TypeMismatchError::class); @@ -55,7 +56,7 @@ public function empty_array_with_prefer_array_strategy_invalid_for_object(): voi public function empty_array_with_prefer_object_strategy_invalid_for_array(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject)); $schema = new Schema(type: 'array'); $this->expectException(TypeMismatchError::class); @@ -67,7 +68,7 @@ public function empty_array_with_prefer_object_strategy_invalid_for_array(): voi public function empty_array_with_prefer_object_strategy_valid_for_object(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject)); $schema = new Schema(type: 'object'); $validator->validate([], $schema, $context); @@ -79,7 +80,7 @@ public function empty_array_with_prefer_object_strategy_valid_for_object(): void public function empty_array_with_reject_strategy_invalid_for_array(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::Reject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::Reject)); $schema = new Schema(type: 'array'); $this->expectException(TypeMismatchError::class); @@ -91,7 +92,7 @@ public function empty_array_with_reject_strategy_invalid_for_array(): void public function empty_array_with_reject_strategy_invalid_for_object(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::Reject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::Reject)); $schema = new Schema(type: 'object'); $this->expectException(TypeMismatchError::class); @@ -103,7 +104,7 @@ public function empty_array_with_reject_strategy_invalid_for_object(): void public function empty_array_with_allow_both_strategy_valid_for_array(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth)); $schema = new Schema(type: 'array'); $validator->validate([], $schema, $context); @@ -115,7 +116,7 @@ public function empty_array_with_allow_both_strategy_valid_for_array(): void public function empty_array_with_allow_both_strategy_valid_for_object(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth)); $schema = new Schema(type: 'object'); $validator->validate([], $schema, $context); @@ -127,7 +128,7 @@ public function empty_array_with_allow_both_strategy_valid_for_object(): void public function empty_array_in_union_type_with_prefer_array(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray)); $schema = new Schema(type: ['array', 'object']); $validator->validate([], $schema, $context); @@ -139,7 +140,7 @@ public function empty_array_in_union_type_with_prefer_array(): void public function empty_array_in_union_type_with_prefer_object(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject)); $schema = new Schema(type: ['array', 'object']); $validator->validate([], $schema, $context); @@ -151,7 +152,7 @@ public function empty_array_in_union_type_with_prefer_object(): void public function empty_array_in_union_type_with_reject(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::Reject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::Reject)); $schema = new Schema(type: ['array', 'object']); $this->expectException(TypeMismatchError::class); @@ -163,7 +164,7 @@ public function empty_array_in_union_type_with_reject(): void public function empty_array_in_union_type_with_allow_both(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth)); $schema = new Schema(type: ['array', 'object']); $validator->validate([], $schema, $context); @@ -200,7 +201,7 @@ public function default_strategy_is_allow_both(): void public function non_empty_array_validation_unchanged_with_prefer_array(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferArray)); $arraySchema = new Schema(type: 'array'); $objectSchema = new Schema(type: 'object'); @@ -215,7 +216,7 @@ public function non_empty_array_validation_unchanged_with_prefer_array(): void public function non_empty_object_validation_unchanged_with_prefer_object(): void { $validator = new TypeValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true, emptyArrayStrategy: EmptyArrayStrategy::PreferObject)); $arraySchema = new Schema(type: 'array'); $objectSchema = new Schema(type: 'object'); diff --git a/tests/Functional/Validator/Validation/CallbackValidatorTest.php b/tests/Functional/Validator/Validation/CallbackValidatorTest.php index fc1159b2..0f8821a7 100644 --- a/tests/Functional/Validator/Validation/CallbackValidatorTest.php +++ b/tests/Functional/Validator/Validation/CallbackValidatorTest.php @@ -22,6 +22,9 @@ use Duyler\OpenApi\Validator\Format\FormatRegistry; use Duyler\OpenApi\Validator\Schema\RefResolver; use Duyler\OpenApi\Validator\Validation\CallbackValidator; +use Duyler\OpenApi\Validator\Validation\Internal\RootServices; +use Duyler\OpenApi\Validator\Validation\Internal\ValidationGroup; +use Duyler\OpenApi\Validator\Validation\Internal\ValidatorOptions; use Duyler\OpenApi\Validator\Validation\ValidationStack; use Duyler\OpenApi\Validator\ValidatorPool; use Nyholm\Psr7\Factory\Psr17Factory; @@ -335,13 +338,15 @@ private function buildDependencies( OpenApiDocument $document, ?EventDispatcherInterface $dispatcher = null, ): ValidationStack { - return new ValidationStack( - document: $document, - pool: new ValidatorPool(), - formatRegistry: new FormatRegistry(), - errorFormatter: new SimpleFormatter(), - refResolver: new RefResolver(), - eventDispatcher: $dispatcher, - ); + return ValidationStack::fromGroup(new ValidationGroup( + root: new RootServices( + document: $document, + pool: new ValidatorPool(), + formatRegistry: new FormatRegistry(), + errorFormatter: new SimpleFormatter(), + refResolver: new RefResolver(), + ), + options: new ValidatorOptions(eventDispatcher: $dispatcher), + )); } } diff --git a/tests/Integration/Concurrency/ValidationContextPerRequestTest.php b/tests/Integration/Concurrency/ValidationContextPerRequestTest.php index da7da2ce..75311f97 100644 --- a/tests/Integration/Concurrency/ValidationContextPerRequestTest.php +++ b/tests/Integration/Concurrency/ValidationContextPerRequestTest.php @@ -5,8 +5,8 @@ namespace Duyler\OpenApi\Test\Integration\Concurrency; use Duyler\OpenApi\Builder\OpenApiValidatorBuilder; -use Duyler\OpenApi\Validator\Error\BreadcrumbManager; use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\ValidatorPool; @@ -137,14 +137,14 @@ public function independent_breadcrumbs_under_simulated_concurrent_validations() { $pool = new ValidatorPool(); - $contextA = ValidationContext::create( + $contextA = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: new SimpleFormatter(), - ); - $contextB = ValidationContext::create( + )); + $contextB = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: new SimpleFormatter(), - ); + )); $contextA->enterBreadcrumb('users'); $contextB->enterBreadcrumb('items'); @@ -176,8 +176,8 @@ public function independent_depth_counters_under_simulated_concurrent_validation { $pool = new ValidatorPool(); - $contextA = ValidationContext::create(pool: $pool); - $contextB = ValidationContext::create(pool: $pool); + $contextA = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); + $contextB = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); self::assertSame(0, $contextA->depth()); self::assertSame(0, $contextB->depth()); @@ -197,29 +197,23 @@ public function independent_depth_counters_under_simulated_concurrent_validation } #[Test] - public function shared_breadcrumb_manager_proves_isolation_failure_when_shared(): void + public function from_init_contexts_have_fully_independent_breadcrumbs(): void { $pool = new ValidatorPool(); - $sharedBreadcrumbs = BreadcrumbManager::create(); - $contextA = new ValidationContext( - breadcrumbs: $sharedBreadcrumbs, + $contextA = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: new SimpleFormatter(), - ); - $contextB = new ValidationContext( - breadcrumbs: $sharedBreadcrumbs, + )); + $contextB = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: new SimpleFormatter(), - ); + )); $contextA->enterBreadcrumb('a'); $contextB->enterBreadcrumb('b'); - self::assertSame('/a/b', $contextA->breadcrumbs->currentPath()); - self::assertSame('/a/b', $contextB->breadcrumbs->currentPath()); - - $contextA->leaveBreadcrumb(); - $contextB->leaveBreadcrumb(); + self::assertSame('/a', $contextA->breadcrumbs->currentPath(), 'Context A must never observe context B breadcrumb.'); + self::assertSame('/b', $contextB->breadcrumbs->currentPath(), 'Context B must never observe context A breadcrumb.'); } } diff --git a/tests/Integration/Validator/Error/BreadcrumbIntegrationTest.php b/tests/Integration/Validator/Error/BreadcrumbIntegrationTest.php index 3d764e09..263325b1 100644 --- a/tests/Integration/Validator/Error/BreadcrumbIntegrationTest.php +++ b/tests/Integration/Validator/Error/BreadcrumbIntegrationTest.php @@ -8,6 +8,7 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\Exception\ValidationException; @@ -59,7 +60,7 @@ public function track_breadcrumb_for_nested_properties(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -88,7 +89,7 @@ public function track_breadcrumb_for_array_indices(): void ), ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -122,7 +123,7 @@ public function track_breadcrumb_for_complex_structure(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -148,7 +149,7 @@ public function include_breadcrumb_in_exception(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -190,7 +191,7 @@ public function maintain_breadcrumb_in_multiple_nesting_levels(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -222,7 +223,7 @@ public function track_multiple_array_indices(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -259,7 +260,7 @@ public function breadcrumb_with_mixed_properties_and_arrays(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { diff --git a/tests/Integration/Validator/Error/ErrorHandlingIntegrationTest.php b/tests/Integration/Validator/Error/ErrorHandlingIntegrationTest.php index a53548fe..e893aa17 100644 --- a/tests/Integration/Validator/Error/ErrorHandlingIntegrationTest.php +++ b/tests/Integration/Validator/Error/ErrorHandlingIntegrationTest.php @@ -8,10 +8,10 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; -use Duyler\OpenApi\Validator\Error\BreadcrumbManager; use Duyler\OpenApi\Validator\Error\Formatter\DetailedFormatter; use Duyler\OpenApi\Validator\Error\Formatter\JsonFormatter; use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\MinimumError; use Duyler\OpenApi\Validator\Exception\MinLengthError; @@ -59,11 +59,10 @@ public function format_validation_error_with_simple_formatter(): void ); $formatter = new SimpleFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -95,11 +94,10 @@ public function format_multiple_errors_with_detailed_formatter(): void ); $formatter = new DetailedFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -126,11 +124,10 @@ public function use_custom_formatter(): void ); $formatter = new JsonFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -170,11 +167,10 @@ public function context_maintains_formatter_through_validation_chain(): void ); $formatter = new DetailedFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -203,11 +199,10 @@ public function simple_formatter_for_root_level_error(): void ); $formatter = new SimpleFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -239,11 +234,10 @@ public function json_formatter_includes_all_error_details(): void ); $formatter = new JsonFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { @@ -279,11 +273,10 @@ public function detailed_formatter_provides_comprehensive_output(): void ); $formatter = new DetailedFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: $formatter, - ); + )); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); try { diff --git a/tests/Integration/Validator/Schema/ItemsValidatorWithContextTest.php b/tests/Integration/Validator/Schema/ItemsValidatorWithContextTest.php index 7e507b80..9c56bc44 100644 --- a/tests/Integration/Validator/Schema/ItemsValidatorWithContextTest.php +++ b/tests/Integration/Validator/Schema/ItemsValidatorWithContextTest.php @@ -16,6 +16,7 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\MissingDiscriminatorPropertyException; use Duyler\OpenApi\Validator\Exception\UnknownDiscriminatorValueException; @@ -45,7 +46,7 @@ protected function setUp(): void '3.1.0', new InfoObject('Test API', '1.0.0'), ); - $this->context = ValidationContext::create(pool: $this->pool); + $this->context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->statelessValidators = new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()); $this->validator = new ItemsValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); } @@ -102,7 +103,7 @@ public function validate_items_with_validation_context(): void $data = ['value1', 'value2']; - $customContext = ValidationContext::create(pool: $this->pool); + $customContext = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->validator->validateWithContext($data, $schema, $customContext); $this->expectNotToPerformAssertions(); @@ -119,7 +120,7 @@ public function validate_items_with_breadcrumb_tracking(): void $data = ['first', 'second', 'third']; - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->validator->validateWithContext($data, $schema, $context); @@ -456,7 +457,7 @@ public function validate_items_with_nullable_item_schema(): void items: $itemSchema, ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $data = ['valid', null, 'also valid']; @@ -644,7 +645,7 @@ public function validate_items_with_ref_to_nullable_type_accepts_null(): void ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $validator->validateWithContext([null], $schema, $nullableContext); @@ -680,7 +681,7 @@ public function validate_items_with_ref_to_non_nullable_type_rejects_null(): voi ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(ValidationException::class); @@ -716,7 +717,7 @@ public function validate_items_with_ref_and_sibling_nullable_accepts_null(): voi ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $validator->validateWithContext([null], $schema, $nullableContext); @@ -752,7 +753,7 @@ public function validate_items_with_ref_continues_to_accept_non_null_values(): v ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $validator->validateWithContext(['hello', 'world'], $schema, $nullableContext); diff --git a/tests/Integration/Validator/Schema/OneOfValidatorWithContextTest.php b/tests/Integration/Validator/Schema/OneOfValidatorWithContextTest.php index bab5ffe1..34a1cd2c 100644 --- a/tests/Integration/Validator/Schema/OneOfValidatorWithContextTest.php +++ b/tests/Integration/Validator/Schema/OneOfValidatorWithContextTest.php @@ -15,6 +15,7 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\ValidatorPool; @@ -45,7 +46,7 @@ protected function setUp(): void '3.1.0', new InfoObject('Test API', '1.0.0'), ); - $this->context = ValidationContext::create(pool: $this->pool); + $this->context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->statelessValidators = new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()); $this->validator = new OneOfValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); } @@ -143,7 +144,7 @@ public function validate_with_discriminator_null_data_nullable(): void ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -167,7 +168,7 @@ public function validate_with_discriminator_null_data_native_nullable_type(): vo ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -192,7 +193,7 @@ public function validate_with_discriminator_null_data_native_null_type_singleton ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -217,7 +218,7 @@ public function validate_with_discriminator_null_data_no_nullable_form(): void ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(ValidationException::class); $this->expectExceptionMessage('data must be an object'); @@ -236,7 +237,7 @@ public function validate_with_discriminator_null_data_native_nullable_with_nulla ], ); - $nonNullableContext = ValidationContext::create($this->pool, nullableAsType: false); + $nonNullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(ValidationException::class); $this->expectExceptionMessage('data must be an object'); @@ -256,7 +257,7 @@ public function validate_with_discriminator_null_data_mixed_nullable_forms(): vo ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -696,7 +697,7 @@ public function validate_without_discriminator_null_with_nullable_schema(): void ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -735,7 +736,7 @@ public function validate_without_discriminator_null_with_nullable_as_type_false( ], ); - $nonNullableContext = ValidationContext::create($this->pool, nullableAsType: false); + $nonNullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(ValidationException::class); @@ -1167,7 +1168,7 @@ public function validate_without_discriminator_with_null_data_nullable_context() ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -1190,7 +1191,7 @@ public function validate_without_discriminator_all_nullable_schemas(): void ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(ValidationException::class); $this->expectExceptionMessage('Data matches multiple schemas'); diff --git a/tests/Integration/Validator/Schema/PropertiesValidatorWithContextTest.php b/tests/Integration/Validator/Schema/PropertiesValidatorWithContextTest.php index 1c49831d..61417f4c 100644 --- a/tests/Integration/Validator/Schema/PropertiesValidatorWithContextTest.php +++ b/tests/Integration/Validator/Schema/PropertiesValidatorWithContextTest.php @@ -16,6 +16,7 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\MissingDiscriminatorPropertyException; use Duyler\OpenApi\Validator\Exception\UnknownDiscriminatorValueException; @@ -45,7 +46,7 @@ protected function setUp(): void '3.1.0', new InfoObject('Test API', '1.0.0'), ); - $this->context = ValidationContext::create(pool: $this->pool); + $this->context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->statelessValidators = new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()); $this->validator = new PropertiesValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); } @@ -107,7 +108,7 @@ public function validate_properties_with_validation_context(): void 'id' => 123, ]; - $customContext = ValidationContext::create(pool: $this->pool); + $customContext = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->validator->validateWithContext($data, $schema, $customContext); $this->expectNotToPerformAssertions(); @@ -127,7 +128,7 @@ public function validate_properties_with_breadcrumb_tracking(): void 'name' => 'Test', ]; - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $this->validator->validateWithContext($data, $schema, $context); @@ -584,7 +585,7 @@ public function validate_properties_with_nullable_property(): void ], ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $data = [ 'name' => null, @@ -655,7 +656,7 @@ public function validate_properties_with_ref_to_nullable_type_accepts_null(): vo ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $validator->validateWithContext(['value' => null], $schema, $nullableContext); @@ -693,7 +694,7 @@ public function validate_properties_with_ref_to_non_nullable_type_rejects_null() ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(ValidationException::class); @@ -731,7 +732,7 @@ public function validate_properties_with_ref_and_sibling_nullable_accepts_null() ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $validator->validateWithContext(['value' => null], $schema, $nullableContext); @@ -769,7 +770,7 @@ public function validate_properties_with_ref_continues_to_accept_non_null_values ), ); - $nullableContext = ValidationContext::create($this->pool, nullableAsType: true); + $nullableContext = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $validator->validateWithContext(['value' => 'hello'], $schema, $nullableContext); diff --git a/tests/Integration/Validator/Schema/SchemaValidatorWithContextResolveRefTest.php b/tests/Integration/Validator/Schema/SchemaValidatorWithContextResolveRefTest.php index 79c8bbec..38eea015 100644 --- a/tests/Integration/Validator/Schema/SchemaValidatorWithContextResolveRefTest.php +++ b/tests/Integration/Validator/Schema/SchemaValidatorWithContextResolveRefTest.php @@ -14,6 +14,7 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\ValidatorPool; @@ -135,7 +136,7 @@ public function validate_with_context_resolves_ref_and_validates(): void { $schema = new Schema(ref: '#/components/schemas/Item'); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $data = [ 'id' => 1, @@ -151,7 +152,7 @@ public function validate_with_context_resolves_ref_and_throws_for_missing_requir { $schema = new Schema(ref: '#/components/schemas/Item'); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $data = []; @@ -317,7 +318,7 @@ public function validate_with_context_without_ref(): void ], ); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $data = ['value' => 'test']; @@ -337,7 +338,7 @@ public function validate_with_context_without_ref_throws_for_invalid(): void ], ); $validator = new SchemaValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $data = []; diff --git a/tests/Security/CallbackRuntimeTemplateSecurityTest.php b/tests/Security/CallbackRuntimeTemplateSecurityTest.php index be683900..9910017b 100644 --- a/tests/Security/CallbackRuntimeTemplateSecurityTest.php +++ b/tests/Security/CallbackRuntimeTemplateSecurityTest.php @@ -18,7 +18,6 @@ use Duyler\OpenApi\Validator\Request\RequestValidatorInterface; use Nyholm\Psr7\Factory\Psr17Factory; use Override; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -150,22 +149,6 @@ public function builder_disable_strict_allows_wildcard(): void $this->assertSame('myCallback', $operation->path); } - #[Test] - #[IgnoreDeprecations] - public function builder_enable_strict_is_backward_compatible_noop(): void - { - $validator = OpenApiValidatorBuilder::create() - ->fromYamlString(self::CALLBACK_RUNTIME_TEMPLATE_YAML) - ->enableStrictCallbackRuntimeTemplate() - ->build(); - - $request = $this->psrFactory->createServerRequest('POST', '/attacker-controlled-url'); - - $this->expectException(UnresolvableCallbackPathException::class); - - $validator->validateCallback($request, 'myCallback'); - } - /** * @param array $expressions */ diff --git a/tests/Security/CompositionErrorCapTest.php b/tests/Security/CompositionErrorCapTest.php index 471821be..f9eb15f4 100644 --- a/tests/Security/CompositionErrorCapTest.php +++ b/tests/Security/CompositionErrorCapTest.php @@ -13,6 +13,7 @@ use Duyler\OpenApi\Validator\SchemaValidator\AllOfValidator; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; use Duyler\OpenApi\Validator\ValidatorPool; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Override; use PHPUnit\Framework\Attributes\Test; @@ -46,7 +47,7 @@ public function composition_validator_caps_errors_at_twenty_with_summary(): void $schema = new Schema(allOf: $subSchemas); $data = []; - $context = ValidationContext::create(pool: new ValidatorPool()); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $caught = null; diff --git a/tests/Security/RedosFuzzTest.php b/tests/Security/RedosFuzzTest.php index 41ab4089..251bb633 100644 --- a/tests/Security/RedosFuzzTest.php +++ b/tests/Security/RedosFuzzTest.php @@ -15,6 +15,7 @@ use Duyler\OpenApi\Validator\SchemaValidator\ContentMediaTypeValidator; use Duyler\OpenApi\Validator\SchemaValidator\PatternValidator; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Format\BuiltinFormats; use Duyler\OpenApi\Validator\Format\FormatRegistry; @@ -57,7 +58,7 @@ public function redos_catastrophic_pattern_aborted_within_backtrack_limit(): voi $start = hrtime(true); try { - $validator->validate($payload, $schema, ValidationContext::create(pool: $this->pool)); + $validator->validate($payload, $schema, ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool))); } catch (PatternMismatchError|RuntimeException) { } $elapsedMs = (hrtime(true) - $start) / 1_000_000; @@ -142,7 +143,7 @@ public function complex_pattern_with_moderate_backtracking_still_works(): void $succeeded = false; try { - $validator->validate('foo-bar_baz', $schema, ValidationContext::create(pool: $this->pool)); + $validator->validate('foo-bar_baz', $schema, ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool))); $succeeded = true; } catch (PatternMismatchError|RuntimeException) { } diff --git a/tests/Unit/Schema/Model/SchemaConstraintGroupsTest.php b/tests/Unit/Schema/Model/SchemaConstraintGroupsTest.php index 8f9629ba..dcc2c1b4 100644 --- a/tests/Unit/Schema/Model/SchemaConstraintGroupsTest.php +++ b/tests/Unit/Schema/Model/SchemaConstraintGroupsTest.php @@ -10,6 +10,7 @@ use Duyler\OpenApi\Schema\Model\Internal\ObjectFields; use Duyler\OpenApi\Schema\Model\Internal\ScalarFields; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Schema\Model\Xml; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -436,4 +437,164 @@ public function with_override_groups_overrides_composition_fields(): void self::assertSame($newOneOf, $result->oneOf); self::assertNotNull($result->anyOf); } + + #[Test] + public function with_override_groups_flips_boolean_back_to_false(): void + { + $original = new Schema( + deprecated: true, + readOnly: true, + writeOnly: true, + hasDefault: true, + hasConst: true, + nullable: true, + ); + + $result = $original->withOverrideGroups( + scalar: new ScalarFields( + deprecated: false, + readOnly: false, + writeOnly: false, + hasDefault: false, + hasConst: false, + ), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(), + nullable: false, + ); + + self::assertFalse($result->deprecated); + self::assertFalse($result->readOnly); + self::assertFalse($result->writeOnly); + self::assertFalse($result->hasDefault); + self::assertFalse($result->hasConst); + self::assertFalse($result->nullable); + } + + #[Test] + public function with_override_groups_ref_family_replaces_ref(): void + { + $original = new Schema(ref: '#/components/schemas/Old'); + + $result = $original->withOverrideGroups( + scalar: new ScalarFields( + ref: '#/components/schemas/New', + refSummary: 'New summary', + refDescription: 'New description', + ), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(), + ); + + self::assertSame('#/components/schemas/New', $result->ref); + self::assertSame('New summary', $result->refSummary); + self::assertSame('New description', $result->refDescription); + } + + #[Test] + public function with_override_groups_replaces_schema_or_bool_union_fields(): void + { + $original = new Schema( + type: 'object', + additionalProperties: true, + unevaluatedProperties: new Schema(type: 'string'), + contentSchema: false, + ); + + $newAdditional = new Schema(type: 'integer'); + $result = $original->withOverrideGroups( + scalar: new ScalarFields(contentSchema: true), + array: new ArrayFields(), + object: new ObjectFields( + additionalProperties: $newAdditional, + unevaluatedProperties: false, + ), + composition: new CompositionFields(), + ); + + self::assertSame($newAdditional, $result->additionalProperties); + self::assertFalse($result->unevaluatedProperties); + self::assertTrue($result->contentSchema); + } + + #[Test] + public function with_override_groups_replaces_discriminator_and_xml(): void + { + $original = new Schema( + xml: new Xml(name: 'old'), + discriminator: new Discriminator(propertyName: 'type', mapping: ['a' => '#/A']), + ); + + $newXml = new Xml(name: 'new', wrapped: true); + $newDiscriminator = new Discriminator(propertyName: 'kind'); + + $result = $original->withOverrideGroups( + scalar: new ScalarFields(xml: $newXml, discriminator: $newDiscriminator), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(), + ); + + self::assertSame($newXml, $result->xml); + self::assertSame($newDiscriminator, $result->discriminator); + } + + #[Test] + public function with_override_groups_replaces_default_with_explicit_value(): void + { + $original = new Schema( + type: 'string', + default: 'old', + hasDefault: true, + ); + + $result = $original->withOverrideGroups( + scalar: new ScalarFields(default: '', hasDefault: false), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(), + ); + + self::assertSame('', $result->default); + self::assertFalse($result->hasDefault); + } + + #[Test] + public function with_override_groups_is_immutable_original_unchanged(): void + { + $original = new Schema(type: 'string', title: 'Original'); + + $result = $original->withOverrideGroups( + scalar: new ScalarFields(type: 'integer'), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(), + ); + + self::assertSame('string', $original->type); + self::assertSame('Original', $original->title); + self::assertSame('integer', $result->type); + self::assertSame('Original', $result->title); + } + + #[Test] + public function with_override_groups_chains(): void + { + $schema = new Schema(type: 'object'); + $array = new ArrayFields(); + $object = new ObjectFields(); + $composition = new CompositionFields(); + + $chained = $schema + ->withOverrideGroups(scalar: new ScalarFields(title: 'First'), array: $array, object: $object, composition: $composition) + ->withOverrideGroups(scalar: new ScalarFields(description: 'Second'), array: $array, object: $object, composition: $composition) + ->withOverrideGroups(scalar: new ScalarFields(deprecated: true), array: $array, object: $object, composition: $composition); + + self::assertSame('object', $chained->type); + self::assertSame('First', $chained->title); + self::assertSame('Second', $chained->description); + self::assertTrue($chained->deprecated); + } } diff --git a/tests/Unit/Schema/Model/SchemaWithOverridesTest.php b/tests/Unit/Schema/Model/SchemaWithOverridesTest.php deleted file mode 100644 index 671ebaff..00000000 --- a/tests/Unit/Schema/Model/SchemaWithOverridesTest.php +++ /dev/null @@ -1,268 +0,0 @@ - new Schema(type: 'integer')], - required: ['id'], - deprecated: true, - hasDefault: true, - default: 'fallback', - nullable: true, - ); - - $result = $original->withOverrides(); - - self::assertNotSame($original, $result); - self::assertSame('object', $result->type); - self::assertSame('User', $result->title); - self::assertSame(['id'], $result->required); - self::assertTrue($result->deprecated); - self::assertTrue($result->hasDefault); - self::assertSame('fallback', $result->default); - self::assertTrue($result->nullable); - } - - #[Test] - public function with_overrides_replaces_scalar_fields(): void - { - $original = new Schema(type: 'string', title: 'Old', minLength: 1); - - $result = $original->withOverrides(type: 'integer', title: 'New', minLength: 5); - - self::assertSame('integer', $result->type); - self::assertSame('New', $result->title); - self::assertSame(5, $result->minLength); - } - - #[Test] - public function with_overrides_null_keeps_original_for_nullable_scalar(): void - { - $original = new Schema(type: 'string', title: 'Keep', pattern: '^[a-z]+$'); - - $result = $original->withOverrides(type: null, title: null, pattern: null); - - self::assertSame('string', $result->type); - self::assertSame('Keep', $result->title); - self::assertSame('^[a-z]+$', $result->pattern); - } - - #[Test] - public function with_overrides_false_flips_boolean_back_to_false(): void - { - $original = new Schema( - deprecated: true, - readOnly: true, - writeOnly: true, - hasDefault: true, - hasConst: true, - nullable: true, - ); - - $result = $original->withOverrides( - deprecated: false, - readOnly: false, - writeOnly: false, - hasDefault: false, - hasConst: false, - nullable: false, - ); - - self::assertFalse($result->deprecated); - self::assertFalse($result->readOnly); - self::assertFalse($result->writeOnly); - self::assertFalse($result->hasDefault); - self::assertFalse($result->hasConst); - self::assertFalse($result->nullable); - } - - #[Test] - public function with_overrides_null_keeps_true_boolean(): void - { - $original = new Schema( - deprecated: true, - readOnly: true, - writeOnly: true, - hasDefault: true, - hasConst: true, - nullable: true, - ); - - $result = $original->withOverrides( - deprecated: null, - readOnly: null, - writeOnly: null, - hasDefault: null, - hasConst: null, - nullable: null, - ); - - self::assertTrue($result->deprecated); - self::assertTrue($result->readOnly); - self::assertTrue($result->writeOnly); - self::assertTrue($result->hasDefault); - self::assertTrue($result->hasConst); - self::assertTrue($result->nullable); - } - - #[Test] - public function with_overrides_replaces_nested_schema_and_collections(): void - { - $originalItems = new Schema(type: 'string'); - $original = new Schema( - type: 'array', - items: $originalItems, - allOf: [new Schema(type: 'object')], - properties: ['a' => new Schema(type: 'string')], - ); - - $newItems = new Schema(type: 'integer'); - $newAllOf = [new Schema(type: 'number')]; - $newProperties = ['b' => new Schema(type: 'boolean')]; - - $result = $original->withOverrides( - items: $newItems, - allOf: $newAllOf, - properties: $newProperties, - ); - - self::assertSame($newItems, $result->items); - self::assertSame($newAllOf, $result->allOf); - self::assertSame($newProperties, $result->properties); - } - - #[Test] - public function with_overrides_ref_family_replaces_ref(): void - { - $original = new Schema(ref: '#/components/schemas/Old'); - - $result = $original->withOverrides( - ref: '#/components/schemas/New', - refSummary: 'New summary', - refDescription: 'New description', - ); - - self::assertSame('#/components/schemas/New', $result->ref); - self::assertSame('New summary', $result->refSummary); - self::assertSame('New description', $result->refDescription); - } - - #[Test] - public function with_overrides_replaces_schema_or_bool_union_fields(): void - { - $original = new Schema( - type: 'object', - additionalProperties: true, - unevaluatedProperties: new Schema(type: 'string'), - contentSchema: false, - ); - - $newAdditional = new Schema(type: 'integer'); - $result = $original->withOverrides( - additionalProperties: $newAdditional, - unevaluatedProperties: false, - contentSchema: true, - ); - - self::assertSame($newAdditional, $result->additionalProperties); - self::assertFalse($result->unevaluatedProperties); - self::assertTrue($result->contentSchema); - } - - #[Test] - public function with_overrides_replaces_discriminator_and_xml(): void - { - $original = new Schema( - xml: new Xml(name: 'old'), - discriminator: new Discriminator(propertyName: 'type', mapping: ['a' => '#/A']), - ); - - $newXml = new Xml(name: 'new', wrapped: true); - $newDiscriminator = new Discriminator(propertyName: 'kind'); - - $result = $original->withOverrides(xml: $newXml, discriminator: $newDiscriminator); - - self::assertSame($newXml, $result->xml); - self::assertSame($newDiscriminator, $result->discriminator); - } - - #[Test] - public function with_overrides_null_keeps_original_for_default_and_const(): void - { - $original = new Schema( - type: 'string', - default: 'keep-default', - hasDefault: true, - const: 'keep-const', - hasConst: true, - ); - - $result = $original->withOverrides(default: null, const: null); - - self::assertSame('keep-default', $result->default); - self::assertSame('keep-const', $result->const); - self::assertTrue($result->hasDefault); - self::assertTrue($result->hasConst); - } - - #[Test] - public function with_overrides_replaces_default_with_explicit_value(): void - { - $original = new Schema( - type: 'string', - default: 'old', - hasDefault: true, - ); - - $result = $original->withOverrides(default: '', hasDefault: false); - - self::assertSame('', $result->default); - self::assertFalse($result->hasDefault); - } - - #[Test] - public function with_overrides_is_immutable_original_unchanged(): void - { - $original = new Schema(type: 'string', title: 'Original'); - - $result = $original->withOverrides(type: 'integer'); - - self::assertSame('string', $original->type); - self::assertSame('Original', $original->title); - self::assertSame('integer', $result->type); - self::assertSame('Original', $result->title); - } - - #[Test] - public function with_overrides_chains(): void - { - $schema = new Schema(type: 'object'); - - $chained = $schema - ->withOverrides(title: 'First') - ->withOverrides(description: 'Second') - ->withOverrides(deprecated: true); - - self::assertSame('object', $chained->type); - self::assertSame('First', $chained->title); - self::assertSame('Second', $chained->description); - self::assertTrue($chained->deprecated); - } -} diff --git a/tests/Unit/SchemaValidator/ReadOnlyWriteOnlyValidatorTest.php b/tests/Unit/SchemaValidator/ReadOnlyWriteOnlyValidatorTest.php index 5bc33912..2237b737 100644 --- a/tests/Unit/SchemaValidator/ReadOnlyWriteOnlyValidatorTest.php +++ b/tests/Unit/SchemaValidator/ReadOnlyWriteOnlyValidatorTest.php @@ -6,9 +6,9 @@ use Duyler\OpenApi\Validator\Schema\RefResolver; use Duyler\OpenApi\Schema\Model\Schema; -use Duyler\OpenApi\Validator\Error\BreadcrumbManager; use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\Format\BuiltinFormats; @@ -40,12 +40,11 @@ public function read_only_property_in_request_throws_exception(): void ], ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Request, - ); + )); $data = ['id' => '123', 'name' => 'test']; @@ -67,12 +66,11 @@ public function write_only_property_in_response_throws_exception(): void ], ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Response, - ); + )); $data = ['password' => 'secret', 'name' => 'test']; @@ -94,12 +92,11 @@ public function read_only_property_in_response_is_allowed(): void ], ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Response, - ); + )); $data = ['id' => '123', 'name' => 'test']; @@ -120,12 +117,11 @@ public function write_only_property_in_request_is_allowed(): void ], ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Request, - ); + )); $data = ['password' => 'secret', 'name' => 'test']; @@ -164,12 +160,11 @@ public function read_only_property_absent_in_request_succeeds(): void ], ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Request, - ); + )); $data = ['name' => 'test']; @@ -187,12 +182,11 @@ public function non_object_data_skips_validation(): void readOnly: true, ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Request, - ); + )); $validator->validate('some string', $schema, $context); @@ -205,12 +199,11 @@ public function schema_without_properties_skips_validation(): void $validator = new ReadOnlyWriteOnlyValidator(new SchemaValidatorDependencies(refResolver: new RefResolver(), statelessValidators: new StatelessValidatorRegistry($this->pool, BuiltinFormats::create()), pool: $this->pool, formatRegistry: BuiltinFormats::create())); $schema = new Schema(type: 'object'); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Request, - ); + )); $validator->validate(['foo' => 'bar'], $schema, $context); @@ -230,21 +223,19 @@ public function combined_read_write_properties_in_correct_contexts(): void ], ); - $requestContext = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $requestContext = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Request, - ); + )); $validator->validate(['password' => 'secret', 'name' => 'test'], $schema, $requestContext); - $responseContext = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $responseContext = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), mode: ValidatorMode::Response, - ); + )); $validator->validate(['id' => '123', 'name' => 'test'], $schema, $responseContext); diff --git a/tests/Unit/Validator/Error/Formatter/JsonFormatterTest.php b/tests/Unit/Validator/Error/Formatter/JsonFormatterTest.php index ed6b3a61..7c16b669 100644 --- a/tests/Unit/Validator/Error/Formatter/JsonFormatterTest.php +++ b/tests/Unit/Validator/Error/Formatter/JsonFormatterTest.php @@ -110,11 +110,6 @@ public function __construct(string $dataPath, string $schemaPath) suggestion: null, ); } - - public function getType(): string - { - return 'test'; - } }; $formatted = $this->formatter->formatMultiple([$error]); @@ -187,11 +182,6 @@ public function __construct(string $dataPath, string $schemaPath) params: ['key' => INF], ); } - - public function getType(): string - { - return 'test'; - } }; $this->expectException(ValueError::class); @@ -214,11 +204,6 @@ public function __construct(string $dataPath, string $schemaPath) params: ['key' => NAN], ); } - - public function getType(): string - { - return 'test'; - } }; $this->expectException(ValueError::class); diff --git a/tests/Unit/Validator/Error/ValidationContextTest.php b/tests/Unit/Validator/Error/ValidationContextTest.php index 7edb8001..083c68e4 100644 --- a/tests/Unit/Validator/Error/ValidationContextTest.php +++ b/tests/Unit/Validator/Error/ValidationContextTest.php @@ -4,10 +4,10 @@ namespace Duyler\OpenApi\Test\Unit\Validator\Error; -use Duyler\OpenApi\Validator\Error\BreadcrumbManager; use Duyler\OpenApi\Validator\Error\Formatter\DetailedFormatter; use Duyler\OpenApi\Validator\Error\Formatter\JsonFormatter; use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\ValidatorPool; use PHPUnit\Framework\Attributes\Test; @@ -19,7 +19,7 @@ class ValidationContextTest extends TestCase public function create_context(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $this->assertSame($pool, $context->pool); $this->assertSame('/', $context->breadcrumbs->currentPath()); @@ -29,7 +29,7 @@ public function create_context(): void public function enter_and_leave_breadcrumb(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $context->enterBreadcrumb('users'); @@ -44,7 +44,7 @@ public function enter_and_leave_breadcrumb(): void public function enter_breadcrumb_index(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $context->enterBreadcrumbIndex(0); @@ -55,7 +55,7 @@ public function enter_breadcrumb_index(): void public function chain_breadcrumbs_with_push_pop(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $context->enterBreadcrumb('users'); $this->assertSame('/users', $context->breadcrumbs->currentPath()); @@ -80,7 +80,7 @@ public function chain_breadcrumbs_with_push_pop(): void public function maintain_pool_across_mutations(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $this->assertSame($pool, $context->pool); @@ -93,7 +93,7 @@ public function maintain_pool_across_mutations(): void public function create_context_with_default_formatter(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $this->assertInstanceOf(SimpleFormatter::class, $context->errorFormatter); } @@ -103,11 +103,10 @@ public function maintain_formatter_across_mutations(): void { $pool = new ValidatorPool(); $formatter = new DetailedFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: $formatter, - ); + )); $context->enterBreadcrumb('users'); @@ -119,11 +118,10 @@ public function use_custom_formatter(): void { $pool = new ValidatorPool(); $formatter = new JsonFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: $formatter, - ); + )); $this->assertSame($formatter, $context->errorFormatter); } @@ -133,11 +131,10 @@ public function maintain_formatter_with_breadcrumb_index(): void { $pool = new ValidatorPool(); $formatter = new DetailedFormatter(); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $pool, errorFormatter: $formatter, - ); + )); $context->enterBreadcrumbIndex(0); @@ -148,7 +145,7 @@ public function maintain_formatter_with_breadcrumb_index(): void public function depth_increment_and_decrement(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $this->assertSame(0, $context->depth()); @@ -169,7 +166,7 @@ public function depth_increment_and_decrement(): void public function breadcrumb_restored_after_pop(): void { $pool = new ValidatorPool(); - $context = ValidationContext::create(pool: $pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $context->enterBreadcrumb('a'); $context->enterBreadcrumb('b'); @@ -186,7 +183,7 @@ public function breadcrumb_restored_after_pop(): void #[Test] public function mark_property_evaluated_tracks_unique_names(): void { - $context = ValidationContext::create(pool: new ValidatorPool()); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $context->markPropertyEvaluated('name'); $context->markPropertyEvaluated('id'); @@ -198,7 +195,7 @@ public function mark_property_evaluated_tracks_unique_names(): void #[Test] public function mark_item_evaluated_tracks_unique_indices(): void { - $context = ValidationContext::create(pool: new ValidatorPool()); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $context->markItemEvaluated(0); $context->markItemEvaluated(2); @@ -210,7 +207,7 @@ public function mark_item_evaluated_tracks_unique_indices(): void #[Test] public function has_property_been_evaluated_returns_true_only_for_registered_names(): void { - $context = ValidationContext::create(pool: new ValidatorPool()); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $context->markPropertyEvaluated('known'); $this->assertTrue($context->hasPropertyBeenEvaluated('known')); @@ -220,7 +217,7 @@ public function has_property_been_evaluated_returns_true_only_for_registered_nam #[Test] public function has_item_been_evaluated_returns_true_only_for_registered_indices(): void { - $context = ValidationContext::create(pool: new ValidatorPool()); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $context->markItemEvaluated(3); $this->assertTrue($context->hasItemBeenEvaluated(3)); @@ -230,7 +227,7 @@ public function has_item_been_evaluated_returns_true_only_for_registered_indices #[Test] public function fork_for_branch_starts_with_empty_annotation_state(): void { - $parent = ValidationContext::create(pool: new ValidatorPool()); + $parent = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $parent->markPropertyEvaluated('parent_only'); $parent->markItemEvaluated(0); @@ -244,7 +241,7 @@ public function fork_for_branch_starts_with_empty_annotation_state(): void public function fork_for_branch_shares_breadcrumbs_and_pool_with_parent(): void { $pool = new ValidatorPool(); - $parent = ValidationContext::create(pool: $pool); + $parent = ValidationContext::fromInit(new ValidationContextInit(pool: $pool)); $parent->enterBreadcrumb('users'); $child = $parent->forkForBranch(); @@ -256,7 +253,7 @@ public function fork_for_branch_shares_breadcrumbs_and_pool_with_parent(): void #[Test] public function merge_child_annotations_unions_property_names_and_item_indices(): void { - $parent = ValidationContext::create(pool: new ValidatorPool()); + $parent = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $parent->markPropertyEvaluated('parent'); $parent->markItemEvaluated(0); @@ -273,7 +270,7 @@ public function merge_child_annotations_unions_property_names_and_item_indices() #[Test] public function merge_child_annotations_does_not_mutate_child_state(): void { - $parent = ValidationContext::create(pool: new ValidatorPool()); + $parent = ValidationContext::fromInit(new ValidationContextInit(pool: new ValidatorPool())); $parent->markPropertyEvaluated('parent_only'); $child = $parent->forkForBranch(); diff --git a/tests/Unit/Validator/Exception/AbstractValidationErrorTest.php b/tests/Unit/Validator/Exception/AbstractValidationErrorTest.php index c8f1384f..81072721 100644 --- a/tests/Unit/Validator/Exception/AbstractValidationErrorTest.php +++ b/tests/Unit/Validator/Exception/AbstractValidationErrorTest.php @@ -6,7 +6,6 @@ use Duyler\OpenApi\Validator\Exception\ConstError; use Duyler\OpenApi\Validator\Exception\EnumError; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -170,26 +169,4 @@ public function keyword_returns_correct_value_for_enum(): void self::assertSame('enum', $exception->keyword()); } - - #[Test] - #[IgnoreDeprecations] - public function get_type_matches_keyword_for_all_subclasses(): void - { - $constException = new ConstError( - expected: 'test', - actual: 'different', - dataPath: '/field', - schemaPath: '/properties/field', - ); - - $enumException = new EnumError( - allowedValues: ['a', 'b'], - actual: 'c', - dataPath: '/field', - schemaPath: '/properties/field', - ); - - self::assertSame($constException->keyword(), $constException->getType()); - self::assertSame($enumException->keyword(), $enumException->getType()); - } } diff --git a/tests/Unit/Validator/Exception/InvalidDataTypeExceptionTest.php b/tests/Unit/Validator/Exception/InvalidDataTypeExceptionTest.php index 087b4634..dca18589 100644 --- a/tests/Unit/Validator/Exception/InvalidDataTypeExceptionTest.php +++ b/tests/Unit/Validator/Exception/InvalidDataTypeExceptionTest.php @@ -58,12 +58,6 @@ public function suggestion_returns_null(): void self::assertNull($this->exception->suggestion()); } - #[Test] - public function type_property_is_invalid(): void - { - self::assertSame('invalid', $this->exception->type); - } - #[Test] public function inherits_invalid_argument_exception(): void { diff --git a/tests/Unit/Validator/Exception/InvalidMultipleOfSchemaExceptionTest.php b/tests/Unit/Validator/Exception/InvalidMultipleOfSchemaExceptionTest.php deleted file mode 100644 index 28770869..00000000 --- a/tests/Unit/Validator/Exception/InvalidMultipleOfSchemaExceptionTest.php +++ /dev/null @@ -1,33 +0,0 @@ -getMessage()); - self::assertStringContainsString('0.0001', $exception->getMessage()); - self::assertStringContainsString('BCMath', $exception->getMessage()); - } -} diff --git a/tests/Unit/Validator/Exception/ValidationExceptionSubclassTest.php b/tests/Unit/Validator/Exception/ValidationExceptionSubclassTest.php index bcab88da..5c9db5b4 100644 --- a/tests/Unit/Validator/Exception/ValidationExceptionSubclassTest.php +++ b/tests/Unit/Validator/Exception/ValidationExceptionSubclassTest.php @@ -68,11 +68,6 @@ public function suggestion(): ?string { return null; } - - public function getType(): string - { - return 'type'; - } }; $subclass = new class ('subclass', 0, null, [$formatError]) extends ValidationException { diff --git a/tests/Unit/Validator/Schema/ContextValidatorsErrorAccumulationTest.php b/tests/Unit/Validator/Schema/ContextValidatorsErrorAccumulationTest.php index 1e6add70..3c4b6793 100644 --- a/tests/Unit/Validator/Schema/ContextValidatorsErrorAccumulationTest.php +++ b/tests/Unit/Validator/Schema/ContextValidatorsErrorAccumulationTest.php @@ -8,6 +8,7 @@ use Duyler\OpenApi\Schema\Model\InfoObject; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\Format\BuiltinFormats; @@ -53,7 +54,7 @@ public function items_validator_accumulates_errors_for_invalid_items(): void ), ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $data = ['ab', 'cd', 'valid_string']; @@ -72,7 +73,7 @@ public function items_validator_passes_for_valid_items(): void items: new Schema(type: 'string'), ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator->validateWithContext(['hello', 'world'], $schema, $context); @@ -85,7 +86,7 @@ public function items_validator_skips_when_no_items_schema(): void $validator = new ItemsValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); $schema = new Schema(type: 'array'); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator->validateWithContext(['a', 'b'], $schema, $context); @@ -102,7 +103,7 @@ public function items_validator_reports_single_error_for_one_invalid_item(): voi items: new Schema(type: 'integer'), ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); try { $validator->validateWithContext(['not_int'], $schema, $context); @@ -125,7 +126,7 @@ public function properties_validator_accumulates_errors_for_invalid_properties() ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $data = ['name' => 'ab', 'email' => 'not-an-email']; @@ -146,7 +147,7 @@ public function properties_validator_passes_for_valid_data(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator->validateWithContext(['name' => 'John'], $schema, $context); @@ -166,7 +167,7 @@ public function properties_validator_skips_missing_optional_properties(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator->validateWithContext(['name' => 'John'], $schema, $context); @@ -179,7 +180,7 @@ public function properties_validator_skips_when_no_properties(): void $validator = new PropertiesValidatorWithContext(document: $this->document, dependencies: new SchemaValidatorDependencies(pool: $this->pool, refResolver: $this->refResolver, statelessValidators: $this->statelessValidators)); $schema = new Schema(type: 'object'); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $validator->validateWithContext(['key' => 'value'], $schema, $context); @@ -199,7 +200,7 @@ public function properties_validator_reports_errors_for_multiple_invalid_propert ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); try { $validator->validateWithContext(['a' => 'string', 'b' => 'also_string'], $schema, $context); diff --git a/tests/Unit/Validator/Schema/ContextValidatorsIntegrationTest.php b/tests/Unit/Validator/Schema/ContextValidatorsIntegrationTest.php index adc802fb..8bb93aa3 100644 --- a/tests/Unit/Validator/Schema/ContextValidatorsIntegrationTest.php +++ b/tests/Unit/Validator/Schema/ContextValidatorsIntegrationTest.php @@ -15,7 +15,7 @@ use Duyler\OpenApi\Validator\Schema\RefResolver; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; use Duyler\OpenApi\Validator\ValidatorPool; -use Duyler\OpenApi\Validator\Error\BreadcrumbManager; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Error\Formatter\SimpleFormatter; use PHPUnit\Framework\Attributes\Test; @@ -50,12 +50,11 @@ public function items_validate_with_context_array_type_error(): void items: new Schema(type: 'integer'), ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), nullableAsType: false, - ); + )); $caught = false; try { @@ -80,12 +79,11 @@ public function properties_validate_with_context_type_error(): void ], ); - $context = new ValidationContext( - breadcrumbs: BreadcrumbManager::create(), + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, errorFormatter: new SimpleFormatter(), nullableAsType: false, - ); + )); $caught = false; try { diff --git a/tests/Unit/Validator/Schema/CycleDetectionWeakMapRegressionTest.php b/tests/Unit/Validator/Schema/CycleDetectionWeakMapRegressionTest.php index 4e3bd335..4c7d25e8 100644 --- a/tests/Unit/Validator/Schema/CycleDetectionWeakMapRegressionTest.php +++ b/tests/Unit/Validator/Schema/CycleDetectionWeakMapRegressionTest.php @@ -6,6 +6,10 @@ use Duyler\OpenApi\Schema\Model\Components; use Duyler\OpenApi\Schema\Model\InfoObject; +use Duyler\OpenApi\Schema\Model\Internal\ArrayFields; +use Duyler\OpenApi\Schema\Model\Internal\CompositionFields; +use Duyler\OpenApi\Schema\Model\Internal\ObjectFields; +use Duyler\OpenApi\Schema\Model\Internal\ScalarFields; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; @@ -154,7 +158,12 @@ public function schema_validator_resolves_composition_with_cycle_and_gc_without_ private function createSchemaSelfReferencingViaComposition(): Schema { $schema = new Schema(type: 'object'); - $schema = $schema->withOverrides(oneOf: [$schema]); + $schema = $schema->withOverrideGroups( + scalar: new ScalarFields(), + array: new ArrayFields(), + object: new ObjectFields(), + composition: new CompositionFields(oneOf: [$schema]), + ); return $schema; } diff --git a/tests/Unit/Validator/Schema/StatelessValidatorDispatcherTest.php b/tests/Unit/Validator/Schema/StatelessValidatorDispatcherTest.php index d6bb60f3..f5691bea 100644 --- a/tests/Unit/Validator/Schema/StatelessValidatorDispatcherTest.php +++ b/tests/Unit/Validator/Schema/StatelessValidatorDispatcherTest.php @@ -11,6 +11,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\AbstractValidationError; use Duyler\OpenApi\Validator\Exception\InvalidFormatException; @@ -57,19 +58,19 @@ public function validate_honors_caller_context_nullable_as_type(): void $dispatcher = $this->createDispatcher(); $schema = new Schema(type: 'string', nullable: true); - $lenient = ValidationContext::create( + $lenient = ValidationContext::fromInit(new ValidationContextInit( pool: new ValidatorPool(), nullableAsType: true, - ); + )); $dispatcher->validate(null, $schema, $lenient); $this->addToAssertionCount(1); $this->expectException(TypeMismatchError::class); - $strict = ValidationContext::create( + $strict = ValidationContext::fromInit(new ValidationContextInit( pool: new ValidatorPool(), nullableAsType: false, - ); + )); $dispatcher->validate(null, $schema, $strict); } diff --git a/tests/Unit/Validator/Schema/UnevaluatedPropertiesWithDiscriminatorTest.php b/tests/Unit/Validator/Schema/UnevaluatedPropertiesWithDiscriminatorTest.php index ef6f7f25..02c807f2 100644 --- a/tests/Unit/Validator/Schema/UnevaluatedPropertiesWithDiscriminatorTest.php +++ b/tests/Unit/Validator/Schema/UnevaluatedPropertiesWithDiscriminatorTest.php @@ -10,6 +10,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\Exception\UnevaluatedPropertyError; @@ -80,7 +81,7 @@ public function discriminator_target_properties_are_propagated_to_parent_context components: new Components(schemas: ['Pet' => $petSchema, 'Cat' => $catSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $this->discriminatorValidator->validate( ['petType' => 'cat', 'name' => 'Whiskers'], @@ -126,7 +127,7 @@ public function discriminator_property_alone_is_evaluated_when_target_has_no_oth components: new Components(schemas: ['Parent' => $parentSchema, 'Target' => $targetSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $this->discriminatorValidator->validate( ['petType' => 'cat'], @@ -166,7 +167,7 @@ public function additional_properties_integer_in_target_are_propagated_to_parent components: new Components(schemas: ['Parent' => $parentSchema, 'Target' => $targetSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $this->discriminatorValidator->validate( ['kind' => 'numbered', 'extra' => 42], @@ -207,7 +208,7 @@ public function invalid_target_input_still_throws_type_mismatch_error(): void components: new Components(schemas: ['Pet' => $petSchema, 'Cat' => $catSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $this->expectException(ValidationException::class); @@ -255,7 +256,7 @@ public function failed_target_validation_does_not_merge_annotations_into_parent( components: new Components(schemas: ['Pet' => $petSchema, 'Cat' => $catSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $caught = null; @@ -309,7 +310,7 @@ public function parent_depth_is_unchanged_after_discriminator_routing(): void components: new Components(schemas: ['Pet' => $petSchema, 'Cat' => $catSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $parentContext->incrementDepth(); $depthBefore = $parentContext->depth(); @@ -400,7 +401,7 @@ public function default_mapping_route_propagates_annotations_to_parent_context() components: new Components(schemas: ['Pet' => $petSchema, 'Generic' => $genericSchema]), ); - $parentContext = ValidationContext::create($this->pool); + $parentContext = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $this->discriminatorValidator->validate( ['anything' => 'value'], diff --git a/tests/Unit/Validator/SchemaValidator/AllOfValidatorTest.php b/tests/Unit/Validator/SchemaValidator/AllOfValidatorTest.php index b2768348..b0993acf 100644 --- a/tests/Unit/Validator/SchemaValidator/AllOfValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/AllOfValidatorTest.php @@ -10,6 +10,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\ValidationException; use Duyler\OpenApi\Validator\ValidatorPool; @@ -262,7 +263,7 @@ public function all_of_rejects_null_when_parent_nullable_is_not_honored(): void allOf: [new Schema(type: 'object', required: ['id'])], ); - $context = ValidationContext::create($this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(ValidationException::class); diff --git a/tests/Unit/Validator/SchemaValidator/AnyOfValidatorTest.php b/tests/Unit/Validator/SchemaValidator/AnyOfValidatorTest.php index 312ca0ab..92f662da 100644 --- a/tests/Unit/Validator/SchemaValidator/AnyOfValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/AnyOfValidatorTest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase; use stdClass; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; #[CoversClass(AnyOfValidator::class)] @@ -190,7 +191,7 @@ public function validate_any_of_with_null_value_and_nullable_schema(): void anyOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(null, $schema, $context); $this->expectNotToPerformAssertions(); @@ -205,7 +206,7 @@ public function throw_error_for_null_without_nullable_schema(): void anyOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(ValidationException::class); $this->validator->validate(null, $schema, $context); @@ -220,7 +221,7 @@ public function validate_any_of_with_context(): void anyOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate('hello', $schema, $context); $this->expectNotToPerformAssertions(); @@ -236,7 +237,7 @@ public function any_of_passes_when_multiple_nullable_schemas_match_null(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(null, $schema, $context); $this->expectNotToPerformAssertions(); @@ -263,7 +264,7 @@ public function any_of_rejects_null_when_parent_nullable_is_not_honored(): void anyOf: [new Schema(type: 'object', required: ['id'])], ); - $context = ValidationContext::create($this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(ValidationException::class); diff --git a/tests/Unit/Validator/SchemaValidator/CompositionBranchOrderIndependenceTest.php b/tests/Unit/Validator/SchemaValidator/CompositionBranchOrderIndependenceTest.php index f6961cbb..f0d4c68f 100644 --- a/tests/Unit/Validator/SchemaValidator/CompositionBranchOrderIndependenceTest.php +++ b/tests/Unit/Validator/SchemaValidator/CompositionBranchOrderIndependenceTest.php @@ -7,6 +7,7 @@ use Duyler\OpenApi\Validator\Schema\RefResolver; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\OneOfError; use Duyler\OpenApi\Validator\Exception\TooManyErrorsError; @@ -219,6 +220,6 @@ private function data(): array private function context(): ValidationContext { - return ValidationContext::create($this->pool); + return ValidationContext::fromInit(new ValidationContextInit($this->pool)); } } diff --git a/tests/Unit/Validator/SchemaValidator/DeprecatedValidatorTest.php b/tests/Unit/Validator/SchemaValidator/DeprecatedValidatorTest.php index 661ed2ff..d3f64ebd 100644 --- a/tests/Unit/Validator/SchemaValidator/DeprecatedValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/DeprecatedValidatorTest.php @@ -9,6 +9,7 @@ use Duyler\OpenApi\Event\ValidationWarningEvent; use Duyler\OpenApi\Event\ArrayDispatcher; use Duyler\OpenApi\Schema\Model\Schema; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\SchemaValidator\DeprecatedValidator; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; @@ -251,7 +252,7 @@ function (ValidationWarningEvent $event) use (&$warningReceived): void { ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $context->enterBreadcrumb('root'); $validator->validate(['oldField' => 'value'], $schema, $context); diff --git a/tests/Unit/Validator/SchemaValidator/IfThenElseValidatorTest.php b/tests/Unit/Validator/SchemaValidator/IfThenElseValidatorTest.php index a6728f33..7664d3a9 100644 --- a/tests/Unit/Validator/SchemaValidator/IfThenElseValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/IfThenElseValidatorTest.php @@ -10,6 +10,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\InvalidDataTypeException; use Duyler\OpenApi\Validator\Exception\MaximumError; @@ -184,7 +185,7 @@ public function apply_branches_to_null_when_parent_nullable_is_not_honored(): vo else: new Schema(type: 'object', required: ['id']), ); - $context = ValidationContext::create($this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(InvalidDataTypeException::class); diff --git a/tests/Unit/Validator/SchemaValidator/ItemsValidatorTest.php b/tests/Unit/Validator/SchemaValidator/ItemsValidatorTest.php index 24bfe6a8..03245d30 100644 --- a/tests/Unit/Validator/SchemaValidator/ItemsValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/ItemsValidatorTest.php @@ -19,6 +19,7 @@ use PHPUnit\Framework\TestCase; use stdClass; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Format\BuiltinFormats; @@ -208,7 +209,7 @@ public function validate_items_with_nullable_and_context(): void items: $itemSchema, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(['a', null, 'b'], $schema, $context); $this->expectNotToPerformAssertions(); @@ -223,7 +224,7 @@ public function validate_items_with_nullable_context(): void items: $itemSchema, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(['hello', 'world'], $schema, $context); $this->expectNotToPerformAssertions(); @@ -255,7 +256,7 @@ public function validate_items_with_context(): void items: $itemSchema, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate([1, 2, 3], $schema, $context); $this->expectNotToPerformAssertions(); diff --git a/tests/Unit/Validator/SchemaValidator/ObjectLengthValidatorTest.php b/tests/Unit/Validator/SchemaValidator/ObjectLengthValidatorTest.php index f215dcf1..deceb5d2 100644 --- a/tests/Unit/Validator/SchemaValidator/ObjectLengthValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/ObjectLengthValidatorTest.php @@ -11,6 +11,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\EmptyArrayStrategy; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\MaxPropertiesError; use Duyler\OpenApi\Validator\Exception\MinPropertiesError; @@ -147,10 +148,10 @@ public function count_numeric_array_keys(): void public function skip_empty_array_for_object_when_strategy_prefers_array(): void { $schema = new Schema(type: 'object', minProperties: 1); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferArray, - ); + )); $this->validator->validate([], $schema, $context); @@ -161,10 +162,10 @@ public function skip_empty_array_for_object_when_strategy_prefers_array(): void public function throw_min_properties_error_for_empty_array_when_strategy_allows_both(): void { $schema = new Schema(type: 'object', minProperties: 1); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::AllowBoth, - ); + )); $this->expectException(MinPropertiesError::class); @@ -175,10 +176,10 @@ public function throw_min_properties_error_for_empty_array_when_strategy_allows_ public function throw_min_properties_error_for_empty_array_when_strategy_prefers_object(): void { $schema = new Schema(type: 'object', minProperties: 1); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferObject, - ); + )); $this->expectException(MinPropertiesError::class); @@ -189,10 +190,10 @@ public function throw_min_properties_error_for_empty_array_when_strategy_prefers public function skip_non_empty_list_for_object_regardless_of_strategy(): void { $schema = new Schema(type: 'object', minProperties: 1); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferArray, - ); + )); $this->validator->validate([1, 2, 3], $schema, $context); @@ -203,10 +204,10 @@ public function skip_non_empty_list_for_object_regardless_of_strategy(): void public function validate_associative_array_with_min_properties_for_any_strategy(): void { $schema = new Schema(type: 'object', minProperties: 1); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferArray, - ); + )); $this->validator->validate(['a' => 1], $schema, $context); diff --git a/tests/Unit/Validator/SchemaValidator/OneOfValidatorTest.php b/tests/Unit/Validator/SchemaValidator/OneOfValidatorTest.php index a73b70cb..738ea623 100644 --- a/tests/Unit/Validator/SchemaValidator/OneOfValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/OneOfValidatorTest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; #[CoversClass(OneOfValidator::class)] @@ -173,7 +174,7 @@ public function validate_one_of_with_null_value_and_nullable_schema(): void oneOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(null, $schema, $context); $this->expectNotToPerformAssertions(); @@ -188,7 +189,7 @@ public function throw_error_for_null_without_nullable_schema_in_one_of(): void oneOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(ValidationException::class); $this->validator->validate(null, $schema, $context); @@ -203,7 +204,7 @@ public function throw_one_of_error_for_multiple_schemas_matching_with_context(): oneOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(OneOfError::class); $this->validator->validate('hello', $schema, $context); @@ -218,7 +219,7 @@ public function validate_one_of_with_context(): void oneOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(42, $schema, $context); $this->expectNotToPerformAssertions(); @@ -233,7 +234,7 @@ public function throw_validation_exception_for_invalid_data_type_in_subschema_wi oneOf: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(ValidationException::class); $this->expectExceptionMessage('Exactly one of the schemas must match, but none did'); @@ -250,7 +251,7 @@ public function one_of_throws_when_multiple_nullable_schemas_match_null(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->expectException(OneOfError::class); @@ -267,7 +268,7 @@ public function one_of_passes_when_single_nullable_schema_matches_null(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $this->validator->validate(null, $schema, $context); $this->expectNotToPerformAssertions(); @@ -297,7 +298,7 @@ public function one_of_rejects_null_when_parent_nullable_is_not_honored(): void oneOf: [new Schema(type: 'object', required: ['id'])], ); - $context = ValidationContext::create($this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: false)); $this->expectException(ValidationException::class); diff --git a/tests/Unit/Validator/SchemaValidator/PrefixItemsValidatorTest.php b/tests/Unit/Validator/SchemaValidator/PrefixItemsValidatorTest.php index ed8038d7..8eac9b81 100644 --- a/tests/Unit/Validator/SchemaValidator/PrefixItemsValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/PrefixItemsValidatorTest.php @@ -9,6 +9,7 @@ use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\Exception\ValidationException; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Format\BuiltinFormats; use Duyler\OpenApi\Validator\SchemaValidator\PrefixItemsValidator; @@ -366,7 +367,7 @@ public function validate_prefix_items_with_nullable_prefix_item(): void prefixItems: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -390,7 +391,7 @@ public function validate_prefix_items_with_nullable_items(): void items: $itemsSchema, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { @@ -413,7 +414,7 @@ public function validate_prefix_items_with_context(): void prefixItems: [$schema1, $schema2], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; try { diff --git a/tests/Unit/Validator/SchemaValidator/PropertiesValidatorTest.php b/tests/Unit/Validator/SchemaValidator/PropertiesValidatorTest.php index 1f923069..14e6b1f1 100644 --- a/tests/Unit/Validator/SchemaValidator/PropertiesValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/PropertiesValidatorTest.php @@ -20,6 +20,7 @@ use RuntimeException; use stdClass; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Format\BuiltinFormats; @@ -337,7 +338,7 @@ public function validate_properties_with_nullable_and_context(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; @@ -364,7 +365,7 @@ public function validate_properties_with_nullable_value(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; @@ -389,7 +390,7 @@ public function validate_properties_with_context(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; @@ -416,7 +417,7 @@ public function validate_properties_with_multiple_nullable(): void ], ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; diff --git a/tests/Unit/Validator/SchemaValidator/TypeValidatorTest.php b/tests/Unit/Validator/SchemaValidator/TypeValidatorTest.php index eec353ef..8ddaa467 100644 --- a/tests/Unit/Validator/SchemaValidator/TypeValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/TypeValidatorTest.php @@ -11,6 +11,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\EmptyArrayStrategy; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\ValidatorPool; @@ -408,10 +409,10 @@ public function validate_nullable_string_allows_null(): void public function validate_array_type_with_empty_array_and_prefer_array_strategy(): void { $schema = new Schema(type: 'array'); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferArray, - ); + )); $succeeded = false; @@ -429,10 +430,10 @@ public function validate_array_type_with_empty_array_and_prefer_array_strategy() public function throw_type_mismatch_error_for_empty_array_when_strategy_prefers_object(): void { $schema = new Schema(type: 'array'); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferObject, - ); + )); $this->expectException(TypeMismatchError::class); @@ -443,10 +444,10 @@ public function throw_type_mismatch_error_for_empty_array_when_strategy_prefers_ public function throw_type_mismatch_error_for_empty_array_when_strategy_rejects(): void { $schema = new Schema(type: 'array'); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::Reject, - ); + )); $this->expectException(TypeMismatchError::class); @@ -457,10 +458,10 @@ public function throw_type_mismatch_error_for_empty_array_when_strategy_rejects( public function validate_object_type_with_empty_array_and_prefer_object_strategy(): void { $schema = new Schema(type: 'object'); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferObject, - ); + )); $succeeded = false; @@ -478,10 +479,10 @@ public function validate_object_type_with_empty_array_and_prefer_object_strategy public function throw_type_mismatch_error_for_empty_array_as_object_when_strategy_prefers_array(): void { $schema = new Schema(type: 'object'); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::PreferArray, - ); + )); $this->expectException(TypeMismatchError::class); @@ -492,10 +493,10 @@ public function throw_type_mismatch_error_for_empty_array_as_object_when_strateg public function throw_type_mismatch_error_for_empty_array_as_object_when_strategy_rejects(): void { $schema = new Schema(type: 'object'); - $context = ValidationContext::create( + $context = ValidationContext::fromInit(new ValidationContextInit( pool: $this->pool, emptyArrayStrategy: EmptyArrayStrategy::Reject, - ); + )); $this->expectException(TypeMismatchError::class); @@ -506,7 +507,7 @@ public function throw_type_mismatch_error_for_empty_array_as_object_when_strateg public function rejects_null_when_type_array_contains_null_and_nullable_as_type_disabled(): void { $schema = new Schema(type: ['string', 'null']); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: false)); $this->expectException(TypeMismatchError::class); @@ -517,7 +518,7 @@ public function rejects_null_when_type_array_contains_null_and_nullable_as_type_ public function accepts_string_when_type_array_contains_null_and_nullable_as_type_disabled(): void { $schema = new Schema(type: ['string', 'null']); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: false); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: false)); $succeeded = false; @@ -535,7 +536,7 @@ public function accepts_string_when_type_array_contains_null_and_nullable_as_typ public function accepts_null_when_type_array_contains_null_with_default_nullable_as_type(): void { $schema = new Schema(type: ['string', 'null']); - $context = ValidationContext::create(pool: $this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, nullableAsType: true)); $succeeded = false; diff --git a/tests/Unit/Validator/SchemaValidator/UnevaluatedItemsValidatorTest.php b/tests/Unit/Validator/SchemaValidator/UnevaluatedItemsValidatorTest.php index ac988d02..b11e416a 100644 --- a/tests/Unit/Validator/SchemaValidator/UnevaluatedItemsValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/UnevaluatedItemsValidatorTest.php @@ -19,6 +19,7 @@ use PHPUnit\Framework\TestCase; use RuntimeException; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use function sprintf; @@ -269,7 +270,7 @@ public function validate_unevaluated_items_with_context(): void unevaluatedItems: $unevaluatedSchema, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $succeeded = false; @@ -342,7 +343,7 @@ public function unevaluated_items_with_contains_only_fails_unevaluated_index(): unevaluatedItems: $unevaluated, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $context->markItemEvaluated(0); $context->markItemEvaluated(1); @@ -388,7 +389,7 @@ public function unevaluated_items_uses_composition_annotations_from_context(): v unevaluatedItems: $unevaluated, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $context->markItemEvaluated(0); $context->markItemEvaluated(1); $context->markItemEvaluated(2); @@ -459,7 +460,7 @@ public function unevaluated_items_out_of_range_annotations_are_ignored(): void unevaluatedItems: $unevaluated, ); - $context = ValidationContext::create($this->pool, nullableAsType: true); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool, nullableAsType: true)); $context->markItemEvaluated(0); $context->markItemEvaluated(99); diff --git a/tests/Unit/Validator/SchemaValidator/UnevaluatedPropertiesValidatorTest.php b/tests/Unit/Validator/SchemaValidator/UnevaluatedPropertiesValidatorTest.php index 86586b71..40cf652f 100644 --- a/tests/Unit/Validator/SchemaValidator/UnevaluatedPropertiesValidatorTest.php +++ b/tests/Unit/Validator/SchemaValidator/UnevaluatedPropertiesValidatorTest.php @@ -7,6 +7,7 @@ use Duyler\OpenApi\Validator\Schema\RefResolver; use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Validator\Schema\StatelessValidatorRegistry; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\TypeMismatchError; use Duyler\OpenApi\Validator\Exception\UnevaluatedPropertyError; @@ -615,7 +616,7 @@ public function unevaluated_properties_with_context_annotations_passes(): void unevaluatedProperties: false, ); - $context = ValidationContext::create($this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $context->markPropertyEvaluated('name'); $succeeded = false; @@ -638,7 +639,7 @@ public function unevaluated_properties_with_partial_context_annotations_fails_on unevaluatedProperties: false, ); - $context = ValidationContext::create($this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $context->markPropertyEvaluated('known'); $this->expectException(UnevaluatedPropertyError::class); @@ -658,7 +659,7 @@ public function unevaluated_properties_merges_static_and_annotation_evaluated(): unevaluatedProperties: false, ); - $context = ValidationContext::create($this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $context->markPropertyEvaluated('from_annotation'); $succeeded = false; @@ -685,7 +686,7 @@ public function unevaluated_properties_with_pattern_properties_and_annotations() unevaluatedProperties: false, ); - $context = ValidationContext::create($this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $context->markPropertyEvaluated('annotated'); $succeeded = false; @@ -731,7 +732,7 @@ public function unevaluated_properties_with_schema_uses_annotation_set(): void unevaluatedProperties: $unevaluatedSchema, ); - $context = ValidationContext::create($this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $context->markPropertyEvaluated('evaluated_by_branch'); $succeeded = false; @@ -775,7 +776,7 @@ public function unevaluated_properties_fails_on_truly_unevaluated(): void unevaluatedProperties: false, ); - $context = ValidationContext::create($this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit($this->pool)); $this->expectException(UnevaluatedPropertyError::class); diff --git a/tests/Unit/Validator/SchemaValidator/ValidationExceptionErrorsTest.php b/tests/Unit/Validator/SchemaValidator/ValidationExceptionErrorsTest.php index d863dc4c..431c23fc 100644 --- a/tests/Unit/Validator/SchemaValidator/ValidationExceptionErrorsTest.php +++ b/tests/Unit/Validator/SchemaValidator/ValidationExceptionErrorsTest.php @@ -10,6 +10,7 @@ use Duyler\OpenApi\Schema\Model\Schema; use Duyler\OpenApi\Schema\OpenApiDocument; use Duyler\OpenApi\Validator\Dto\SchemaValidatorDependencies; +use Duyler\OpenApi\Validator\Error\Internal\ValidationContextInit; use Duyler\OpenApi\Validator\Error\ValidationContext; use Duyler\OpenApi\Validator\Exception\DiscriminatorDataError; use Duyler\OpenApi\Validator\Exception\InvalidDataTypeException; @@ -73,7 +74,7 @@ public function read_only_violation_has_errors_array(): void ], ); - $context = ValidationContext::create(pool: $this->pool, mode: ValidatorMode::Request); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, mode: ValidatorMode::Request)); $caught = null; try { @@ -103,7 +104,7 @@ public function write_only_violation_has_errors_array(): void ], ); - $context = ValidationContext::create(pool: $this->pool, mode: ValidatorMode::Response); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool, mode: ValidatorMode::Response)); $caught = null; try { @@ -142,7 +143,7 @@ public function oneof_discriminator_non_object_has_errors_array(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $caught = null; try { @@ -180,7 +181,7 @@ public function oneof_discriminator_null_data_has_errors_array(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $caught = null; try { @@ -216,7 +217,7 @@ public function oneof_multiple_match_has_errors_array(): void ], ); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $caught = null; try { @@ -625,7 +626,7 @@ public function oneof_discriminator_in_resolved_schema_has_errors_array(): void ); $resolvedSchema = $this->refResolver->resolve('#/components/schemas/Pet', $document); - $context = ValidationContext::create(pool: $this->pool); + $context = ValidationContext::fromInit(new ValidationContextInit(pool: $this->pool)); $caught = null; try {