nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.22k stars 833 forks source link

use attributes instead of groups #1952

Open SakhriHoussem opened 2 years ago

SakhriHoussem commented 2 years ago

I have a constant array of specific entity attributes

    const SELECT_ATTRIBUTES = [
        "id",
        "email", 
    ];
    /**
     * List of users.
     *
     * This call return all the users.
     *
     * @OA\Response(
     *     response=200,
     *     description="Returns list of all the users",
     *     @OA\JsonContent(
     *        type="array",
     *        @OA\Items(
     *          type="object",
     *          ref=@Model(type=User::class, options={"attributes"=User::SELECT_ATTRIBUTES})),
     *     )     
     * )
     * @OA\Tag(name="users")
     * @Security(name="cookieAuth")
     */

I want to use attributes instead of groups

see example selecting-specific-attributes

GuilhemN commented 2 years ago

Sure that would be nice!

That shouldn't be too complicated to implement, maybe we could just use a key serializer_context as default context passed to the property info, would that suit you to then use: @Model(type=User::class, options={"serializer_context"={"attributes=User::SELECT_ATTRIBUTES}}))?

I don't have much time to dedicate to developping new features in this bundle unfortunately but I'd be happy to merge pull requests :)