mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
[php-symfony] Don't crash at runtime on null convertFormat
$this->convertFormat may return "null". When it's the case we end up calling ...->serialize($data, null); but this crashes at runtime because that serialize method declares that the 2nd parameter is of type "string" (so null is not accepted). With this patch we avoid having an error 500. Instead we return something that makes perfect sense when the OpenApi specification declares a content of type "text/plain" and that the returned value is for instance a string, an int, or a boolean.
This commit is contained in:
parent
f6e2173e0e
commit
d300ae9a41
@ -29,7 +29,12 @@ class JmsSerializer implements SerializerInterface
|
||||
*/
|
||||
public function serialize($data, string $format): string
|
||||
{
|
||||
return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format));
|
||||
$convertFormat = $this->convertFormat($format);
|
||||
if ($convertFormat !== null) {
|
||||
return SerializerBuilder::create()->build()->serialize($data, $convertFormat);
|
||||
} else {
|
||||
return is_string($data) ? $data : var_export($data, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,12 @@ class JmsSerializer implements SerializerInterface
|
||||
*/
|
||||
public function serialize($data, string $format): string
|
||||
{
|
||||
return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format));
|
||||
$convertFormat = $this->convertFormat($format);
|
||||
if ($convertFormat !== null) {
|
||||
return SerializerBuilder::create()->build()->serialize($data, $convertFormat);
|
||||
} else {
|
||||
return is_string($data) ? $data : var_export($data, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user