swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.09k stars 6.03k forks source link

[PHP] Class "" not found #12449

Open Lexian-droid opened 3 months ago

Lexian-droid commented 3 months ago
Description

I generated a PHP API Client for the Azuracast API, and it works well, but some endpoints give the error message "Class "" not found" when I try to use the API via the client, some classes work without issue, but for example, StationsSongRequestsApi > getRequestableSongsWithHttpInfo where it will respond with the error message above. I need it as I can't really utilize the API without it, and I'm not sure what the issue is. I've tried to regenerate the client multiple times, but the issue persists. I'm not sure if it's an issue with the swagger file or the codegen itself.

Also, here is the actual project.

Swagger-codegen version

3.0.61

Swagger declaration file content or url

https://raw.githubusercontent.com/AzuraCast/AzuraCast/main/web/static/openapi.yml

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i https://raw.githubusercontent.com/AzuraCast/AzuraCast/main/web/static/openapi.yml -l php -o output/azuracast-php-client3 -c ./config.json

Steps to reproduce
require_once __DIR__ . '/vendor/autoload.php';

use AzuraCast\Api\StationsSongRequestsApi;
use AzuraCast\Configuration;
use AzuraCast\ApiClient;

$config = Configuration::getDefaultConfiguration();

$apiInstance = new StationsSongRequestsApi(new ApiClient($config));

try {
    $result = $apiInstance->getRequestableSongs();
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling StationsSongRequestsApi->getRequestableSongs: ', $e->getMessage(), PHP_EOL;
}

also here is the config:

{
  "invokerPackage": "AzuraCast",
  "apiPackage": "Client\\Api",
  "modelPackage": "Client\\Model",
  "packagePath": "Azuracast",
  "srcBasePath": "src",
  "gitUserId": "Lexian-droid",
  "gitRepoId": "azuracast-php-client",
  "artifactVersion": "1.0.2",
  "hideGenerationTimestamp": true
}
Related issues/PRs

#8380 This is the closest issue I could find, but it's not the same issue. (The issue states it returns "Null" but my issue returns an empty string.)

Suggest a fix/enhancement

Not sure what the issue is, but I think it might be an issue with the codegen itself, as the classes are generated, but some of them are not found when trying to use them. I've followed the documentation and the examples provided, but I'm not sure what the issue is.

The error is from: azuracast-php-client\src\ObjectSerializer.php on line 298, specifically with

// If a discriminator is defined and points to a valid subclass, use it.
$discriminator = $class::DISCRIMINATOR;
fugikzl commented 2 weeks ago

HI, meet the same problem. Any updates?

Lexian-droid commented 2 weeks ago

HI, meet the same problem. Any updates?

Hello, unfortunately I have not. I personally gave up on the topic, as it seems to be a swagger issue, I've fixed what I could in Azuracast, but Swagger won't work at all. It's been a while now so I can't remember what I rounded up doing, but I talked to one of Azuracsat's developer, and they thought it was an issue with Swagger, so I went on to try openapi-generator, which also didn't work. But I think they both fell from the same tree, because they both seem really similar.

But, you may find better success in alternatives, however you may also consider making your own, if you have the knowledge to. I'd personally recommend going the "Make it yourself" method, It's the best way as these tools aren't quite a "One size fits all" for all use cases.

But I hope you the best with your project, and I apologize that there haven't been any answers to the problem, I wish I knew, I really do. Actually, here is this thread: https://github.com/AzuraCast/AzuraCast/issues/7396 I know you're probably not doing it with Azuracast, but maybe the info there might help you.