Merge 6e05331119501ba1a7881699e4051adaa1b58e9a into 2fb26c362ea6557c90353606ccdc3c446d6a8f35

This commit is contained in:
Guillaume Turri 2025-05-11 18:25:12 +02:00 committed by GitHub
commit e3f3c79943
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 5 deletions

View File

@ -417,10 +417,16 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
op.vendorExtensions.put("x-comment-type", "void");
}
// Create a variable to add typing for return value of interface
if (op.returnType != null) {
op.vendorExtensions.put("x-return-type", "array|object|null");
} else {
if (op.returnType == null) {
op.vendorExtensions.put("x-return-type", "void");
} else if (op.isArray || op.isMap || isApplicationJsonOrApplicationXml(op)
|| !op.returnTypeIsPrimitive // it could make sense to remove it, but it would break retro-compatibility
) {
op.vendorExtensions.put("x-return-type", "array|object|null");
} else if ("binary".equals(op.returnProperty.dataFormat)) {
op.vendorExtensions.put("x-return-type", "mixed");
} else {
op.vendorExtensions.put("x-return-type", op.returnType);
}
// Add operation's authentication methods to whole interface
@ -438,6 +444,18 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
return objs;
}
private boolean isApplicationJsonOrApplicationXml(CodegenOperation op) {
if (op.produces != null) {
for(Map<String, String> produce : op.produces) {
if ("application/json".equalsIgnoreCase(produce.get("mediaType"))
|| "application/xml".equalsIgnoreCase(produce.get("mediaType"))) {
return true;
}
}
}
return false;
}
@Override
public ModelsMap postProcessModels(ModelsMap objs) {
objs = super.postProcessModels(objs);

View File

@ -204,6 +204,10 @@ class Controller extends AbstractController
return 'application/xml';
}
if (in_array('*/*', $accept)) {
return $produced[0];
}
// If we reach this point, we don't have a common ground between server and client
return null;
}

View File

@ -29,7 +29,13 @@ 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 {
// don't use var_export if $data is already a string: it may corrupt binary strings
return is_string($data) ? $data : var_export($data, true);
}
}
/**

View File

@ -214,6 +214,10 @@ class Controller extends AbstractController
return 'application/xml';
}
if (in_array('*/*', $accept)) {
return $produced[0];
}
// If we reach this point, we don't have a common ground between server and client
return null;
}

View File

@ -29,7 +29,13 @@ 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 {
// don't use var_export if $data is already a string: it may corrupt binary strings
return is_string($data) ? $data : var_export($data, true);
}
}
/**