nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.23k stars 834 forks source link

[4.0] "Try out" possible without filling required parameters #1705

Open NicoHaase opened 4 years ago

NicoHaase commented 4 years ago

Using v4.0.0-BETA2, it is possible to submit a "Try out" request while a required field is not filled. The "Loading" animation spins and spins:

Bildschirmfoto von 2020-08-21 15-30-11

The error console provides information about this:

Error: Required parameter myself is not provided cr index.js:4100 cr index.js:4070 Ne actions.js:416 ae utils.js:195 O Redux c wrap-actions.js:33 r system.js:174 z system.js:461 Re actions.js:459 ae utils.js:195 O Redux g spec-wrap-actions.js:9 r system.js:174 z system.js:461 n execute.jsx:24 React 14 system.js:464:16

I had expected that the "Execute" button is disabled until all required fields are filled, or that some kind of warning pops up when clicking the button

NicoHaase commented 4 years ago

A further hint: there seems to be a distinction between regular URL parameters (defined in the route itself) and additional parameters.

When using this "Try out" on a route that must contain the parameter by the route definition itself (like @Route("/room/{ressource}")), everything works as expected. The error reported above is related to a parameter defined using @OA\Parameter with required=true

vmeling commented 3 years ago

Annotation

     * @OA\Get(
     *     path="/user/{id}",
     *     summary="Retrieve User",
     *     description="Retrieve User",
     *     tags={"User"},
     *     @OA\Parameter(ref="#/components/parameters/Identifier"),
     *     @OA\Response(
     *          response="200",
     *          description="User Entity",
     *          @OA\JsonContent(ref=@Model(type=User::class, groups={"userForm"})),
     *     )
     * )

Config

nelmio_api_doc:
    documentation:
        components:
            parameters:
                Identifier:
                    name: id
                    in: path
                    description: Entity Identifier
                    schema:
                        type: integer
                        pattern: \d+

Result

{
    "/user/{id}": {
        "get": {
            "tags": [
                "User"
            ],
            "summary": "Retrieve User",
            "description": "Retrieve User",
            "operationId": null,
            "parameters": [
                {
                    "$ref": "#/components/parameters/Identifier"
                },
                {
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "User Entity",
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/User"
                            }
                        }
                    }
                },
            }
        }
    }
}

In result identifier was added twice, as referenced parameter and as default parameter (string)

When i click "Try it out", fill id and "Execute", i get error in field "Required field is not provided"

GuilhemN commented 3 years ago

Thanks for the report!

This is probably related to https://github.com/nelmio/NelmioApiDocBundle/pull/1740: the usage of $ref for path parameters was broken. It is not released yet, but will be soon. I'd like to merge php8 support in the master branch before.

Could you try whether it does indeed fix your issue please?

pavel-vasiluk commented 2 years ago

@GuilhemN I am currently at v4.8.2 version and can confirm that the query parameter is being required. However, there is still similar problem with header parameter.

     *     @OA\Parameter(
     *         name="X-SOME-TOKEN",
     *         in="header",
     *         required=true
     *     )

Try out is still possible without filling required header value.