Skip to content

[OpenAPI/Hydra] Validation error schema should be generated #4480

Open
@alanpoulain

Description

@alanpoulain

Description

In OpenApiFactory, the schema is not generated for the validation error (422):

$responses['422'] = new Model\Response('Unprocessable entity');

It would be nice to add it at least for Hydra.
Hydra normalizes the validation error like this:

'@context' => $this->urlGenerator->generate('api_jsonld_context', ['shortName' => 'ConstraintViolationList']),
'@type' => 'ConstraintViolationList',
'hydra:title' => $context['title'] ?? 'An error occurred',
'hydra:description' => $messages ? implode("\n", $messages) : (string) $object,
'violations' => $violations,

One way to implement it would be to add a new schema type, like TYPE_VALIDATION_ERROR here:

public const TYPE_INPUT = 'input';
public const TYPE_OUTPUT = 'output';

And handle this new type in this method:

public function buildSchema(string $className, string $format = 'jsonld', string $type = Schema::TYPE_OUTPUT, ?string $operationType = null, ?string $operationName = null, ?Schema $schema = null, ?array $serializerContext = null, bool $forceCollection = false): Schema

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions