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 'null' not found #8380

Open mickaelmonsieur opened 6 years ago

mickaelmonsieur commented 6 years ago

Hello, I have this error:

Fatal error: Uncaught Error: Class 'null' not found in /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/lib/ObjectSerializer.php:294
Stack trace:
#0 /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/lib/ObjectSerializer.php(247): Swagger\Client\ObjectSerializer::deserialize(Object(stdClass), 'null', NULL)
#1 /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/lib/ObjectSerializer.php(311): Swagger\Client\ObjectSerializer::deserialize(Array, 'null[]', NULL)
#2 /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/lib/Api/DefaultApi.php(157): Swagger\Client\ObjectSerializer::deserialize(Object(stdClass), '\\Swagger\\Client...', Array)
#3 /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/lib/Api/DefaultApi.php(98): Swagger\Client\Api\DefaultApi->vaultPostWithHttpInfo(Object(Swagger\Client\Model\VaultRequest))
#4 /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/test.php(18): Swagger\Client\Api\DefaultApi->vaultPost(Object(S in /Users/mickael/Desktop/swagger-codegen/SwaggerClient-php/lib/ObjectSerializer.php on line 294
Swagger-codegen version

swagger-codegen version: 2.3.1

Swagger declaration file content or url

https://gist.github.com/mickaelmonsieur/6f761d5f9f1077b49fe3f7a95a4a78d0

Command line used for generation

swagger-codegen generate -i /tmp/swagger.json -l php -o /Users/mickael/Desktop/swagger-codegen/

Steps to reproduce
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$apiInstance = new Swagger\Client\Api\DefaultApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(['cert' => ['../../certs/xxxxxxxxxx.net.pem',
    'PassW0rdXXX']]),
    $config
);

$data = array('source_id' => 40, 'allow_partial_update' => false);
$json_vault_request = new \Swagger\Client\Model\VaultRequest($data); // \Swagger\Client\Model\VaultRequest |

echo $json_vault_request->__toString();

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

?>
mickaelmonsieur commented 6 years ago

Hi, The generator show:

{
  "SourceId": 0,
  "AllowPartialUpdate": true,
  "Entities": [
    null
  ]
}

Is it possible that a JSON swagger is incorrect ?

Lexian-droid commented 3 months ago

Hey bro, have you ever figured out what was causing this? I'm currently having the same error.