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

OpenApi\Analysis::getSchemaForSource(): Argument #1 ($fqdn) must be of type string, array given, #2152

Closed
jdechavanne opened this issue Nov 18, 2023 · 7 comments

Comments

@jdechavanne
Copy link

jdechavanne commented Nov 18, 2023

Hi there,
I have a simple symfony 6.3 project with php 8.2 Api platform 3.2 and Nelmio api doc.
Then i generate a simple Post entity with title and description but when i want to access nelmio doc, i have the following error.

OpenApi\Analysis::getSchemaForSource(): Argument #1 ($fqdn) must be of type string, array given,

After investigate, i've found that if i describe manually my operation from api platform, it works well :

#[ORM\Entity(repositoryClass: PostRepository::class)]
#[ApiResource(
    new Get(),
    new Post(),
    new Put(),
    new Patch(),
    new Delete(),
)]
class PostArticle

But then here we go, i set the new GetCollection() attribute, and the error appear again :/

I can't figure out the problem :'(

Here is my require part in composer.json file

"require": {
        "php": ">=8.1",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "api-platform/core": "^3.2",
        "doctrine/doctrine-bundle": "^2.11",
        "doctrine/doctrine-migrations-bundle": "^3.3",
        "doctrine/orm": "^2.16",
        "nelmio/api-doc-bundle": "^4.12",
        "nelmio/cors-bundle": "^2.3",
        "phpdocumentor/reflection-docblock": "^5.3",
        "phpstan/phpdoc-parser": "^1.24",
        "symfony/asset": "6.3.*",
        "symfony/console": "6.3.*",
        "symfony/dotenv": "6.3.*",
        "symfony/expression-language": "6.3.*",
        "symfony/flex": "^2",
        "symfony/framework-bundle": "6.3.*",
        "symfony/property-access": "6.3.*",
        "symfony/property-info": "6.3.*",
        "symfony/runtime": "6.3.*",
        "symfony/security-bundle": "6.3.*",
        "symfony/serializer": "6.3.*",
        "symfony/translation": "6.3.*",
        "symfony/twig-bundle": "6.3.*",
        "symfony/validator": "6.3.*",
        "symfony/yaml": "6.3.*",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
@Dayvin30
Copy link

same issue, any solutions ?

@xammmue
Copy link

xammmue commented Nov 20, 2023

I got the same issue when upgrading from Api platform 2.7 to ApiPlatform 3.2. Looking forward to finding a solution here.

TypeError : OpenApi\Analysis::getSchemaForSource(): Argument #1 ($fqdn) must be of type string, array given, called in /var/www/symfony/vendor/zircote/swagger-php/src/Processors/AugmentSchemas.php on line 106

We are using these versions:

api-platform/core 3.2.5
nelmio/api-doc-bundle 4.12.0
zircote/swagger-php 4.7.15

There is an issue in zircote/swagger-php which got closed as it was deemed as unrelated to their project: zircote/swagger-php#1464

Looking forward to finding a solution here

@sauls
Copy link

sauls commented Nov 22, 2023

Maybe we can have temporary solution by introducing configuration like enable_api_platform.

So instead in DependencyInjection/NelmioApiDocExtension.php:170-173

// ApiPlatform support
if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Documentation\Documentation')) {
    $loader->load('api_platform.xml');
}

Would be nice not to force api platform integration

// ApiPlatform support
if ($config['enable_api_platform'] && isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Documentation\Documentation')) {
    $loader->load('api_platform.xml');
}

I know this doesn't fix the problem, but at least having this option we can have separate UIs that work, until the problem is fixed.

My project use case is that v1 is under nelmio api docs , and we are moving to v2 using api-platform, both docs are rendered separately. So now only v2 renders correctly while v1 gets this exception too... And if I comment out these lines, v1 and v2 docs are rendered without any issues.

@DjordyKoert
Copy link
Collaborator

I have a work in progress PR open at zircote/swagger-php zircote/swagger-php#1502.

This happens because Api platform 3.2 creates documentation according to openapi spec 3.1.0 which allows types to be defined as a string or a list of types. A list of types causes a TypeError because that method only accepts string as a parameter but an arrar (list of types) is passed instead.

@jdechavanne
Copy link
Author

Thanks @DjordyKoert for you feedback 🙏

@DjordyKoert
Copy link
Collaborator

zircote/swagger-php#1502 has been merged so a simple update of swagger-php on your project should fix the issue 😄

@jdechavanne
Copy link
Author

Thanks @DjordyKoert
I have another error now, Warning: Undefined array key "owl:maxCardinality"

But i don't think it's related 🤔

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

5 participants