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

Description from OpenApi\Attributes\QueryParameter is not processing #2220

Open
akankov opened this issue Feb 16, 2024 · 2 comments
Open

Description from OpenApi\Attributes\QueryParameter is not processing #2220

akankov opened this issue Feb 16, 2024 · 2 comments

Comments

@akankov
Copy link

akankov commented Feb 16, 2024

Description from OpenApi\Attributes*QueryParameter* is not processing.
nelmio/api-doc-bundle version 5.x-dev and 4.20.0
zircote/swagger-php version 4.8.4

Request class:

<?php
class ExampleRequest
{
    #[OA\QueryParameter(
        description: 'Page number.',
        example: 1,
    )]
    protected int $page = 1;

    public function getPage(): int
    {
        return $this->page;
    }

    public function setPage(int $page): self
    {
        $this->page = $page;

        return $this;
    }
}

Controller:

class ExampleController extends AbstractController
{
    #[Route(path: '', name: 'name', methods: ['GET'])]
    public function listAction(
        #[MapQueryString]
        ExampleRequest $request = new ExampleRequest(),
    ): void {
        // todo do something
    }
}

Result:

{
  "openapi": "3.0.0",
  "info": {
    "title": "title",
    "version": "1.0.0"
  },
  "servers": [],
  "paths": {
    "/": {
      "get": {
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1
            }
          }
        ],
        "responses": {
          "default": {
            "description": ""
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExampleRequest": {
        "properties": {
          "page": {
            // no description
            "type": "integer",
            "default": 1
          }
        },
        "type": "object"
      }
    },
    "securitySchemes": {
      "Bearer": {
        "type": "http",
        "bearerFormat": "JWT",
        "scheme": "bearer"
      }
    }
  },
  "security": [
    {
      "Bearer": []
    }
  ]
}
@pixelplan-digitalweb
Copy link

👍 I was also wondering if it would be possible to define the parameters on the DTO, would make the action much cleaner

@robertbakker1
Copy link

I have a similiar case where the Examples aren't processed:

<?php

use Symfony\Component\Validator\Constraints as Assert;
use OpenApi\Attributes as OA;

final readonly class Sort
{
    public function __construct(
        #[Assert\NotBlank(allowNull: true)]
        public ?string $sort = null,

        #[
            Assert\Choice(choices: ['asc', 'desc']),
            OA\Examples(
                example: "asc",
                summary: "Ascending",
                value: "asc",
            ),
            OA\Examples(
                example: "desc",
                summary: "Descending",
                value: "desc",
            ),
        ]
        public ?string $dir = null,
    )
    {
    }
}

Would make it indeed much cleaner, I will be able to reuse the Sort object in controllers with #[MapQueryString].
My goal is to generate http tests on the openapi spec; using the examples as the input test cases.

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

3 participants