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

Parameter $ref of class OpenApi\Attributes\Property constructor expects string|null #1228

Closed
dmamchyts opened this issue May 6, 2022 · 3 comments · Fixed by #1229
Closed

Comments

@dmamchyts
Copy link

Hi, I am use "nelmio/api-doc-bundle": "^4.9"
After fix 6e13ebb#diff-8962249d92fe80c501dbd3daac234614f6ea464693982f14ac70822549bfcd3aL23

I got an error:

  25     Parameter $ref of class OpenApi\Attributes\Property constructor        
         expects string|null, Nelmio\ApiDocBundle\Annotation\Model given.       
  31     Parameter $content of class OpenApi\Attributes\Response constructor    
         expects                                                                
         array<OpenApi\Annotations\JsonContent|OpenApi\Annotations\MediaType|O  
         penApi\Annotations\XmlContent>|OpenApi\Annotations\JsonContent|OpenAp  
         i\Annotations\MediaType|OpenApi\Annotations\XmlContent|null,           
         Nelmio\ApiDocBundle\Annotation\Model given. 

Src:

<?php

declare(strict_types=1);

namespace App\Controller\Api;

use App\Request\Api\Config\ConfigRequest;
use App\Response\Api\ConfigResponse;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\{Request, Response};
use Symfony\Component\Routing\Annotation\Route;

#[OA\Tag(name: 'Config')]
class ConfigController extends AbstractApiController
{
    #[OA\Post(
        requestBody: new OA\RequestBody(
            content: new OA\JsonContent(
                properties: [
                    new OA\Property(property: 'request_data', ref: new Model(type: ConfigRequest::class)),
                    new OA\Property(property: 'ts', type: 'string'),
                ]
            )
        ),
        responses: [
            new OA\Response(response: Response::HTTP_OK, description: 'success', content: new Model(type: ConfigResponse::class)),
            new OA\Response(response: '4XX/5XX', description: 'error'),
        ]
    )]
    #[Route('/api/config', methods: [Request::METHOD_POST])]
    public function getConfig(
    ): Response {
        return $this->json('XXX');
    }
}

@michaljusiega
Copy link

I can confirm the same issue with:

use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OpenApi;
use Symfony\Component\HttpFoundation\Response;

    #[OpenApi\Response(
        response: Response::HTTP_OK, 
        description: 'Response when data was successfully returned.', 
        content: new OpenApi\JsonContent(
            type: 'array', 
            items: new OpenApi\Items(
                ref: new Model(type: Expert::class)
            )
        )
    )]

@dmamchyts
Copy link
Author

PS. Downgrade to 4.3 will help (cc @michaljusiega )

composer req --dev zircote/swagger-php:"4.3.*"

@DerManoMann
Copy link
Collaborator

Well, I guess I'll have to add the object typehint back in then.

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

Successfully merging a pull request may close this issue.

3 participants