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

Duplication of query parameter if it's a reference #2314

Open
jneidel opened this issue Jul 15, 2024 · 3 comments
Open

Duplication of query parameter if it's a reference #2314

jneidel opened this issue Jul 15, 2024 · 3 comments
Labels

Comments

@jneidel
Copy link

jneidel commented Jul 15, 2024

Version

4.28.0

Description

Referencing a parameter defined in components duplicates the parameter in the rendered output.

Screenshot 2024-07-15 at 12 38 40
 * @Nelmio\Operation(
 *     @OA\Parameter(ref="#/components/parameters/limit"),
 *      ...
 *
 * @FOS\RestBundle\Controller\Annotations\QueryParam(name="limit", requirements="[1-9]\d*", description="Limit", default="20", strict=true) 
# config/nelmio_api_doc.yaml
nelmio_api_doc:
    documentation:
        components:
            parameters:
                limit:
                    name: limit
                    in: query
                    example: 20
                    description: "How many entries per page?"
                    schema:
                        type: integer

working alternative

Compared to this case where there is no duplication:

@OA\Parameter(name="limit", in="query", description="How many entries per page?", required=false, @OA\Schema(type="string")),
Screenshot 2024-07-15 at 12 40 28

Additional context

Seems similar to the problems described in #1739 and #1407

The error does not happen on parameters of in: path

@jneidel jneidel added the bug label Jul 15, 2024
@jneidel jneidel changed the title Duplication of paramter if it's a reference Duplication of query parameter if it's a reference Jul 16, 2024
@DjordyKoert
Copy link
Collaborator

Could you share your openapi docs in json?

@jneidel
Copy link
Author

jneidel commented Jul 17, 2024

@OA\Parameter(ref="#/components/parameters/pagination--limit"),                                                                           
@OA\Parameter(name="page", in="query", description="Which page?", required=false, @OA\Schema(type="string")),
@OA\Parameter(ref="#/components/parameters/channel-id"),
@OA\Parameter(ref="#/components/parameters/version"),
                "parameters": [
                    {
                        "$ref": "#/components/parameters/pagination--limit"
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "description": "Which page?",
                        "required": true,
                        "allowEmptyValue": false,
                        "schema": {
                            "type": "string",
                            "default": "1",
                            "pattern": "\\d+"
                        }
                    },
                    {
                        "$ref": "#/components/parameters/channel-id"
                    },
                    {
                        "$ref": "#/components/parameters/version"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "Limit",
                        "required": true,
                        "allowEmptyValue": false,
                        "schema": {
                            "type": "string",
                            "default": "20",
                            "pattern": "\\d+"
                        }
                    }
                ],
Screenshot 2024-07-17 at 12 10 18

@jneidel
Copy link
Author

jneidel commented Nov 12, 2024

For people with the same problem: our solution was to create a custom attribute:

<?php

namespace App\ApiBundle\Attribute\ApiDocs\Parameter;

use OpenApi\Attributes\Parameter;
use OpenApi\Attributes\Schema;

#[\Attribute(\Attribute::TARGET_CLASS_CONSTANT | \Attribute::TARGET_METHOD)]
final class Limit extends Parameter
{
    public function __construct()
    {
        parent::__construct(
            name: 'limit',
            in: 'query',
            description: 'How many entries to show?',
            required: false,
            schema: new Schema(type: 'integer'),
        );
    }
}

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

No branches or pull requests

2 participants