Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2708
Closed
Open
Issue created Apr 20, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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.

Assignee
Assign to
Time tracking