Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
darius-v opened this issue Sep 25, 2024 · 2 comments
Open

Comments

@darius-v
Copy link

darius-v commented Sep 25, 2024

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
Copy link
Collaborator

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants