NelmioApiDocBundle icon indicating copy to clipboard operation
NelmioApiDocBundle copied to clipboard

OA\Property as attribute doesn't work, annotation does

Open arjanfrans opened this issue 3 years ago • 7 comments

image

I have a model here that I just tried migration to attributes, but I noticed that the OA\Property doesn't work correctly as an attribute.

With annotation: image

With attribute: image

arjanfrans avatar Apr 28 '22 07:04 arjanfrans

Hello,

Are you using the latest versions of both zircote/swagger-php and NelmioApiDocBundle?

GuilhemN avatar Apr 28 '22 13:04 GuilhemN

zircote/swagger-php 4.3.0
nelmio/api-doc-bundle v4.8.2 (and I also tried dev-master)

arjanfrans avatar Apr 28 '22 13:04 arjanfrans

Interesting that your example works at all without a Schema annotation on the class itself!

Using swagger-php directly on the command line with the following file I get the same for annotation and attribute, so I would suspect the issue is somewhere else.

<?php

use OpenApi\Annotations as OA;
use OpenApi\Attributes as OAT;

/**
 * @OA\Schema()
 */
class Model
{
    /**
     * @OA\Property(example=123)
     */
    private int $annId;

    #[OAT\Property(example: 222)]
    private int $attId;
}

Running openapi:

$ ./bin/openapi -b scratch/prop_example.php scratch/prop_example.php 
Warning: Required @OA\Info() not found
Warning: Required @OA\PathItem() not found
openapi: 3.0.0
components:
  schemas:
    Model:
      properties:
        annId:
          type: integer
          example: 123
        attId:
          type: integer
          example: 222
      type: object

DerManoMann avatar Apr 28 '22 20:04 DerManoMann

My controller annotations look like this:

image

I suspect that it is something related to the Nelmio\ApiDocBundle\Annotation\Model class

arjanfrans avatar Apr 29 '22 07:04 arjanfrans

Hmm, yes, that is possible. Its a pain to get both behaving the same and mixing attributes/annotations from different libraries doesn't make it any easier.

DerManoMann avatar Apr 29 '22 08:04 DerManoMann

As far as I can see, the "ModelDescriber" logic doesn't do anything with attributes.

arjanfrans avatar Apr 29 '22 08:04 arjanfrans

You could try to isolate the issue by reducing the code to avoid using bundle annotations while keeping the error. Then you could compare the openapi output with the bundle, I suppose.

DerManoMann avatar Apr 29 '22 08:04 DerManoMann