OpenAPITools / OpenAPITools/openapi-generator
[BUG] [PHP] Object of class stdClass could not be converted to string
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
Description
generating the php classes of these open-api definitions:
https://developer.ebay.com/api-docs/sell/analytics/overview.html
leads to a problem i have in ObjectSerializer.php
where i get the error:
Object of class stdClass could not be converted to string
openapi-generator version
tested: 3.3.4 (php5) and 4.3.1 (php7)
OpenAPI declaration file content or url
https://developer.ebay.com/api-docs/master/sell/analytics/openapi/3/sell_analytics_v1_oas3.yaml
https://developer.ebay.com/api-docs/master/sell/analytics/openapi/3/sell_analytics_v1_oas3.json
Command line used for generation
generate -i /app/sell_analytics_v1_oas3.yaml -g php -o /app/ --config /app/openapi-config.php.ebay.analytics.json
Steps to reproduce
testing this code:
php7: https://github.com/michabbb/sdk-ebay-rest-analytics
php5: https://github.com/michabbb/sdk-ebay-rest-analytics/tree/php5
for real testing, you need an eBay oauth code, then you can use the generated code like that:
$config = Configuration::getDefaultConfiguration()->setAccessToken($ebay_access_token);
$apiInstance = new SellerStandardsProfileApi(null,$config);
try {
$result = $apiInstance->findSellerStandardsProfiles();
+d($result);
} catch (\Exception $e) {
echo 'Exception when calling CustomerServiceMetricApi->getCustomerServiceMetric: ', $e->getMessage(), PHP_EOL;
}
here you can see an example API result of findSellerStandardsProfiles
Suggest a fix
in ObjectSerializer.php line 299 where this code is in:
} elseif (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
settype($data, $class);
return $data;
}
i have to change:
} elseif (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
if ($data instanceof \stdClass) {
settype($data,'array');
} else {
settype($data, $class);
}
return $data;
}
that is a hack not a fix... i know... i don´t know whats wrong here.
thanks for any help!!!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ObjectSerializer.php around line 299 and reproduce the failure with the linked eBay OpenAPI YAML or JSON using the provided generation command. Compare the generated SDK behavior with the example API result and determine the correct handling for stdClass values; done means the generated PHP client can process that result without the conversion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100