[BUG] [php-symfony] constraint Valid cannot be nested
Created by: BenjaminHae
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When creating an requestBody
that contains a schema with an Array of Object, the generated code for php-symfony
raises an error when calling the associated operation. The error is:
The constraint Valid cannot be nested inside constraint Symfony\Component\Validator\Constraints\All. You can only declare the Valid constraint directly on a field or method.
openapi-generator version
dockerhub: latest
OpenAPI declaration file content or url
openapi: 3.0.0
info:
description: Test
version: 0.0.1
title: Test
tags:
- name: test
description: test
paths:
/test:
put:
tags:
- test
summary: test
operationId: test
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/TestArray"
required: true
responses:
"200":
description: successful operation
components:
schemas:
TestObject:
type: object
properties:
name:
type: string
TestArray:
type: array
items:
$ref: "#/components/schemas/TestObject"
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -i /local/OpenAPIDescription.yaml -g php-symfony -o /local/OpenAPIServerBundle
Steps to reproduce
Generate the code from the declaration above. Use it in a symfony project(current stable version 4.3), implement the interfaces, empty methods are ok.
Run http PUT
against /test.
Related issues/PRs
Suggest a fix
The relevant lines in the generated code are in OpenAPI\Server\Controller\TestController.testAction
$asserts = [];
$asserts[] = new Assert\NotNull();
$asserts[] = new Assert\All([
new Assert\Type("OpenAPI\Server\Model\TestObject"),
new Assert\Valid(),
]);
Removing the new Assert\Valid()
line fixes it. Moving it to the bottom as in the following example also works:
$asserts = [];
$asserts[] = new Assert\NotNull();
$asserts[] = new Assert\All([
new Assert\Type("OpenAPI\Server\Model\TestObject"),
]);
$asserts[] = new Assert\Valid(),
I don't know however whether this achieves the desired validation.