zircote / swagger-php

A php swagger annotation and parsing library
http://zircote.github.io/swagger-php/
Apache License 2.0
5.07k stars 933 forks source link

Using Get atribute does not add documentation and does not give any error #1655

Open darius-v opened 5 days ago

darius-v commented 5 days ago

Example with annotations: https://zircote.github.io/swagger-php/guide/cookbook.html#reusing-responses

/**
 * @OA\Response(
 *   response="product",
 *   description="All information about a product",
 *   @OA\JsonContent(ref="#/components/schemas/Product")
 * )
 */
class ProductResponse {}

 // ...

class ProductController
{
    /**
     * @OA\Get(
     *   tags={"Products"},
     *   path="/products/{product_id}",
     *   @OA\Response(
     *       response="default",
     *       ref="#/components/responses/product"
     *   )
     * )
     */
    public function getProduct($id)
    {
    }
}

Based on the example I have made minimal code. Just added Areas attribute, because in my project without that tag it never shows up. And this does not show up anyway:

#[OA\Get(summary: 'Get orders belonging to a seller', path: '/sellers/{sellerId}/orders1', tags: ['Couriers'])]
    #[Areas(['public'])]
    public function getSellerOrdersAction1(
        Request $request,
        int $sellerId,

    ): Response {

    }

If I do this, it works:

#[Route( 
        path: '/{version}/sellers/{sellerId}/orders1',
        name: 'get_seller_orders1',
        requirements: ['version' => '%supported_versions%'],
        methods: ['GET']
    )]
    #[OA\Tag(name: 'Couriers')]
    #[Areas(['public'])]
    public function getSellerOrdersAction1(
        Request $request,
        int $sellerId,

    ): Response {

    }

So why it does not work as is in documentation? I assume the @OA\Response( is not necessary for minimal code. Get attribute by the source I see just extends Get annotation, so it should work. How to debug such cases when there is no error? Maybe I do not know some basics and so do not understand but I have read cookbook.

Tried also create dump and when there is no route attribute, and is get instead - there is no such url in the dump.

bin/console nelmio:apidoc:dump > dump.json --area=public

DerManoMann commented 5 days ago

Not sure how the issue is related to reusing responses in swagger-php.

To solve the issue of not being able to use OA\Get you might have to look into the nelmio bundle. Route is not a swagger-php attribute, so perhaps code without a valid Symfony route are ignored?

darius-v commented 4 days ago

Not sure how the issue is related to reusing responses in swagger-php.

Just that this example is from reusing responses. I was trying to write code with attributes by this example.

To solve the issue of not being able to use OA\Get you might have to look into the nelmio bundle. Route is not a swagger-php attribute, so perhaps code without a valid Symfony route are ignored?

Maybe. I did not know where to even look at, it is confusing. So as I understand now - examples in swagger-php cookbook are not guaranteed to work when using nelmio api bundle.

But now reading nelmio documentation:

https://symfony.com/bundles/NelmioApiDocBundle/current/index.html#how-does-this-bundle-work

This configuration field can more generally be used to store your documentation as yaml. You may find in the .yaml files from SwaggerPHP examples.

So it points me to swagger php github so probably thats why I expected them to work.

Examples of using the annotations can be found in SwaggerPHP examples.