nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.21k stars 830 forks source link

Referenced parameters are not added to reqeuest #1903

Open sweoggy opened 2 years ago

sweoggy commented 2 years ago

Hi,

We just upgraded to v4 from v3 and are having issues with references which were previously working just fine.

First issue we hit was in regards to required parameters with default values:

image

It is not possible to execute the request despite order parameter having a default value. Selecting a different value doesn't help either. But if we make the parameter optional, it is possible to execute the request. However, we also see that the referenced parameters are never added to the query:

image

Additionally, sortColumn is not required in the UI, despite being required according to annotation.

Controller annotations:

/**
     * @Rest\Get(path="/users")
     * @Rest\QueryParam(name="page", requirements="\d+", nullable=true)
     * @Rest\QueryParam(name="rowsPerPage", requirements="\d+", nullable=true)
     * @Rest\QueryParam(name="search", requirements=".+", nullable=true)
     * @Rest\QueryParam(name="sortColumn", requirements=".+", nullable=false)
     * @Rest\QueryParam(name="order", requirements=".+", nullable=false)
     *
     * @Operation(
     *     tags={"Admin"},
     *     summary="Get a list of your users.",
     *     @OA\Parameter(
     *         ref="#/components/parameters/table_page"
     *     ),
     *     @OA\Parameter(
     *         ref="#/components/parameters/table_rows_per_page"
     *     ),
     *     @OA\Parameter(
     *         name="search",
     *         in="query",
     *         @OA\Schema(type="string"),
     *         required=false,
     *         description="Search for email and name"
     *     ),
     *     @OA\Parameter(
     *         name="sortColumn",
     *         description="Which column to sort result by",
     *         in="query",
     *         @OA\Schema(type="string", enum={"email", "firstName", "lastName", "userStatus", "userRoles"}),
     *         required=true,
     *     ),
     *     @OA\Parameter(
     *         ref="#/components/parameters/table_order",
     *     ),
     *     @OA\Response(
     *         response="200",
     *         description="Returned when successful, a JSON encoded array consisting of user data."
     *     ),
     *     @OA\Response(
     *         response="400",
     *         description="Returned when required data is missing or given data is invalid. Look at the response
     *         body's message to know exactly what went wrong."
     *     ),
     *     @OA\Response(
     *         response="401",
     *         description="Returned when authorisation fails, such as missing JWT-token, insufficient privileges or
     *         expired JWT-token. Look at the response body's message to know exactly what went wrong."
     *     )
     * )
     */

Bundle config, including parameters:

nelmio_api_doc:
    documentation:
        info:
            title: "Debricked API Documentation"
            version: 1.1.0
        security:
            -   JWT: []
        components:
            securitySchemes:
                JWT:
                    type: "apiKey"
                    description: ""
                    name: "Authorization"
                    in: "header"
            parameters:
                table_page:
                    name: page
                    in: query
                    schema:
                        type: integer
                        default: 1
                    required: false
                    description: "Which page to show results for, starting at 1"
                table_rows_per_page:
                    name: rowsPerPage
                    description: "Amount of rows per page"
                    in: query
                    schema:
                        type: integer
                        default: 25
                    required: false
                table_order:
                    name: order
                    description: "Sorting order, asc or desc"
                    in: query
                    schema:
                        type: string
                        enum: [ "asc", "desc" ]
                    required: true

Are we doing something wrong or is something up with referencing parameters in v4? :)

CarlTern commented 2 years ago

Adding to the issue: We've now managed to do a workaround for the issue, by defining "name" and "in" both for the parameter in the bundle config file as well as the parameter in the annotations of the controller function, like below (bundle config is the same as above):

     *     @OA\Parameter(
     *         ref="#/components/parameters/table_page"
     *         name="page",
     *         in="query",
     *     ),